StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofMatchEffMaker.cxx
1 /*******************************************************************
2  *
3  * $Id: StBTofMatchEffMaker.cxx,v 1.4 2018/02/26 23:26:51 smirnovd Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: TPC->TOF match efficiency maker
9  *
10  *******************************************************************/
11 #include <iostream>
12 #include "StEventTypes.h"
13 #include "Stypes.h"
14 #include "StThreeVectorF.hh"
15 #include "StHelix.hh"
16 #include "StTrackGeometry.h"
17 #include "StDedxPidTraits.h"
18 #include "StTrackPidTraits.h"
19 #include "StBTofPidTraits.h"
20 #include "StarClassLibrary/StParticleTypes.hh"
21 #include "StarClassLibrary/StParticleDefinition.hh"
22 #include "StTpcDedxPidAlgorithm.h"
23 #include "StEventUtilities/StuRefMult.hh"
24 #include "PhysicalConstants.h"
25 #include "StHelix.hh"
26 #include "TH1.h"
27 #include "TH2.h"
28 #include "TFile.h"
29 #include "TTree.h"
30 #include "StMessMgr.h"
31 #include "StMemoryInfo.hh"
32 #include "StTimer.hh"
33 #include "StBTofMatchEffMaker.h"
34 //#include "TMemStat.h"
35 
36 
37 //---------------------------------------------------------------------------
39  // set default values
40  mEventCounter = 0;
41  mAcceptedEventCounter = 0;
42  mTofEventCounter = 0;
43  mAcceptAndBeam = 0;
44 
45  setMinFitPointsPerTrack(15);
46  setMinFitPointsOverMax(0.52);
47  setMaxDCA(3.);
48 
49  setCreateHistoFlag(kFALSE);
50  setHistoFileName("tofana.root");
51  doPrintMemoryInfo = kFALSE;
52  doPrintCpuInfo = kFALSE;
53 }
54 
55 StBTofMatchEffMaker::~StBTofMatchEffMaker(){ /* nope */}
56 
57 //void StBTofMatchEffMaker::Clear(Option_t *opt){StMaker::Clear();}
58 
59 //---------------------------------------------------------------------------
60 Int_t StBTofMatchEffMaker::Init(){
61  LOG_INFO << "StBTofMatchEffMaker -- initializing ..." << endm;
62  if(Debug()) {
63  LOG_INFO << "Minimum fitpoints per track: " << mMinFitPointsPerTrack << endm;
64  LOG_INFO << "Minimum fitpoints over max: " << mMinFitPointsOverMax << endm;
65  LOG_INFO << "Maximum DCA: " << mMaxDCA << endm;
66  }
67 
68  // m_Mode can be set by SetMode() method
69  if(m_Mode) {
70 // setHistoFileName("tofana.root");
71  } else {
72  setHistoFileName("");
73  }
74 
75  if (mHisto){
76  bookHistograms();
77  LOG_INFO << "Histograms are booked" << endm;
78  if (mHistoFileName!="") {
79  LOG_INFO << "Histograms will be stored in " << mHistoFileName.c_str() << endm;
80  }
81  }
82 
83  // reset event counters
84  mEventCounter = 0;
85  mAcceptedEventCounter = 0;
86  mTofEventCounter = 0;
87  mAcceptAndBeam = 0;
88 
89  return kStOK;
90 }
91 
92 //---------------------------------------------------------------------------
94 
95  LOG_INFO << "StBTofMatchEffMaker ----- RUN SUMMARY ----- (Finish)\n"
96  << "\tProcessed " << mEventCounter << " events."
97  << " Accepted " << mAcceptedEventCounter << " events."
98  << " Rejected " << mEventCounter - mAcceptedEventCounter << " events\n"
99  << "\tTOF events " << mTofEventCounter
100  << "\t Accept & Beam " << mAcceptAndBeam << " events" << endm;
101 
102  //if (mHisto) writeHistogramsToFile();
103  if (mHistoFileName!="") writeHistogramsToFile();
104  return kStOK;
105 }
106 
107 
108 //---------------------------------------------------------------------------
110  LOG_INFO << "StBTofMatchEffMaker -- welcome" << endm;
111  if(Debug()) LOG_INFO << " processing event ... " << endm;
112 
113  if(mHisto) mEventCounterHisto->Fill(0);
114  // event selection ...
115  mEvent = (StEvent *) GetInputDS("StEvent");
116  if (!validEvent(mEvent)){
117  LOG_INFO << "StBTofMatchEffMaker -- nothing to do ... bye-bye" << endm;
118  return kStOK;
119  }
120 
121  // timing & memory info -only when requested-
122  StTimer timer;
123  if (doPrintCpuInfo) timer.start();
124  if (doPrintMemoryInfo) StMemoryInfo::instance()->snapshot();
125 
126  //.........................................................................
127  // check for tofCollection and fill local copy with ADC and TDC data
128  StBTofCollection *theTof = mEvent->btofCollection(); if (theTof){};
129 
130  //.........................................................................
132  //
133 
134  StSPtrVecTrackNode& nodes = mEvent->trackNodes();
135  Int_t nAllTracks=0;
136  for (unsigned int iNode=0; iNode<nodes.size(); iNode++){
137  StPrimaryTrack *theTrack = dynamic_cast<StPrimaryTrack*>(nodes[iNode]->track(primary));
138  if(!validTrack(theTrack)) continue;
139 
140  StThreeVectorF mom = theTrack->geometry()->momentum();
141  float pt = mom.perp();
142  float eta = mom.pseudoRapidity();
143  int q = theTrack->geometry()->charge();
144 
145  float nSigmaPion = -999.;
146  float nSigmaKaon = -999.;
147  float nSigmaProton = -999.;
148  static StPionPlus* Pion = StPionPlus::instance();
149  static StKaonPlus* Kaon = StKaonPlus::instance();
150  static StProton* Proton = StProton::instance();
151 
152  static StTpcDedxPidAlgorithm PidAlgorithm;
153  const StParticleDefinition* pd = theTrack->pidTraits(PidAlgorithm);
154  if (pd) {
155  nSigmaPion = PidAlgorithm.numberOfSigma(Pion);
156  nSigmaKaon = PidAlgorithm.numberOfSigma(Kaon);
157  nSigmaProton = PidAlgorithm.numberOfSigma(Proton);
158  }
159 
160  nAllTracks++;
161 
162  if(mHisto) {
163  if(fabs(nSigmaPion)<2.) mPionDen->Fill(pt, eta);
164  if(fabs(nSigmaKaon)<2.) mKaonDen->Fill(pt, eta);
165  if(fabs(nSigmaProton)<2.) {
166  if(q>0) mProtonDen->Fill(pt, eta);
167  else mAntiPDen->Fill(pt, eta);
168  }
169  }
170 
171  const StPtrVecTrackPidTraits& theTofPidTraits = theTrack->pidTraits(kTofId);
172  if(theTofPidTraits.size()) continue;
173 
174  StTrackPidTraits *theSelectedTrait = theTofPidTraits[theTofPidTraits.size()-1];
175  if(!theSelectedTrait) continue;
176 
177  StBTofPidTraits *pidTof = dynamic_cast<StBTofPidTraits *>(theSelectedTrait);
178  if(!pidTof) continue;
179 
180  if(pidTof->matchFlag()<=0) continue; // no match
181 
182  if(mHisto) {
183  if(fabs(nSigmaPion)<2.) mPionNum->Fill(pt, eta);
184  if(fabs(nSigmaKaon)<2.) mKaonNum->Fill(pt, eta);
185  if(fabs(nSigmaProton)<2.) {
186  if(q>0) mProtonNum->Fill(pt, eta);
187  else mAntiPNum->Fill(pt, eta);
188  }
189  }
190 
191 
192  } // loop over nodes
193 
194 
195  if (doPrintMemoryInfo) {
196  StMemoryInfo::instance()->snapshot();
197  StMemoryInfo::instance()->print();
198  }
199  if (doPrintCpuInfo) {
200  timer.stop();
201  LOG_INFO << "CPU time for StBTofMatchEffMaker::Make(): "
202  << timer.elapsedTime() << " sec" << endm;
203  }
204 
205  LOG_INFO << "StBTofMatchEffMaker -- bye-bye" << endm;
206 
207  return kStOK;
208 }
209 
210 //---------------------------------------------------------------------------
211 // Book histograms and create ordered collection for easy manipulation
212 void StBTofMatchEffMaker::bookHistograms(void){
213 
214  mEventCounterHisto = new TH1D("eventCounter","eventCounter",20,0,20);
215 
216  mPionDen = new TH2D("pionDen","pionDen",500,0.,5.,40,-1.,1.);
217  mKaonDen = new TH2D("kaonDen","kaonDen",500,0.,5.,40,-1.,1.);
218  mProtonDen = new TH2D("protonDen","protonDen",500,0.,5.,40,-1.,1.);
219  mAntiPDen = new TH2D("antiPDen","antiPDen",500,0.,5.,40,-1.,1.);
220 
221  mPionNum = new TH2D("pionNum","pionNum",500,0.,5.,40,-1.,1.);
222  mKaonNum = new TH2D("kaonNum","kaonNum",500,0.,5.,40,-1.,1.);
223  mProtonNum = new TH2D("protonNum","protonNum",500,0.,5.,40,-1.,1.);
224  mAntiPNum = new TH2D("antiPNum","antiPNum",500,0.,5.,40,-1.,1.);
225 
226  return;
227 }
228 
229 
230 //---------------------------------------------------------------------------
231 // store histograms in a seperate root file
232 void StBTofMatchEffMaker::writeHistogramsToFile(){
233  // Output file
234  TFile *theHistoFile = new TFile(mHistoFileName.c_str(), "RECREATE");
235  LOG_INFO << "StBTofMatchEffMaker::writeHistogramsToFile()"
236  << " histogram file " << mHistoFileName << endm;
237 
238  theHistoFile->cd();
239 
240  if(mHisto) {
241 
242  mEventCounterHisto->Write();
243 
244  mPionDen->Write();
245  mKaonDen->Write();
246  mProtonDen->Write();
247  mAntiPDen->Write();
248 
249  mPionNum->Write();
250  mKaonNum->Write();
251  mProtonNum->Write();
252  mAntiPNum->Write();
253 
254  theHistoFile->Write();
255  theHistoFile->Close();
256 
257  }
258 
259  return;
260 }
261 
262 //---------------------------------------------------------------------------
263 // determine whether this is a valid TOF beam event
264 bool StBTofMatchEffMaker::validEvent(StEvent *event){
265  mEventCounter++;
266  // 1. must have non-zero pointer
267  if (!event) return false;
268  if(mHisto) mEventCounterHisto->Fill(1);
269 
270  // 2. must have a valid primary vertex
271  if (!event->primaryVertex()) return false;
272  mAcceptedEventCounter++;
273  if(mHisto) mEventCounterHisto->Fill(2);
274 
275  return true;
276 }
277 
278 
279 //---------------------------------------------------------------------------
280 // determine whether this is a valid TPC track
281 bool StBTofMatchEffMaker::validTrack(StTrack *track){
282  // 1. no track, no go.
283  if (!track) return false;
284 
285  // 2. track quality flag, should be >0
286  if (track->flag()<=0) return false;
287 
288  // 3. minimum #hits per track - not necessary now in ITTF
289 // if (track->topologyMap().numberOfHits(kTpcId) < mMinHitsPerTrack) return false;
290  // 4. minimum #fit points per track
291  if (track->fitTraits().numberOfFitPoints(kTpcId) < mMinFitPointsPerTrack) return false;
292  // 5. minimum #fit points over #maximum points
293  float ratio = (1.0*track->fitTraits().numberOfFitPoints(kTpcId)) / (1.0*track->numberOfPossiblePoints(kTpcId));
294  if (ratio < mMinFitPointsOverMax) return false;
295  // 6. maximum dca
296  if (track->impactParameter() > mMaxDCA) return false;
297 
298  return true;
299 }
300 
301 /*****************************************************************
302  *
303  * $Log: StBTofMatchEffMaker.cxx,v $
304  * Revision 1.4 2018/02/26 23:26:51 smirnovd
305  * StTof: Remove outdated ClassImp macro
306  *
307  * Revision 1.3 2018/02/26 23:13:20 smirnovd
308  * Move embedded CVS log messages to the end of file
309  *
310  * Revision 1.2 2010/01/28 18:16:53 perev
311  * WarningOff
312  *
313  * Revision 1.1 2009/02/26 21:23:17 dongx
314  * first release - example to calculate the TPC->TOF matching efficiency
315  *
316  */
Int_t m_Mode
counters
Definition: StMaker.h:81
unsigned char matchFlag() const
Matching information.
Int_t Make()
initial functions - DaqMap, Geometry Alignment, INL are extracted from db
StBTofMatchEffMaker(const Char_t *name="btofMatch")
Default constructor.
Definition: Stypes.h:40