63 #include "StEStructMCReader.h"
64 #include "StEStructPool/AnalysisMaker/StEStructEventCuts.h"
65 #include "StEStructPool/AnalysisMaker/StEStructTrackCuts.h"
66 #include "StEStructPool/EventMaker/StEStructEvent.h"
67 #include "StEStructPool/EventMaker/StEStructTrack.h"
68 #include "StMessMgr.h"
81 StEStructMCReader::StEStructMCReader(
int nevents, TTree *tree,
StEStructEventCuts *ecuts,
StEStructTrackCuts *tcuts) : meventsToDo(nevents), meventCount(0), mloopIndex(0), mAmDone(false), mNentries(0), mIPMAX(1000000) {
85 StEStructMCReader::StEStructMCReader(
int nevents,
const char *fileListFile,
StEStructEventCuts *ecuts,
StEStructTrackCuts *tcuts) : meventsToDo(nevents), meventCount(0), mloopIndex(0), mAmDone(false), mNentries(0), mIPMAX(1000000) {
86 ifstream fin(fileListFile);
88 TChain *chain =
new TChain(
"h999");
95 Int_t StEStructMCReader::LoadTree(Int_t entry)
98 if (!fChain)
return -5;
99 Int_t centry = fChain->LoadTree(entry);
100 if (centry < 0)
return centry;
101 if (fChain->IsA() != TChain::Class())
return centry;
102 TChain *chain = (TChain*)fChain;
103 if (chain->GetTreeNumber() != fCurrent) {
104 fCurrent = chain->GetTreeNumber();
110 Int_t StEStructMCReader::GetEntry(Int_t entry)
113 if (!fChain)
return 0;
114 return fChain->GetEntry(entry);
117 void StEStructMCReader::Init(TTree *tree)
120 if (tree == 0)
return;
124 fChain->SetMakeClass(1);
126 fChain->SetBranchAddress(
"itrac",&itrac);
127 fChain->SetBranchAddress(
"istat",&istat);
128 fChain->SetBranchAddress(
"ipdg",&ipdg);
129 fChain->SetBranchAddress(
"moth1",&moth1);
130 fChain->SetBranchAddress(
"moth2",&moth2);
131 fChain->SetBranchAddress(
"idau1",&idau1);
132 fChain->SetBranchAddress(
"idau2",&idau2);
133 fChain->SetBranchAddress(
"Pxyz",Pxyz);
134 fChain->SetBranchAddress(
"ener",&ener);
135 fChain->SetBranchAddress(
"mass",&mass);
136 fChain->SetBranchAddress(
"Vxyz",Vxyz);
137 fChain->SetBranchAddress(
"Vtime",&Vtime);
142 double x = fChain->GetEntries();
143 if( x > (pow(2., 8. *
sizeof(
int) - 1.) - 1.) )
144 gMessMgr->Message(
"Number of Entries causes integer overflow.",
"E");
150 Bool_t StEStructMCReader::Notify()
154 b_itrac = fChain->GetBranch(
"itrac");
155 b_istat = fChain->GetBranch(
"istat");
156 b_ipdg = fChain->GetBranch(
"ipdg");
157 b_moth1 = fChain->GetBranch(
"moth1");
158 b_moth2 = fChain->GetBranch(
"moth2");
159 b_idau1 = fChain->GetBranch(
"idau1");
160 b_idau2 = fChain->GetBranch(
"idau2");
161 b_Pxyz = fChain->GetBranch(
"Pxyz");
162 b_ener = fChain->GetBranch(
"ener");
163 b_mass = fChain->GetBranch(
"mass");
164 b_Vxyz = fChain->GetBranch(
"Vxyz");
165 b_Vtime = fChain->GetBranch(
"Vtime");
169 void StEStructMCReader::Show(Int_t entry)
176 Int_t StEStructMCReader::Cut(Int_t entry)
184 void StEStructMCReader::Loop()
186 if (fChain == 0)
return;
188 Int_t nentries = Int_t(fChain->GetEntries());
190 Int_t nbytes = 0, nb = 0;
191 for (Int_t jentry=0; jentry<nentries;jentry++) {
192 Int_t ientry = LoadTree(jentry);
193 if (ientry < 0)
break;
194 nb = fChain->GetEntry(jentry); nbytes += nb;
198 StEStructMCReader::~StEStructMCReader()
201 delete fChain->GetCurrentFile();
204 int StEStructMCReader::getTotalEventCount() {
205 if (fChain == 0)
return 0;
207 double nentries = fChain->GetEntries();
209 Int_t nbytes = 0, nb = 0;
211 for (Int_t jentry=0; jentry<nentries;jentry++) {
212 Int_t ientry = LoadTree(jentry);
213 if (ientry < 0)
break;
214 nb = fChain->GetEntry(jentry); nbytes += nb;
215 if(itrac == -1) retVal++;
220 int StEStructMCReader::getCharge(
int pid) {
221 if(pid == -11 || pid == -13)
return 1;
222 else if(pid == 11 || pid == 13)
return -1;
223 else if(pid > 0)
return 1;
224 else if(pid < 0)
return -1;
228 bool StEStructMCReader::measureable(
int pid){
262 float* StEStructMCReader::globalDCA(
float* p,
float* v){
265 float* r=
new float[4];
266 r[0]=r[1]=r[2]=r[3]=0;
269 float a = v[0] * p[0] + v[1] * p[1] + v[2] * p[2] ;
270 a = a / sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
272 r[3] = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2] - a*a);
279 if( fChain == NULL || (meventsToDo != 0 && meventCount == meventsToDo) ||
280 mloopIndex >= mNentries ) {
288 bool useEvent = mECuts->goodCentrality(retVal->Centrality());
294 retVal->FillChargeCollections();
296 mECuts->fillHistogram(mECuts->centralityName(), retVal->Centrality(), useEvent);
301 void StEStructMCReader::fillTracks(
StEStructEvent* estructEvent) {
306 Int_t nbytes = 0, nb = 0;
308 for(; mloopIndex < mNentries && itrac != -1; mloopIndex++) {
309 Int_t ientry = LoadTree(mloopIndex);
310 if(ientry < 0)
break;
311 nb = fChain->GetEntry(mloopIndex); nbytes += nb;
312 eTrack->SetInComplete();
321 if(istat == 11 && ipdg == mIPMAX - 2) {
326 estructEvent->SetCentrality(Pxyz[0]);
328 if(istat == 11 && ipdg == mIPMAX - 3) {
334 if(istat != 1 || !measureable(ipdg) )
continue;
336 float pt = TMath::Sqrt(Pxyz[0] * Pxyz[0] + Pxyz[1] * Pxyz[1]);
337 if( pt < 0.15 )
continue;
339 float *gdca = globalDCA(Pxyz, Vxyz);
340 bool useTrack =
true;
341 useTrack = (mTCuts->goodGlobalDCA(gdca[3]) && useTrack);
343 float theta = acos(Pxyz[2] / TMath::Sqrt(Pxyz[2] * Pxyz[2] + pt * pt));
344 float eta = -log(tan(theta/2.));
345 useTrack = (mTCuts->goodEta(eta) && useTrack);
346 float phi=atan2((
double)Pxyz[1], (
double)Pxyz[0]);
347 useTrack=(mTCuts->goodPhi(phi) && useTrack);
348 if(useTrack)mnumTracks++;
350 useTrack=(mTCuts->goodPt(pt) && useTrack);
353 float yt=log(sqrt(1+_r*_r)+_r);
354 useTrack = (mTCuts->goodYt(yt) && useTrack);
356 mTCuts->fillHistograms(useTrack);
358 eTrack->SetBx(gdca[0]);
359 eTrack->SetBy(gdca[1]);
360 eTrack->SetBz(gdca[2]);
361 eTrack->SetBxGlobal(gdca[0]);
362 eTrack->SetByGlobal(gdca[1]);
363 eTrack->SetBzGlobal(gdca[2]);
366 if(!useTrack)
continue;
368 eTrack->SetPx(Pxyz[0]);
369 eTrack->SetPy(Pxyz[1]);
370 eTrack->SetPz(Pxyz[2]);
373 eTrack->SetCharge(getCharge(ipdg));
374 estructEvent->AddTrack(eTrack);