StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTofMuDstReader.cxx
1 #include "StTofMuDstReader.h"
2 
3 #include "StChain.h"
4 #include "TF1.h"
5 #include "TRandom.h"
6 
7 #include <iostream>
8 #include <fstream>
9 #include <stdlib.h>
10 #include <string>
11 #include <vector>
12 #include <math.h>
13 #include <cmath>
14 
15 #include "PhysicalConstants.h"
16 #include "SystemOfUnits.h"
17 #include "StThreeVector.hh"
18 #include "StThreeVectorF.hh"
19 #include "StThreeVectorD.hh"
20 #include "StLorentzVectorD.hh"
21 
22 #include "StTriggerIdCollection.h"
23 #include "StTriggerId.h"
24 
25 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
26 #include "StMuDSTMaker/COMMON/StMuEvent.h"
27 #include "StMuDSTMaker/COMMON/StMuDst.h"
28 #include "StMuDSTMaker/COMMON/StMuTrack.h"
29 #include "StMuDSTMaker/COMMON/StMuTofHit.h"
30 
31 #include "StTofMuDstEval.h"
32 #include "tofHitTree.h"
33 
34 
35 
36 //_________________________________________________
37 StTofMuDstReader::StTofMuDstReader(const char *name, const char *file, StMuDstMaker* maker):StMaker(name)
38 {
39  // StTofMuDstReader Constructor
40  // - zero all pointers defined in the header file
41  mMuDstMaker = maker;
42  mOutputFile = new TFile(file,"RECREATE");
43  mOutputFile->SetCompressionLevel(1);
44  int BufSize=(int)pow(2.,16.);
45  int Split=1;
46  mTree = new TTree("T","T",BufSize);
47  mTree->SetAutoSave(10000); // autosave every 10 Mbytes
48  mTree->Branch("runId",&mTofHit.runId,"runId/I");
49  mTree->Branch("evtId",&mTofHit.evtId,"evtId/I");
50  mTree->Branch("vz",&mTofHit.vz,"vz/F");
51  mTree->Branch("mult",&mTofHit.mult,"mult/I");
52  mTree->Branch("neast",&mTofHit.neast,"neast/I");
53  mTree->Branch("nwest",&mTofHit.nwest,"nwest/I");
54  mTree->Branch("module",&mTofHit.module,"module/I");
55  mTree->Branch("cell",&mTofHit.cell,"cell/I");
56  mTree->Branch("tot",&mTofHit.tot,"tot/F");
57  mTree->Branch("tof",&mTofHit.tof,"tof/F");
58  mTree->Branch("L",&mTofHit.L,"L/F");
59  mTree->Branch("beta",&mTofHit.beta,"beta/F");
60  mTree->Branch("localY",&mTofHit.localY,"localY/F");
61  mTree->Branch("localZ",&mTofHit.localZ,"localZ/F");
62  mTree->Branch("deltaY",&mTofHit.deltaY,"deltaY/F");
63  mTree->Branch("m2",&mTofHit.m2,"m2/F");
64  mTree->Branch("trkId",&mTofHit.trkId,"trkId/I");
65  mTree->Branch("nHitsFit",&mTofHit.nHitsFit,"nHitsFit/I");
66  mTree->Branch("pt",&mTofHit.pt,"pt/F");
67  mTree->Branch("eta",&mTofHit.eta,"eta/F");
68  mTree->Branch("phi",&mTofHit.phi,"phi/F");
69  mTree->Branch("dca",&mTofHit.dca,"dca/F");
70  mTree->Branch("dEdx",&mTofHit.dEdx,"dEdx/F");
71  mTree->Branch("nSigmaPi",&mTofHit.nSigmaPi,"nSigmaPi/F");
72  mTree->Branch("nSigmaK",&mTofHit.nSigmaK,"nSigmaK/F");
73  mTree->Branch("nSigmaP",&mTofHit.nSigmaP,"nSigmaP/F");
74  mTree->Branch("nSigmaE",&mTofHit.nSigmaE,"nSigmaE/F");
75  mTree->Branch("nSigmaMu",&mTofHit.nSigmaMu,"nSigmaMu/F");
76  mTree->Branch("nSigmaTofPi",&mTofHit.nSigmaTofPi,"nSigmaTofPi/F");
77  mTree->Branch("nSigmaTofK",&mTofHit.nSigmaTofK,"nSigmaTofK/F");
78  mTree->Branch("nSigmaTofP",&mTofHit.nSigmaTofP,"nSigmaTofP/F");
79  mTree->Branch("nSigmaTofE",&mTofHit.nSigmaTofE,"nSigmaTofE/F");
80  eventNumber=0;
81  oldEventRunId=0;
82 }
83 
84 //_________________________________________________
85 StTofMuDstReader::~StTofMuDstReader()
86 {
87 }
88 
89 //_____________________________________________________________________________
90 
91 void StTofMuDstReader::Clear(const char*)
92 {
93  mTofHit.runId = -1;
94  mTofHit.evtId = -1;
95  mTofHit.vz = -999.;
96  mTofHit.mult = -999;
97  mTofHit.neast = 0;
98  mTofHit.nwest = 0;
99  mTofHit.module = 0;
100  mTofHit.cell = 0;
101  mTofHit.tot = -999.;
102  mTofHit.tof = -999.;
103  mTofHit.L = -999.;
104  mTofHit.beta = -999.;
105  mTofHit.localY = -999;
106  mTofHit.localZ = -999.;
107  mTofHit.deltaY = -999.;
108  mTofHit.m2 = -999.;
109  mTofHit.trkId = -1;
110  mTofHit.nHitsFit = 0;
111  mTofHit.pt = -999.;
112  mTofHit.eta = -999.;
113  mTofHit.phi = -999.;
114  mTofHit.dca = -999.;
115  mTofHit.dEdx = -999.;
116  mTofHit.nSigmaPi = -999.;
117  mTofHit.nSigmaK = -999.;
118  mTofHit.nSigmaP = -999.;
119  mTofHit.nSigmaE = -999.;
120  mTofHit.nSigmaMu = -999.;
121  mTofHit.nSigmaTofPi = -999.;
122  mTofHit.nSigmaTofK = -999.;
123  mTofHit.nSigmaTofP = -999.;
124  mTofHit.nSigmaTofE = -999.;
125 
126  StMaker::Clear();
127 }
128 
129 //_________________________________________________
131 {
132  mOutputFile->Write();
133  mOutputFile->Close();
134  return StMaker::Finish();
135 }
136 
137 
138 //_________________________________________________
139 Int_t StTofMuDstReader::Init()
140 {
141  Clear("C");
142  return kStOK;
143 }
144 //_________________________________________________
146 {
147  cout << "StTofMuDstReader::Make()" << endl;
148 
149  if( mMuDstMaker != NULL ) {
150  mMuDst = mMuDstMaker->muDst();
151  }
152 
153  if(!mMuDst) return kStOK;
154 
155  StTofMuDstEval *tofEval = (StTofMuDstEval *)GetMaker("tofMuDstEval");
156  if(!tofEval) return kStOK;
157 
158  StMuPrimaryVertex *vtx = mMuDst->primaryVertex();
159  if(!vtx) return kStOK;
160 
161  StMuEvent *muEvent = mMuDst->event();
162  if(!muEvent) return kStOK;
163 
164  StThreeVectorF vertexPos = muEvent->primaryVertexPosition();
165  if(fabs(vertexPos.x())<1.0e-5 && fabs(vertexPos.y())<1.0e-5 && fabs(vertexPos.z())<1.0e-5) return kStOK;
166 
167  int runId = muEvent->runId();
168  int evtId = muEvent->eventId();
169  int refMult = muEvent->refMultPos() + muEvent->refMultNeg();
170 
171  int nEast = 0;
172  int nWest = 0;
173  tofEval->GetPvpdNHits(nEast , nWest);
174  cout << " nEast = " << nEast << " nWest = " << nWest << endl;
175 
176  int nTofHits = mMuDst->numberOfTofHit();
177  int n = mMuDst->numberOfPrimaryTracks();
178  cout << " There are " << nTofHits << " TofHits in this event." << endl;
179  for(int i=0;i<nTofHits;i++) {
180  StMuTofHit *tof = (StMuTofHit*)mMuDst->tofHit(i);
181  if(!tof) continue;
182  int trkId = tof->associatedTrackId();
183  int index = -1;
184  for(int j=0;j<n;j++) {
185  StMuTrack* t = (StMuTrack*)mMuDst->primaryTracks(j);
186  if(!t) continue;
187  if(trkId==t->id()) {
188  index = j;
189  break;
190  }
191  } // end track loop
192  if(index<0||index>=n) {
193  cout << "Warning! no matched TPC track, strange!" << endl;
194  continue;
195  }
196  StMuTrack *trk = (StMuTrack*)mMuDst->primaryTracks(index);
197  if(!trk) continue;
198 
199  Double_t local[3];
200  tofEval->GetLocalHitPosition(tof, &local[0]);
201  Double_t yCenter = (tof->cellIndex()-1-2.5)*3.45;
202 
203  float m2 = pow(trk->pt()*TMath::CosH(trk->eta()),2.0)*(1./tof->beta()/tof->beta()-1.);
204 
205  mTofHit.runId = runId;
206  mTofHit.evtId = evtId;
207  mTofHit.vz = vertexPos.z();
208  mTofHit.mult = refMult;
209  mTofHit.neast = nEast;
210  mTofHit.nwest = nWest;
211  mTofHit.module = tof->moduleIndex();
212  mTofHit.cell = tof->cellIndex();
213  mTofHit.tot = tofEval->GetUncorrectedTot(tof);
214  mTofHit.tof = tof->timeOfFlight();
215  mTofHit.L = tof->pathLength();
216  mTofHit.beta = tof->beta();
217  mTofHit.localY = local[1];
218  mTofHit.localZ = local[2];
219  mTofHit.deltaY = local[1]-yCenter;
220  mTofHit.m2 = m2;
221  mTofHit.trkId = index;
222  mTofHit.nHitsFit = trk->nHitsFit(kTpcId)*trk->charge();
223  mTofHit.pt = trk->pt();
224  mTofHit.eta = trk->eta();
225  mTofHit.phi = trk->phi();
226  mTofHit.dca = abs(trk->dcaGlobal());
227  mTofHit.dEdx = trk->dEdx()*1.e+6;
228  mTofHit.nSigmaPi = trk->nSigmaPion();
229  mTofHit.nSigmaK = trk->nSigmaKaon();
230  mTofHit.nSigmaP = trk->nSigmaProton();
231  mTofHit.nSigmaE = trk->nSigmaElectron();
232  mTofHit.nSigmaMu = -999.;
233  mTofHit.nSigmaTofPi = tof->sigmaPion()/2.;
234  mTofHit.nSigmaTofK = tof->sigmaKaon()/2.;
235  mTofHit.nSigmaTofP = tof->sigmaProton()/2.;
236  mTofHit.nSigmaTofE = tof->sigmaElectron()/2.;
237 
238  mTree->Fill();
239 
240  }
241 
242 
243 
244  return kStOK;
245 }
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
unsigned short refMultNeg(int vtx_id=-1)
Reference multiplicity of negative particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:184
StMuDst * muDst()
Definition: StMuDstMaker.h:425
Double_t pt() const
Returns pT at point of dca to primary vertex.
Definition: StMuTrack.h:256
short id() const
Returns the track id(or key), is unique for a track node, i.e. global and primary tracks have the sam...
Definition: StMuTrack.h:228
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: tof.h:15
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
Double_t nSigmaPion() const
Returns Craig&#39;s distance to the calculated dE/dx band for pions in units of sigma.
Definition: StMuTrack.h:245
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
Double_t nSigmaElectron() const
Returns Craig&#39;s distance to the calculated dE/dx band for electrons in units of sigma.
Definition: StMuTrack.h:244
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
static StMuTofHit * tofHit(int i)
returns pointer to the i-th muTofHit
Definition: StMuDst.h:412
Definition: Stypes.h:40
Double_t dEdx() const
Returns measured dE/dx value.
Definition: StMuTrack.h:248
Double_t phi() const
Returns phi at point of dca to primary vertex.
Definition: StMuTrack.h:258
virtual Int_t Finish()
Definition: StMaker.cxx:776
Double_t nSigmaProton() const
Returns Craig&#39;s distance to the calculated dE/dx band for protons in units of sigma.
Definition: StMuTrack.h:247
StThreeVectorF dcaGlobal(Int_t vtx_id=-1) const
Returns 3D distance of closest approach to primary vertex of associated global track.
Definition: StMuTrack.cxx:371
Double_t nSigmaKaon() const
Returns Craig&#39;s distance to the calculated dE/dx band for kaons in units of sigma.
Definition: StMuTrack.h:246
unsigned short refMultPos(int vtx_id=-1)
Reference multiplicity of positive particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:173