StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtPedPlotter.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StFgtPedPlotter.cxx,v 1.7 2012/01/31 16:48:04 wwitzke Exp $
9  * Author: S. Gliske, Sept 2011
10  *
11  ***************************************************************************
12  *
13  * Description: See header
14  *
15  ***************************************************************************
16  *
17  * $Log: StFgtPedPlotter.cxx,v $
18  * Revision 1.7 2012/01/31 16:48:04 wwitzke
19  * Changed for cosmic test stand.
20  *
21  * Revision 1.6 2011/09/30 19:09:07 sgliske
22  * general update
23  *
24  * Revision 1.5 2011/09/29 18:39:43 sgliske
25  * Update for geoId->elecCoord function now in StFgtCosmicTestStandGeom
26  *
27  * Revision 1.4 2011/09/27 00:49:00 sgliske
28  * cosmic QA update
29  *
30  * Revision 1.3 2011/09/26 16:55:52 sgliske
31  * Continued work on cosmic QA plots
32  *
33  * Revision 1.2 2011/09/24 02:14:10 sgliske
34  * updated FGT cosmic QA
35  *
36  * Revision 1.1 2011/09/22 21:21:59 sgliske
37  * creation
38  *
39  *
40  **************************************************************************/
41 
42 #include "StFgtPedPlotter.h"
43 
44 #include <iostream>
45 #include <fstream>
46 using std::cerr;
47 using std::cout;
48 using std::endl;
49 
50 #include <TGraphErrors.h>
51 
52 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
53 
54 // since this isn't defined elsewhere (yet)
55 // set to 8 so that it doesn't matter if bins are 0-6 or 1-7
56 const Int_t StFgtPedPlotter::mMaxNumTimeBins = 8;
57 
58 Int_t StFgtPedPlotter::makePlots(){
59  Int_t ierr = 0;
60 
61  // decide how many time bins are present
62  mTimeBinMap.clear();
63 
64  for( Int_t i=0, k=-1; i<mMaxNumTimeBins; ++i )
65  if( 1<<i & mTimeBinMask )
66  mTimeBinMap[i] = ++k;
67 
68  UInt_t nTimeBins = mTimeBinMap.size();
69  if( !nTimeBins )
70  cerr << "No time bins in the time bin mask!" << endl;
71 
72  std::vector< std::vector< Float_t > > X, Y, E;
73  X.reserve( nTimeBins );
74  Y.reserve( nTimeBins );
75  E.reserve( nTimeBins );
76 
77  // set up the vectors
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 >() );
82  };
83 
84  ierr = fillData( X, Y, E );
85 
86  for( UInt_t i = 0; i<mGraphVec.size(); ++i ){
87  if( mGraphVec[i] )
88  delete mGraphVec[i];
89  };
90  mGraphVec.clear();
91  mGraphVec.resize( nTimeBins, 0 );
92 
93  if( !ierr ){
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;
98 
99  TGraph* gr = makePlot( X[i], Y[i], E[i], timebin );
100  cout << "Plot for time bin " << timebin << ' ' << gr << endl;
101 
102  if( gr && gr->GetN() )
103  mGraphVec[i] = gr;
104  };
105  };
106 
107  return ierr;
108 };
109 
110 // to load the data
111 Int_t StFgtPedPlotter::fillData( VecVec_t& X, VecVec_t& Y, VecVec_t& E ){
112  Int_t ierr = 0;
113 
114  std::ifstream fin( mFileNameIn.data() );
115 
116  if( !fin ){
117  cerr << "Error opening file '" << mFileNameIn << "'" << endl;
118  ierr = 1;
119  };
120 
121  if( !ierr ){
122  Int_t timebin, geoId;
123  Short_t disc, quad; //, strip;
124  Char_t layer;
125  Float_t ped, stdev, x = 0;
126 
127  while( !fin.eof() && !ierr ){
128  fin >> geoId >> timebin >> ped >> stdev;
129  //cout << geoId << ' ' << timebin << ' ' << ped << ' ' << stdev << endl;
130 
131  if( 1<<timebin & mTimeBinMask ){
132  Double_t pos, high, low;
133 
134  //StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
135  StFgtGeom::getPhysicalCoordinate( geoId, disc, quad, layer, pos, high, low );
136 
137  Bool_t pass = 1;
138 
139  if( disc == mDiscId && quad == mQuadId ){
140  Int_t i = mTimeBinMap[ timebin ];
141 
142  if( mPlotVsStrip == 'r' || mPlotVsStrip == 'R' ){
143  pass = ( layer == 'R' );
144  pass &= ( mPlotVsStrip == 'R' ? (low > 0.785) : (low < 0.785) );
145  x = pos;
146  } else if( mPlotVsStrip == 'P' ){
147  x = pos;
148  pass = ( layer == mPlotVsStrip );
149  } else {
150  Int_t rdo, arm, apv, channel;
151  StFgtCosmicTestStandGeom::getNaiveElecCoordFromGeoId(geoId,rdo,arm,apv,channel);
152  x = 128*(apv%12) + channel;
153  };
154 
155  if( x && pass ){
156 // cout << mPlotVsStrip << ' ' << x << ' ' << ped << ' ' << stdev << " | "
157 // << geoId << ' ' << disc << ' ' << quad << ' ' << layer << ' ' << high << ' ' << low << endl;
158 
159  X[i].push_back( x );
160  Y[i].push_back( ped );
161  E[i].push_back( stdev );
162 
163  Float_t maxY = stdev;
164  if( !mDoPlotStDev )
165  maxY += ped;
166  if( maxY > mMaxY )
167  mMaxY = maxY;
168  if( x > mMaxX )
169  mMaxX = x;
170  };
171  };
172  };
173 
174  // check to see if at the end of the file
175  fin >> std::ws;
176  fin.peek();
177  };
178  };
179 
180  if( mMaxY > 4096 )
181  mMaxY = 4096;
182 
183  return ierr;
184 };
185 
186 // for each time bin
187 TGraph* StFgtPedPlotter::makePlot( std::vector< Float_t >& x,
188  std::vector< Float_t >& y,
189  std::vector< Float_t >& e,
190  Int_t timebin ){
191  TGraph* gr = 0;
192 // Float_t xlow = 0;
193 // Float_t xhigh = 1280;
194 // Int_t nbins = 1280;
195 // if( mPlotVsStrip == 'R' ){
196 // xlow = 100;
197 // xhigh = 400;
198 // } else if ( mPlotVsStrip == 'P' ){
199 // xlow = 0;
200 // xhigh = 6.28/4;
201 // };
202 
203  cout << "sizes " << x.size() << ' ' << y.size() << ' ' << e.size() << endl;
204  if( !x.empty() && x.size() == y.size() && y.size() == e.size() ){
205  // need to copy to array
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() ];
209 
210  for( UInt_t i=0; i<x.size(); ++i ){
211  xArr[i] = x[i];
212  yArr[i] = y[i];
213  eArr[i] = e[i];
214  };
215 
216  if( mDoPlotStDev )
217  gr = new TGraph( x.size(), xArr, eArr );
218  else
219  gr = new TGraphErrors( x.size(), xArr, yArr, 0, eArr );
220  std::stringstream ss;
221 
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: ";
228 
229  ss << "Pedestal ";
230  if( mDoPlotStDev )
231  ss << "St. Dev. ";
232  ss << "vs. ";
233 
234  if( mPlotVsStrip == 'R' || mPlotVsStrip == 'r' || mPlotVsStrip == 'P' )
235  ss << "Position";
236  else
237  ss << "Channel";
238 
239  if( !mQuadName.empty() )
240  ss << ", Quad " << mQuadName;
241 
242  if( mPlotVsStrip == 'r' || mPlotVsStrip == 'R' )
243  ss << "; r Strip Pos. [cm]";
244  else if( mPlotVsStrip == 'P' )
245  ss << "; #phi Strip Pos. [cm]";
246  else
247  ss << "; 128x(APV Num) + Channel Id.";
248 
249  ss << "; ADC Value";
250 
251  gr->SetTitle( ss.str().data() );
252 
253  if( mDoPlotStDev )
254  gr->SetMarkerStyle(20);
255  };
256 
257  return gr;
258 };
259 
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 ]);
263 };
264 
265 
266 ClassImp( StFgtPedPlotter );