StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtCosmicTrackQA.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtCosmicTrackQA.cxx,v 1.2 2012/01/31 16:48:34 wwitzke Exp $
4  * Author: C. K. Riley (ckriley@bnl.gov), Oct. 18 2011
5  *
6  ***************************************************************************
7  *
8  * Description: Plotting class for different histograms concerning
9  * cosmicstand tracks
10  *
11  ***************************************************************************
12  *
13  * $Log: StFgtCosmicTrackQA.cxx,v $
14  * Revision 1.2 2012/01/31 16:48:34 wwitzke
15  * Changed for cosmic test stand.
16  *
17  * Revision 1.1 2012/01/31 09:26:16 sgliske
18  * StFgtQaMakers moved to StFgtPool
19  *
20  * Revision 1.11 2012/01/30 10:42:23 sgliske
21  * strip containers now contain adc values for
22  * all time bins. Also fixed bug where setType modified the timebin
23  * rather than the type.
24  *
25  * Revision 1.10 2012/01/26 13:13:11 sgliske
26  * Updated to use StFgtConsts, which
27  * replaces StFgtEnums and StFgtGeomDefs
28  *
29  * Revision 1.9 2011/12/07 17:19:59 ckriley
30  * minor update
31  *
32  * Revision 1.8 2011/11/25 20:20:04 ckriley
33  * added statusmaker functionality
34  *
35  * Revision 1.7 2011/11/09 21:03:20 ckriley
36  * working version with current containers
37  *
38  * Revision 1.6 2011/11/01 19:07:24 sgliske
39  * Updated to correspond with StEvent containers, take 2.
40  *
41  * Revision 1.4 2011/10/26 20:39:18 ckriley
42  * compilation fix
43  *
44  * Revision 1.3 2011/10/25 20:43:32 ckriley
45  * added more plots
46  *
47  * Revision 1.2 2011/10/25 15:42:45 ckriley
48  * minor change
49  *
50  * Revision 1.1 2011/10/25 15:41:53 ckriley
51  * creation of StFgtCosmicTrackQA
52  *
53  **************************************************************************/
54 
55 #include "StFgtCosmicTrackQA.h"
56 
57 #include <string>
58 #include <TH1F.h>
59 #include <TH2F.h>
60 #include <TProfile.h>
61 #include <TROOT.h>
62 #include <TStyle.h>
63 #include <TCanvas.h>
64 #include "StMaker.h"
65 
66 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
67 #include "StRoot/StFgtPool/StFgtCosmicTestStandGeom/StFgtCosmicTestStandGeom.h"
68 
69 
70 #include "StRoot/StEvent/StFgtCollection.h"
71 #include "StRoot/StEvent/StFgtHit.h"
72 #include "StRoot/StEvent/StFgtPoint.h"
73 
74 // constructors
75 StFgtCosmicTrackQA::StFgtCosmicTrackQA( const Char_t* name,
76  Short_t discId,
77  Short_t quadId,
78  const Char_t* quadName ) :
79  StFgtQaMaker( name, discId, quadId, quadName ),
80  mPath(""), mFileNameBase(""), mFileNameKey( quadName )/*,mHist(0)*/{
81 
82  // set the style to plain
83  gROOT->SetStyle("Plain");
84 
85  // few defaults
86  mXbins = 1280;
87  mXmin = 0;
88  mXmax = mXbins;
89 
90  mYbins = 4096;
91  mYmin = 0;
92  mYmax = mYbins;
93 };
94 
95 StFgtCosmicTrackQA::StFgtCosmicTrackQA(const StFgtCosmicTrackQA&){
96  std::cerr << "TODO" << endl;
97  throw 0;
98 };
99 
100 // deconstructor
101 StFgtCosmicTrackQA::~StFgtCosmicTrackQA(){
102 /*
103  if( mHistAPV ) {
104  for( Int_t i=0;i<10;i++) {
105  delete mHistAPV[i];
106  }
107  }
108  if( mHist1Dcluster ) {
109  for( Int_t i=0;i<2;i++) {
110  delete mHist1Dcluster[i];
111  }
112  }
113  if( mHist1Dclusters )
114  delete mHist1Dclusters;
115  if( mHist2Dpoint )
116  delete mHist2Dpoint;
117 */
118 };
119 
120 // equals operator
121 StFgtCosmicTrackQA& StFgtCosmicTrackQA::operator=(const StFgtCosmicTrackQA&){
122  std::cerr << "TODO" << endl;
123  throw 0;
124 };
125 
126 // initializing CosmicTrackQA
127 Int_t StFgtCosmicTrackQA::Init(){
128  Int_t ierr = StFgtQaMaker::Init();
129 
130  if( !ierr ){
131 /*
132  // Take care of the histogram
133  if( mHistAPV ) {
134  for( Int_t i=0;i<10;i++) {
135  delete mHistAPV[i];
136  }
137  }
138  if( mHist1Dcluster ) {
139  for( Int_t i=0;i<2;i++) {
140  delete mHist1Dcluster[i];
141  }
142  }
143  if( mHist1Dclusters )
144  delete mHist1Dclusters;
145  if( mHist2Dpoint )
146  delete mHist2Dpoint;
147 */
148  // note: 10 APV chips plots per Quadrant
149  // naming the APV plots
150  std::string name, nameforhist, title;
151  {
152  std::stringstream ss;
153  ss << GetName() << "_" << mDiscId << "_" << mQuadId;
154  ss >> name;
155  };
156  // APV chip binning
157 
158  // regular
159  mXmin = -200;
160  mXmax = 500;
161  mXbins = 140;
162 /*
163  // 5sigma
164  mXmin = 0;
165  mXmax = 4000;
166  mXbins = 200;
167 */
168  string channelId[10]={"0-127","128-255","256-383","384-511","512-639","640-767","768-895","896-1023","1024-1151","1152-1279"};
169 
170  // easiest way to ensure stream is cleared is construct a new one
171  for(int i=0;i<10;i++) {
172  std::stringstream sx, sy, ss, sn, snx, sny;
173  ss << " Quad " << mQuadName << ", APV " << i
174  << ", Channels " << channelId[i] << "; adc-ped";
175  sn << name;
176  sn << "_" << i;
177  sn >> nameforhist;
178  title = ss.str();
179  //cout << "title = " << title << endl;
180 
181  mHistAPV[i] = new TH1F( nameforhist.data(), title.data(), mXbins/mBinFactorX, mXmin, mXmax );
182  }
183 
184  // naming test hist by plane
185 {
186  std::string name1DR, name1DP, title1DR, title1DP;
187  {
188  std::stringstream ss, sr, sp;
189  ss << GetName() << "_" << mDiscId << "_" << mQuadId;
190  sr << ss.str() << "_Rtest";
191  sp << ss.str() << "_Ptest";
192  sr >> name1DR;
193  sp >> name1DP;
194  };
195  // test plot binning
196  mXmin = 0;
197  mXmax = 720;
198  mXbins = 720;
199 
200  // easiest way to ensure stream is cleared is construct a new one
201  std::stringstream ss, sr ,sp;
202  ss << " Quad " << mQuadName << " hits";
203  sr << ss.str() << " in R; strip";
204  sp << ss.str() << " in Phi; strip";
205  title1DR = sr.str();
206  title1DP = sp.str();
207  //cout << "title = " << title1DR << endl;
208 
209  testHist[0] = new TH1F( name1DR.data(), title1DR.data(), mXbins/mBinFactorX, /*mXmin, mXmax*/ 0,720 );
210  testHist[1] = new TH1F( name1DP.data(), title1DP.data(), mXbins/mBinFactorX, /*mXmin, mXmax*/ 0,720 );
211 }
212 
213 
214  // naming 1D clusters by plane
215  std::string name1D, name1DR, name1DP, title1D, title1DR, title1DP;
216  {
217  std::stringstream ss, sr, sp;
218  ss << GetName() << "_" << mDiscId << "_" << mQuadId;
219  sr << ss.str() << "_R";
220  sp << ss.str() << "_P";
221  ss << "_C";
222  ss >> name1D;
223  sr >> name1DR;
224  sp >> name1DP;
225  };
226  // 1D cluster plot binning
227 
228  // regular
229  mXmin = 0;
230  mXmax = 4000;
231  mXbins = 400;
232 
233 /*
234  // 5sigma
235  mXmin = 0;
236  mXmax = 6000;
237  mXbins = 200;
238 */
239  // easiest way to ensure stream is cleared is construct a new one
240  std::stringstream ss, sr ,sp;
241  ss << " Quad " << mQuadName << " clusters";
242  sr << ss.str() << " in R; adc sum";
243  sp << ss.str() << " in Phi; adc sum";
244  ss << " in R & Phi; adc sum";
245  title1D = ss.str();
246  title1DR = sr.str();
247  title1DP = sp.str();
248  //cout << "title = " << title1DR << endl;
249 
250  mHist1Dclusters = new TH1F( name1D.data(), title1D.data(), mXbins/mBinFactorX, mXmin, mXmax/*8000*/ );
251  mHist1Dcluster[0] = new TH1F( name1DR.data(), title1DR.data(), mXbins/mBinFactorX, mXmin, mXmax );
252  mHist1Dcluster[1] = new TH1F( name1DP.data(), title1DP.data(), mXbins/mBinFactorX, mXmin, mXmax );
253 
254 
255  // naming 2D point plot
256  std::string name2D, title2D;
257  {
258  std::stringstream ss;
259  ss << GetName() << "_" << mDiscId << "_" << mQuadId;
260  ss >> name2D;
261  };
262  // 2Dcluster plot binning
263  mXmin = 0;
264  mXmax = 40;
265  mXbins = 40;
266 
267  // easiest way to ensure stream is cleared is construct a new one
268  std::stringstream sstream;
269  sstream << " Quad " << mQuadName << " cluster points; cm; cm";
270  title2D = sstream.str();
271  //cout << "title = " << title2D << endl;
272 
273  mHist2Dpoint = new TH2F( name2D.data(), title2D.data(), mXbins/mBinFactorX, mXmin, mXmax, mXbins/mBinFactorX, mXmin, mXmax );
274 
275  };
276  return ierr;
277 };
278 
279 // collect hit info for QA
281  Int_t ierr = StFgtQaMaker::Make();
282 
283  StFgtStripCollection *stripCollectionPtr = 0;
284  if( !ierr ){
285  stripCollectionPtr = mFgtCollectionPtr->getStripCollection( mDiscId );
286  };
287 
288  if( stripCollectionPtr ){
289 
290  const StSPtrVecFgtStrip &stripVec = stripCollectionPtr->getStripVec();
291  StSPtrVecFgtStripConstIterator stripIter;
292 
293  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
294  // this ADC is adc-ped if StFgtCorAdcMaker is called first
295  Int_t geoId = (*stripIter)->getGeoId();
296  Short_t adc = (*stripIter)->getAdc( mTimeBin );
297 
298  // to store position data
299  Short_t disc, quad; //, strip;
300  Char_t layer;
301 
302  Double_t pos, high, low;
303 
304  //StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
305  StFgtGeom::getPhysicalCoordinate( geoId, disc, quad, layer, pos, high, low );
306  if( disc == mDiscId && quad == mQuadId ){
307  Int_t rdo, arm, apv, channel;
308  StFgtCosmicTestStandGeom::getNaiveElecCoordFromGeoId(geoId,rdo,arm,apv,channel);
309 
310  // fill histogram per apv chip
311  if(disc==2) apv -= 12; // for disc2, apv# range from 12-23
312  mHistAPV[apv]->Fill ( adc );
313  };
314 
315  // looking for hot channels simpleClusterAlgo use this
316  Short_t stripId;
317  StFgtGeom::decodeGeoId(geoId,disc,quad,layer,stripId);
318  if(layer=='R') testHist[0]->Fill( stripId );
319  else testHist[1]->Fill( stripId );
320  };
321  };
322 
323 
324  StFgtHitCollection *hitCollectionPtr = 0;
325  if( !ierr ){
326  hitCollectionPtr = mFgtCollectionPtr->getHitCollection( mDiscId );
327  };
328 
329  if( hitCollectionPtr ){
330  const StSPtrVecFgtHit &hitVec = hitCollectionPtr->getHitVec();
331  StSPtrVecFgtHitConstIterator hitIter;
332 
333  Short_t adcSum=0;
334  // LOG_INFO << "We have " << hitVec.size() << " clusters " << endm;
335  for( hitIter = hitVec.begin(); hitIter != hitVec.end(); ++hitIter ){
336  Bool_t haveR=false;
337 
338  haveR=((*hitIter)->getLayer()=='R');
339 
340 /* // looking for hot channels maxClusterAlgo use this
341  Int_t geoId = (*hitIter)->getCentralStripGeoId();
342  //Int_t rdo, arm, apv, channel;
343  // StFgtCosmicTestStandGeom::getNaive...
344  Short_t disc, quad, stripId;
345  Char_t layer;
346  StFgtGeom::decodeGeoId(geoId,disc,quad,layer,stripId);
347  if(haveR) testHist[0]->Fill( stripId );
348  else testHist[1]->Fill( stripId );
349 */
350 
351  if( haveR ) mHist1Dcluster[0]->Fill( (*hitIter)->charge() );
352  else mHist1Dcluster[1]->Fill( (*hitIter)->charge() );
353  adcSum += (*hitIter)->charge();
354  };
355  //if(adcSum>=200) mHist1Dclusters->Fill( adcSum );
356  if(adcSum!=0) mHist1Dclusters->Fill( adcSum ); // for ped files
357  };
358 
359  StFgtPointCollection *pointCollectionPtr = 0;
360  if( !ierr ){
361  pointCollectionPtr = mFgtCollectionPtr->getPointCollection();
362  };
363 
364  if( pointCollectionPtr ){
365  const StSPtrVecFgtPoint &pointVec = pointCollectionPtr->getPointVec();
366  StSPtrVecFgtPointConstIterator pointIter;
367 
368  // LOG_INFO << "We have " << pointVec.size() << " points " << endm;
369  for( pointIter = pointVec.begin(); pointIter != pointVec.end(); ++pointIter ){
370  if( (*pointIter)->getDisc() == mDiscId ){
371  Float_t R = (*pointIter)->getPositionR();
372  Float_t Phi = (*pointIter)->getPositionPhi();
373 
374  mHist2Dpoint->Fill( R*cos(Phi+.2618) , R*sin(Phi+.2618) );
375  };
376  };
377  };
378 
379  return ierr;
380 };
381 
382 // make the histogram pretty and save it to a file, if given a filename base
384  //cout << "StFgtCosmicTrackQA::Finish()" << endl;
385  // remove hot bins (over 3 sigma say) -> I actually want to look at specific strip... for now just look at removing hot bins
386 /* Float_t avg2Dpoint = 0;
387  Float_t sigma = 0;
388  Int_t numXbins = 40;
389  Int_t numYbins = 40;
390  for(Int_t i=0;i<numXbins;i++) {
391  for(Int_t j=0;j<numYbins;j++) {
392  Float_t con2Dpoint = mHist2Dpoint -> GetBinContent(i+1,j+1);
393  avg2Dpoint += con2Dpoint;
394  }
395  }
396  avg2Dpoint /= numXbins*numYbins;
397  for(Int_t i=0;i<numXbins;i++) {
398  for(Int_t j=0;j<numYbins;j++) {
399  Float_t con2Dpoint = mHist2Dpoint -> GetBinContent(i+1,j+1);
400  sigma += (con2Dpoint-avg2Dpoint)*(con2Dpoint-avg2Dpoint);
401  }
402  }
403  sigma /= numXbins*numYbins;
404  sigma = sqrt(sigma);
405  for(Int_t i=0;i<numXbins;i++) {
406  for(Int_t j=0;j<numYbins;j++) {
407  Float_t con2Dpoint = mHist2Dpoint -> GetBinContent(i+1,j+1);
408  if(con2Dpoint > avg2Dpoint+3*sigma)
409  mHist2Dpoint -> SetBinContent(i+1,j+1,0);
410  }
411  }
412 */
413 /*
414  // Find hot strips and for removal > 5 sigma
415  Float_t avgStripHitsR = 0, avgStripHitsP = 0;
416  Float_t sigmaR = 0, sigmaP = 0;
417  Int_t numXbins = 720;
418  for(Int_t i=0;i<numXbins;i++) {
419  Float_t conStripHitsR = testHist[0] -> GetBinContent(i+1);
420  Float_t conStripHitsP = testHist[1] -> GetBinContent(i+1);
421  avgStripHitsR += conStripHitsR;
422  avgStripHitsP += conStripHitsP;
423  }
424  avgStripHitsR /= numXbins;
425  avgStripHitsP /= numXbins;
426  for(Int_t i=0;i<numXbins;i++) {
427  Float_t conStripHitsR = testHist[0] -> GetBinContent(i+1);
428  sigmaR += (conStripHitsR-avgStripHitsR)*(conStripHitsR-avgStripHitsR);
429  Float_t conStripHitsP = testHist[1] -> GetBinContent(i+1);
430  sigmaP += (conStripHitsP-avgStripHitsP)*(conStripHitsP-avgStripHitsP);
431  }
432  sigmaR /= numXbins;
433  sigmaP /= numXbins;
434  sigmaR = sqrt(sigmaR);
435  sigmaP = sqrt(sigmaP);
436  cout << "\nFor " << mFileNameKey << "\nHot R channels: ";
437  for(Int_t i=0;i<numXbins;i++) {
438  Float_t conStripHitsR = testHist[0] -> GetBinContent(i+1);
439  if(conStripHitsR > avgStripHitsR+5*sigmaR)
440  cout << i << " ";
441  }
442  cout << "\nHot Phi channels: ";
443  for(Int_t i=0;i<numXbins;i++) {
444  Float_t conStripHitsP = testHist[1] -> GetBinContent(i+1);
445  if(conStripHitsP > avgStripHitsP+5*sigmaP)
446  cout << i << " ";
447  }
448  cout << endl;
449 */
450  if( !mFileNameBase.empty() ){
451 
452  // filename
453  std::string filename;
454  if( !mPath.empty() )
455  filename = mPath + "/";
456  filename += mFileNameBase;
457  if( !mFileNameKey.empty() )
458  filename += std::string( "." ) + mFileNameKey;
459  filename += ".eps";
460 
461  // draw
462  gROOT->SetStyle("Plain");
463  TCanvas *canAPV = new TCanvas( "fgtTrackQAcanAPV", "fgtTrackQAcanAPV", 900, 400 );
464  gStyle->SetOptStat(0);
465  gStyle->SetOptDate(0);
466  Int_t pad=1;
467  canAPV->Divide(5,2);
468  for( Int_t i=0;i<10;i++) {
469  canAPV->cd(pad);
470  mHistAPV[i]->Draw();
471  pad++;
472  }
473 
474  TCanvas *can2Dpoint = new TCanvas( "fgtTrackQAcan2Dpoint", "fgtTrackQAcan2Dpoint", 900, 400 );
475  gStyle->SetOptStat(0);
476  gStyle->SetOptDate(0);
477  mHist2Dpoint->Draw();
478 
479 
480  TCanvas *can1Dcluster = new TCanvas( "fgtTrackQAcan1Dcluster", "fgtTrackQAcan1Dcluster", 900, 400 );
481  gStyle->SetOptStat(100000);
482  gStyle->SetOptDate(0);
483  can1Dcluster->Divide(2,1);
484  can1Dcluster->cd(1);
485  mHist1Dcluster[0]->Draw();
486  can1Dcluster->cd(2);
487  mHist1Dcluster[1]->Draw();
488 
489  TCanvas *can1Dclusters = new TCanvas( "fgtTrackQAcan1Dclusters", "fgtTrackQAcan1Dclusters", 900, 400 );
490  gStyle->SetOptStat(100000);
491  gStyle->SetOptDate(0);
492  mHist1Dclusters->Draw();
493 
494  canAPV->Print( filename.data() );
495  can2Dpoint->Print( filename.data() );
496  can1Dcluster->Print( filename.data() );
497  can1Dclusters->Print( filename.data() );
498  delete canAPV;
499  delete can2Dpoint;
500  delete can1Dcluster;
501  delete can1Dclusters;
502  };
503 
504  return kStOk;
505 };
506 
507 void StFgtCosmicTrackQA::Clear( Option_t *opt ) {
508 
509 };
510 
511 
512 ClassImp(StFgtCosmicTrackQA);
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
virtual Int_t Make()
void Clear(Option_t *opt="")
User defined functions.
Definition: Stypes.h:41