42 #include "StFgtPedPlotter.h"
50 #include <TGraphErrors.h>
52 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
56 const Int_t StFgtPedPlotter::mMaxNumTimeBins = 8;
58 Int_t StFgtPedPlotter::makePlots(){
64 for( Int_t i=0, k=-1; i<mMaxNumTimeBins; ++i )
65 if( 1<<i & mTimeBinMask )
68 UInt_t nTimeBins = mTimeBinMap.size();
70 cerr <<
"No time bins in the time bin mask!" << endl;
72 std::vector< std::vector< Float_t > > X, Y, E;
73 X.reserve( nTimeBins );
74 Y.reserve( nTimeBins );
75 E.reserve( nTimeBins );
78 for( UInt_t i=0; i<nTimeBins; ++i ){
79 X.push_back( std::vector< Float_t >() );
80 Y.push_back( std::vector< Float_t >() );
81 E.push_back( std::vector< Float_t >() );
84 ierr = fillData( X, Y, E );
86 for( UInt_t i = 0; i<mGraphVec.size(); ++i ){
91 mGraphVec.resize( nTimeBins, 0 );
94 std::map< Int_t, Int_t >::iterator iter;
95 for( iter = mTimeBinMap.begin(); iter != mTimeBinMap.end(); ++iter ){
96 Int_t timebin = iter->first;
97 Int_t i = iter->second;
99 TGraph* gr = makePlot( X[i], Y[i], E[i], timebin );
100 cout <<
"Plot for time bin " << timebin <<
' ' << gr << endl;
102 if( gr && gr->GetN() )
111 Int_t StFgtPedPlotter::fillData( VecVec_t& X, VecVec_t& Y, VecVec_t& E ){
114 std::ifstream fin( mFileNameIn.data() );
117 cerr <<
"Error opening file '" << mFileNameIn <<
"'" << endl;
122 Int_t timebin, geoId;
125 Float_t ped, stdev, x = 0;
127 while( !fin.eof() && !ierr ){
128 fin >> geoId >> timebin >> ped >> stdev;
131 if( 1<<timebin & mTimeBinMask ){
132 Double_t pos, high, low;
135 StFgtGeom::getPhysicalCoordinate( geoId, disc, quad, layer, pos, high, low );
139 if( disc == mDiscId && quad == mQuadId ){
140 Int_t i = mTimeBinMap[ timebin ];
142 if( mPlotVsStrip ==
'r' || mPlotVsStrip ==
'R' ){
143 pass = ( layer ==
'R' );
144 pass &= ( mPlotVsStrip ==
'R' ? (low > 0.785) : (low < 0.785) );
146 }
else if( mPlotVsStrip ==
'P' ){
148 pass = ( layer == mPlotVsStrip );
150 Int_t rdo, arm, apv, channel;
151 StFgtCosmicTestStandGeom::getNaiveElecCoordFromGeoId(geoId,rdo,arm,apv,channel);
152 x = 128*(apv%12) + channel;
160 Y[i].push_back( ped );
161 E[i].push_back( stdev );
163 Float_t maxY = stdev;
187 TGraph* StFgtPedPlotter::makePlot( std::vector< Float_t >& x,
188 std::vector< Float_t >& y,
189 std::vector< Float_t >& e,
203 cout <<
"sizes " << x.size() <<
' ' << y.size() <<
' ' << e.size() << endl;
204 if( !x.empty() && x.size() == y.size() && y.size() == e.size() ){
206 Float_t *xArr =
new Float_t[ x.size() ];
207 Float_t *yArr =
new Float_t[ x.size() ];
208 Float_t *eArr =
new Float_t[ x.size() ];
210 for( UInt_t i=0; i<x.size(); ++i ){
217 gr =
new TGraph( x.size(), xArr, eArr );
219 gr =
new TGraphErrors( x.size(), xArr, yArr, 0, eArr );
220 std::stringstream ss;
222 if( mPlotVsStrip ==
'r' )
223 ss <<
"r-strips, cham. 1: ";
224 else if( mPlotVsStrip ==
'R' )
225 ss <<
"r-strips, cham. 2: ";
226 else if( mPlotVsStrip ==
'P' )
227 ss <<
"#phi-strips: ";
234 if( mPlotVsStrip ==
'R' || mPlotVsStrip ==
'r' || mPlotVsStrip ==
'P' )
239 if( !mQuadName.empty() )
240 ss <<
", Quad " << mQuadName;
242 if( mPlotVsStrip ==
'r' || mPlotVsStrip ==
'R' )
243 ss <<
"; r Strip Pos. [cm]";
244 else if( mPlotVsStrip ==
'P' )
245 ss <<
"; #phi Strip Pos. [cm]";
247 ss <<
"; 128x(APV Num) + Channel Id.";
251 gr->SetTitle( ss.str().data() );
254 gr->SetMarkerStyle(20);
260 const TGraph* StFgtPedPlotter::getGraph( Int_t timebin )
const {
261 std::map< Int_t, Int_t >::const_iterator iter = mTimeBinMap.find( timebin );
262 return (iter == mTimeBinMap.end() ? 0 : mGraphVec[ iter->second ]);