StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtQaAdcVsChannel.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtQaAdcVsChannel.cxx,v 1.2 2012/01/31 16:48:34 wwitzke Exp $
4  * Author: S. Gliske, Sept 2011
5  *
6  ***************************************************************************
7  *
8  * Description: See header.
9  *
10  ***************************************************************************
11  *
12  * $Log: StFgtQaAdcVsChannel.cxx,v $
13  * Revision 1.2 2012/01/31 16:48:34 wwitzke
14  * Changed for cosmic test stand.
15  *
16  * Revision 1.1 2012/01/31 09:26:17 sgliske
17  * StFgtQaMakers moved to StFgtPool
18  *
19  * Revision 1.13 2012/01/30 10:42:23 sgliske
20  * strip containers now contain adc values for
21  * all time bins. Also fixed bug where setType modified the timebin
22  * rather than the type.
23  *
24  * Revision 1.12 2012/01/26 13:13:11 sgliske
25  * Updated to use StFgtConsts, which
26  * replaces StFgtEnums and StFgtGeomDefs
27  *
28  * Revision 1.11 2011/11/01 19:07:24 sgliske
29  * Updated to correspond with StEvent containers, take 2.
30  *
31  * Revision 1.10 2011/10/04 18:45:22 sgliske
32  * made cut on short events optional
33  *
34  * Revision 1.9 2011/09/30 19:05:31 sgliske
35  * general update
36  *
37  * Revision 1.8 2011/09/29 18:39:21 sgliske
38  * Update for geoId->elecCoord function now in StFgtCosmicTestStandGeom
39  *
40  * Revision 1.7 2011/09/28 17:48:50 sgliske
41  * minor updates
42  *
43  * Revision 1.6 2011/09/27 15:28:17 sgliske
44  * added common StFgtQaMaker parent
45  *
46  * Revision 1.5 2011/09/27 00:49:01 sgliske
47  * cosmic QA update
48  *
49  * Revision 1.4 2011/09/26 16:55:53 sgliske
50  * Continued work on cosmic QA plots
51  *
52  * Revision 1.3 2011/09/24 02:14:10 sgliske
53  * updated FGT cosmic QA
54  *
55  * Revision 1.2 2011/09/22 21:21:35 sgliske
56  * working on adding in ped. subtr.
57  *
58  * Revision 1.1 2011/09/21 20:26:46 sgliske
59  * creation
60  *
61  *
62  *
63  **************************************************************************/
64 
65 #include "StFgtQaAdcVsChannel.h"
66 
67 #include <string>
68 #include <TH2F.h>
69 #include <TROOT.h>
70 #include <TStyle.h>
71 #include <TCanvas.h>
72 #include "StMaker.h"
73 
74 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
75 
76 #include "StRoot/StEvent/StFgtCollection.h"
77 #include "StRoot/StEvent/StFgtStripCollection.h"
78 
79 
80 // constructors
81 StFgtQaAdcVsChannel::StFgtQaAdcVsChannel( const Char_t* name,
82  Short_t discId,
83  Short_t quadId,
84  const Char_t* quadName ) :
85  StFgtQaMaker( name, discId, quadId, quadName ),
86  mPath(""), mFileNameBase(""), mFileNameKey( quadName ), mHist(0) {
87 
88  // few defaults
89  mXbins = 1280;
90  mXmin = 0;
91  mXmax = mXbins;
92 
93  mYbins = 4096;
94  mYmin = 0;
95  mYmax = mYbins;
96 };
97 
98 StFgtQaAdcVsChannel::StFgtQaAdcVsChannel(const StFgtQaAdcVsChannel&){
99  std::cerr << "TODO" << endl;
100  throw 0;
101 };
102 
103 // deconstructor
104 StFgtQaAdcVsChannel::~StFgtQaAdcVsChannel(){
105  if( mHist )
106  delete mHist;
107 };
108 
109 // equals operator
110 StFgtQaAdcVsChannel& StFgtQaAdcVsChannel::operator=(const StFgtQaAdcVsChannel&){
111  std::cerr << "TODO" << endl;
112  throw 0;
113 };
114 
115 Int_t StFgtQaAdcVsChannel::Init(){
116  Int_t ierr = StFgtQaMaker::Init();
117 
118  if( !ierr ){
119  // Take care of the histogram
120 
121  if( mHist )
122  delete mHist;
123 
124  std::string name, title;
125  {
126  std::stringstream ss;
127  ss << GetName() << "_" << mDiscId << "_" << mQuadId << "_" << mDoVsStrip << mDoSubtrPeds;
128  ss >> name;
129  };
130 
131  // easiest way to ensure stream is cleared is construct a new one
132  std::stringstream ss;
133 
134  if( mDoVsStrip == 'r' )
135  ss << "r-strips, cham. 1: ";
136  else if( mDoVsStrip == 'R' )
137  ss << "r-strips, cham. 2: ";
138  else if( mDoVsStrip == 'P' )
139  ss << "#phi-strips: ";
140 
141  ss << "ADC ";
142  if( mDoSubtrPeds )
143  ss << "(ped sub) ";
144  if( mDoVsStrip == 'R' || mDoVsStrip == 'r' || mDoVsStrip == 'P' )
145  ss << "vs. Position";
146  else
147  ss << "vs. Channel";
148 
149  ss << ", Quad " << mQuadName;
150 
151  if( mDoVsStrip == 'R' || mDoVsStrip == 'r' )
152  ss << "; r [cm]";
153  else if( mDoVsStrip == 'P' )
154  ss << "; #phi [rad]";
155  else
156  ss << "; 128x(APV Num) + Channel Id.";
157 
158  ss << "; ADC Value";
159  title = ss.str();
160 
161  //cout << "title = " << title << endl;
162 
163  mXmin = 0;
164  mXmax = 1280;
165  mXbins = 1280;
166  if( mDoVsStrip == 'r' || mDoVsStrip == 'R' ){
167  mXmin = 10;
168  mXmax = 40;
169  mXbins = 280;
170  } else if ( mDoVsStrip == 'P' ){
171  mXmin = 0;
172  mXmax = 6.28/4;
173  mXbins = 720;
174  };
175 
176  mHist = new TH2F( name.data(), title.data(), mXbins/mBinFactorX, mXmin, mXmax, mYbins/mBinFactorY, mYmin, mYmax );
177  };
178 
179  return ierr;
180 };
181 
183  Int_t ierr = StFgtQaMaker::Make();
184 
185  StFgtStripCollection *stripCollectionPtr = 0;
186  if( !ierr ){
187  stripCollectionPtr = mFgtCollectionPtr->getStripCollection( mDiscId );
188  };
189 
190  if( stripCollectionPtr ){
191 
192  const StSPtrVecFgtStrip &stripVec = stripCollectionPtr->getStripVec();
193  StSPtrVecFgtStripConstIterator stripIter;
194 
195  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
196  Int_t geoId = (*stripIter)->getGeoId();
197  Short_t adc = (*stripIter)->getAdc( mTimeBin );
198 
199  // to store position data
200  Short_t disc, quad; //, strip;
201  Char_t layer;
202 
203  Double_t pos, high, low;
204 
205  //StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
206  StFgtGeom::getPhysicalCoordinate( geoId, disc, quad, layer, pos, high, low );
207 
208  if( disc == mDiscId && quad == mQuadId ){
209  Float_t bin = 0;
210 
211  Bool_t pass = 0;
212  if( mDoVsStrip == 'R' || mDoVsStrip == 'r' ){
213  pass = ( layer == 'R' );
214  pass &= ( mDoVsStrip == 'R' ? (low > 0.785) : (low < 0.785) );
215  bin = pos;
216  } else if( mDoVsStrip == 'P' ){
217  pass = ( layer == 'P' );
218  bin = pos;
219  } else {
220  pass = 1;
221 
222  Int_t rdo, arm, apv, channel;
223  StFgtCosmicTestStandGeom::getNaiveElecCoordFromGeoId(geoId,rdo,arm,apv,channel);
224  bin = 128*(apv%12) + channel;
225  };
226 
227  //cerr << "QA mDoSubtrPeds = " << mDoSubtrPeds << endl;
228  //cout << geoId << " adc = " << adc << endl;
229  if( mDoSubtrPeds && pass ){
230  pass = 0;
231  Float_t ped = 0, err = 0;
232 
233  mPedReader->getPed( geoId, mTimeBin, ped, err );
234  adc -= ped;
235  pass = (adc > mPedThres*err );
236  };
237 
238  if( pass )
239  mHist->Fill( bin, adc );
240  };
241  };
242  };
243 
244  return ierr;
245 };
246 
247 // make the histogram pretty and save it to a file, if given a filename base
249  //cout << "StFgtQaAdcVsChannel::Finish()" << endl;
250 
251  if( !mFileNameBase.empty() ){
252 
253  // filename
254  std::string filename;
255  if( !mPath.empty() )
256  filename = mPath + "/";
257  filename += mFileNameBase;
258  if( !mFileNameKey.empty() )
259  filename += std::string( "." ) + mFileNameKey;
260  filename += ".eps";
261 
262  // draw
263  gROOT->SetStyle("Plain");
264  TCanvas *can = new TCanvas( "fgtQAcan", "fgtQAcan", 900, 400 );
265 
266  gStyle->SetOptStat(0);
267  gStyle->SetPalette(1);
268  mHist->Draw("COLZ");
269 
270  can->Print( filename.data() );
271 
272  delete can;
273  };
274 
275  return kStOk;
276 };
277 
278 ClassImp(StFgtQaAdcVsChannel);
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
virtual Int_t Make()
Definition: Stypes.h:41