StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtSingleEventQA.cxx
1 /***************************************************************************
2  *
3  * $Id: StFgtSingleEventQA.cxx,v 1.1 2012/01/31 09:26:17 sgliske Exp $
4  * Author: S. Gliske, Jan 2012
5  *
6  ***************************************************************************
7  *
8  * Description: See header.
9  *
10  ***************************************************************************
11  *
12  * $Log: StFgtSingleEventQA.cxx,v $
13  * Revision 1.1 2012/01/31 09:26:17 sgliske
14  * StFgtQaMakers moved to StFgtPool
15  *
16  * Revision 1.5 2012/01/30 10:42:23 sgliske
17  * strip containers now contain adc values for
18  * all time bins. Also fixed bug where setType modified the timebin
19  * rather than the type.
20  *
21  * Revision 1.4 2012/01/26 13:13:12 sgliske
22  * Updated to use StFgtConsts, which
23  * replaces StFgtEnums and StFgtGeomDefs
24  *
25  * Revision 1.3 2012/01/24 06:27:35 sgliske
26  * debugged a bit more
27  *
28  * Revision 1.2 2012/01/24 05:45:31 sgliske
29  * debugged--mostly :)
30  *
31  * Revision 1.1 2012/01/24 03:32:16 sgliske
32  * creation
33  *
34  *
35  **************************************************************************/
36 
37 #include "StFgtSingleEventQA.h"
38 #include "StRoot/StFgtUtil/StFgtConsts.h"
39 
40 #include <string>
41 #include <TFile.h>
42 #include <TH2F.h>
43 
44 #include "StRoot/StFgtUtil/geometry/StFgtGeom.h"
45 
46 #include "StRoot/StEvent/StEvent.h"
47 #include "StRoot/StEvent/StFgtCollection.h"
48 #include "StRoot/StEvent/StFgtStripCollection.h"
49 #include "StRoot/StEvent/StFgtStrip.h"
50 
51 // constructors
52 StFgtSingleEventQA::StFgtSingleEventQA( const Char_t* name ) : StMaker( name ), mTFile( 0 ) {
53  // nothing
54 };
55 
56 // deconstructor
57 StFgtSingleEventQA::~StFgtSingleEventQA(){
58  if( mTFile ){
59  //mTFile->Close();
60  delete mTFile;
61  };
62 };
63 
64 Int_t StFgtSingleEventQA::Init(){
65  Int_t ierr = kStOk;
66 
67  mEventNum = 0;
68 
69  if( mFilename.empty() ){
70  mFilename = "fgtSingleEvents.root";
71  LOG_INFO << "Empty filename. Defaulting to '" << mFilename << "'" << endl;
72  };
73 
74  mTFile = new TFile( mFilename.data(), "RECREATE" );
75  if( !mTFile->IsOpen() ){
76  LOG_FATAL << "Error opening file '" << mFilename << "' "<< endm;
77  ierr = kStFatal;
78  };
79 
80  return ierr;
81 };
82 
84  Int_t ierr = kStOk;
85 
86  StEvent* eventPtr = 0;
87  mFgtCollectionPtr = 0;
88 
89  eventPtr = (StEvent*)GetInputDS("StEvent");
90  if( !eventPtr ) {
91  LOG_ERROR << "Error getting pointer to StEvent in '" << ClassName() << "'" << endm;
92  ierr = kStErr;
93  } else {
94  mFgtCollectionPtr=eventPtr->fgtCollection();
95 
96  if( !mFgtCollectionPtr) {
97  LOG_ERROR << "Error getting pointer to StFgtCollection in '" << ClassName() << "'" << endm;
98  ierr = kStErr;
99  };
100  };
101 
102  for( Int_t disc = 0; disc < kFgtNumDiscs; ++disc ){
103  StFgtStripCollection *stripCollectionPtr = 0;
104  if( !ierr ){
105  stripCollectionPtr = mFgtCollectionPtr->getStripCollection( disc );
106  };
107 
108  if( stripCollectionPtr ){
109  TH2F *hP[kFgtNumOctantsPerDisc*kFgtNumTimeBins], *hR[kFgtNumOctantsPerDisc*kFgtNumTimeBins];
110  for( TH2F** hPptr = hP, **hRptr = hR; hPptr != &hP[kFgtNumOctantsPerDisc*kFgtNumTimeBins]; ++hPptr, ++hRptr )
111  (*hPptr) = (*hRptr) = 0;
112 
113  const StSPtrVecFgtStrip &stripVec = stripCollectionPtr->getStripVec();
114  StSPtrVecFgtStripConstIterator stripIter;
115 
116  for( stripIter = stripVec.begin(); stripIter != stripVec.end(); ++stripIter ){
117  Int_t geoId = (*stripIter)->getGeoId();
118 
119  for( Int_t tb = 0; tb < kFgtNumTimeBins; ++tb ){
120  Short_t adc = (*stripIter)->getAdc(tb);
121 
122  // to store position data
123  Short_t disc, quad, strip;
124  Char_t layer;
125  StFgtGeom::decodeGeoId( geoId, disc, quad, layer, strip );
126 
127  // Note: r strips 0-279 and phi strips 0-359 are for
128  // the half of the quadrant with local coordinate phi
129  // in the range of pi/4 and pi/2. Note: phi increases
130  // for decreasing phi strip number. r strips in
131  // 400-679 and phi strips in 360-719 are for the local
132  // coordinate phi in the range 0 to pi/4. Short side
133  // is for phi strips near 720, i.e. short side has
134  // smaller local phi values than long side.
135  Bool_t octIsShort = ( layer == 'R' ? (strip > 279) : (strip > 359) );
136 
137  Int_t bin = ( quad*2 + octIsShort )*kFgtNumTimeBins + tb;
138  if( !hP[bin] )
139  makeHists( mEventNum, tb, disc, quad, octIsShort, hP[bin], hR[bin] );
140 
141  if( layer == 'P' ){
142  Double_t pos, high = 0, low = 0;
143  StFgtGeom::getPhysicalCoordinate( geoId, disc, quad, layer, pos, low, high );
144 
145  hP[bin]->SetBinContent( strip+1, 2, adc ); // larger r
146  if( low < 19.125 )
147  hP[bin]->SetBinContent( strip+1, 1, adc ); // smaller r--not all strips extend here
148  } else {
149  hR[bin]->SetBinContent( 1, strip+1, adc );
150  };
151  };
152  };
153 
154  mTFile->cd();
155  if( mTFile && mTFile->IsOpen() )
156  for( TH2F **hPptr = hP, **hRptr = hR; hPptr != &hP[kFgtNumOctantsPerDisc*kFgtNumTimeBins]; ++hPptr, ++hRptr )
157  if( (*hPptr) ){
158  (*hPptr)->Write();
159  (*hRptr)->Write();
160  };
161  };
162  };
163 
164  ++mEventNum;
165  return ierr;
166 };
167 
169  mTFile->Close();
170  return kStOk;
171 };
172 
173 void StFgtSingleEventQA::makeHists( Int_t ev, Int_t tb, Int_t disc, Int_t quad, Bool_t isShort, TH2F* &hP, TH2F* &hR ){
174  std::stringstream ss;
175  ss << "h"
176  << "_e" << ev
177  << "_t" << tb
178  << "_d" << disc
179  << "_q" << quad
180  << ( isShort ? 'S' : 'L' );
181  std::string nameP = ss.str() + "_P";
182  std::string nameR = ss.str() + "_R";
183 
184  mTFile->cd();
185  if( isShort ){
186  hP = new TH2F( nameP.data(), "", 360, 0, 360, 2, 0, 2 );
187  hR = new TH2F( nameR.data(), "", 1, 0, 0.7854, 280, 0, 280 );
188  } else {
189  hP = new TH2F( nameP.data(), "", 360, 360, 720, 2, 0, 2 );
190  hR = new TH2F( nameR.data(), "", 1, 0.7854, 1.5708, 280, 400, 680 );
191  };
192 };
193 
194 ClassImp(StFgtSingleEventQA);
Definition: Stypes.h:44
Definition: Stypes.h:41