StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHbtFlowPicoReader.cxx
1 #include "StHbtFlowPicoReader.h"
2 #include "StThreeVectorD.hh"
3 #include "StHbtMaker/Infrastructure/StHbtEvent.hh"
4 #include "math_constants.h"
5 #include "SystemOfUnits.h"
6 #include <fstream>
7 
8 ClassImp(StHbtFlowPicoReader)
9 
10  const double ETAMIN = -5.; /* cutoff values to avoid nan arithmetics */
11  const double ETAMAX = 5.;
13 StHbtFlowPicoReader::StHbtFlowPicoReader(string list_inp,int nevents)
14 {
15  /*
16 Because pairs analysis is so much slower than DWT, I have to make finer
17 parallelization splitting (more jobs). For this reason, I have two different
18 set of "to do list" files: one for the DWT analysis and the other for pairs.
19 It makes therefore no sense to assume that to_do_list.inp files (for DWT)
20 will be recycled by the pairs analysis, and consequently to maintain the
21 uniformity of the input format. Here I follow the StHbtMuDstReader format
22 (.lis).
23  */
24  cout << "StHbtFlowPicoReader::StHbtFlowPicoReader Initializing the reader ! \n";
25  to_do_list_inp = list_inp;
26  mReaderStatus = 0; // means "good"
27  Nbytes = 0;
28  crrnt_entry = 0;
29  crrnt_eventI = 0;
30  NEvt_in_chain = 0;
31  NEVENTS = nevents;
32  // read the list of input data files (DST ntuples)
33 
34 
35  std::ifstream input(to_do_list_inp.c_str());
36 
37  while (input.good())
38  {
39  string filename;
40  input >> filename;
41 
42  if (filename!="" )
43  {
44  L_runs.push_back(filename);
45  }
46  }
47 
48  input.close();
49 cout << " chain has "<<L_runs.size()<<" runs \n";
50 
51  Init();
52 }
54 int StHbtFlowPicoReader::Init()
55 {
56  cout << " StHbtFlowPicoReader::Init\n"; // open DST
57 
58  // build the chain
59 DST_Chain = new TChain("FlowTree");
60 
61  vector<string>::const_iterator it = L_runs.begin();
62 
63 
64  while (it!=L_runs.end())
65  {
66  if (NEvt_in_chain <NEVENTS)
67  {
68  cout << "StHbtFlowPicoReader::StHbtFlowPicoReader add " <<*it<<"\n";
69 
70  TChain* tmpChain = new TChain("FlowTree");
71 
72  int ok1 = tmpChain->Add((*it).c_str());
73  if (!ok1) {cout << "tmpChain->Add error !\n";}
74  int tmpEntries = (int)tmpChain->GetEntries();
75  NEvt_in_chain += tmpEntries;
76  cout << " in file " <<tmpEntries<<" total "<<NEvt_in_chain<< "\n";
77  delete tmpChain;
78  cout << " adding... \n";
79  int ok2 = DST_Chain->Add((*it).c_str());
80  if (!ok2) {cout << "DST_Chain->Add error !\n";}
81  }
82  ++it;
83  }
84 
85  this->pDST = new flow_pDST(DST_Chain);
86  cout << "ST_txtr::ST_txtr flow_pDST instantiated \n";
87  this->pDST->fChain->SetBranchStatus("*",0); // disable all branches
88 
89  // enable the branches we need
90  this->pDST->fChain->SetBranchStatus("mRunID",1);
91  this->pDST->fChain->SetBranchStatus("mMagneticField",1);
92  this->pDST->fChain->SetBranchStatus("mEventID",1);
93  this->pDST->fChain->SetBranchStatus("mNtrack",1);
94  this->pDST->fChain->SetBranchStatus("mVertexX",1);
95  this->pDST->fChain->SetBranchStatus("mVertexY",1);
96  this->pDST->fChain->SetBranchStatus("mVertexZ",1);
97  this->pDST->fChain->SetBranchStatus("fTracks.fUniqueID",1);
98  this->pDST->fChain->SetBranchStatus("fTracks.fBits",1);
99  this->pDST->fChain->SetBranchStatus("fTracks.mPtGlobal",1);
100  this->pDST->fChain->SetBranchStatus("fTracks.mEtaGlobal",1);
101  this->pDST->fChain->SetBranchStatus("fTracks.mPhiGlobal",1);
102  this->pDST->fChain->SetBranchStatus("fTracks.mNhits",1);
103  this->pDST->fChain->SetBranchStatus("fTracks.mCharge",1);
104  this->pDST->fChain->SetBranchStatus("fTracks.mFitPts",1);
105  this->pDST->fChain->SetBranchStatus("fTracks.mMaxPts",1);
106  this->pDST->fChain->SetBranchStatus("fTracks.mDedx",1);
107  this->pDST->fChain->SetBranchStatus("fTracks.mPidElectron",1);
108  this->pDST->fChain->SetBranchStatus("fTracks.mPidPion",1);
109  this->pDST->fChain->SetBranchStatus("fTracks.mPidKaon",1);
110  this->pDST->fChain->SetBranchStatus("fTracks.mPidProton",1);
111  this->pDST->fChain->SetBranchStatus("fTracks.mMostLikelihoodPID",1);
112  this->pDST->fChain->SetBranchStatus("fTracks.mMostLikelihoodProb",1);
113  this->pDST->fChain->SetBranchStatus("fTracks.mDcaGlobal",1);
114  this->pDST->fChain->SetBranchStatus("fTracks.mDcaGlobalX",1);
115  this->pDST->fChain->SetBranchStatus("fTracks.mDcaGlobalY",1);
116  this->pDST->fChain->SetBranchStatus("fTracks.mDcaGlobalZ",1);
117 
118  Nentries = (int)(this->pDST->fChain->GetEntries());
119 
120  if (Nentries) {return 0;}
121  else
122  {
123  cout << "StHbtFlowPicoReader::Init() -- see no entries \n";
124  return 1;
125  }
126 }
128 StHbtEvent* StHbtFlowPicoReader::ReturnHbtEvent()
129 {
130 
131  /* using StHbtMcEventReader.cxx as an example
132 http://www.star.bnl.gov/webdatanfs/dox/html/StHbtMcEventReader_8cxx-source.html
133 
134 StHbtTrack is here:
135 http://www.star.bnl.gov/webdatanfs/dox/html/StHbtTrack_8hh-source.html
136 http://www.star.bnl.gov/webdatanfs/dox/html/StHbtTrack_8cc-source.html
137 
138 StHbtEvent:
139 http://www.star.bnl.gov/webdatanfs/dox/html/StHbtEvent_8hh-source.html
140 http://www.star.bnl.gov/webdatanfs/dox/html/StHbtEvent_8cc-source.html
141  */
142 StHbtEvent* hbtEvent = new StHbtEvent();
143 
144  cout << "StHbtFlowPicoReader::ReturnHbtEvent() crrnt_entry begins "
145 <<crrnt_entry<<"\n";
146  int ientry;
147  if (crrnt_entry<Nentries)
148  {
149  ientry = this->pDST->LoadTree(crrnt_entry);
150  nb = this->pDST->fChain->GetEntry(crrnt_entry); Nbytes += nb;
151 
152  hbtEvent->SetEventNumber(crrnt_eventI);
153  hbtEvent->SetCtbMult(0);
154  hbtEvent->SetZdcAdcEast(0);
155  hbtEvent->SetZdcAdcWest(0);
156  hbtEvent->SetNumberOfTpcHits(0);
157 
158  int Mult = this->pDST->fTracks_;
159  hbtEvent->SetNumberOfTracks(Mult);
160  hbtEvent->SetNumberOfGoodTracks(Mult);
161  hbtEvent->SetReactionPlane(0.);
162  hbtEvent->SetReactionPlaneSubEventDifference(0.);
163 
164  float BTesla = pDST->mMagneticField;
165  float vX = pDST->mVertexX;
166  float vY = pDST->mVertexY;
167  float vZ = pDST->mVertexZ;
168 
169  StHbtThreeVector VertexPosition = StHbtThreeVector(vX,vY,vZ);
170 
171  hbtEvent->SetPrimVertPos(VertexPosition);
172  // loop over tracks
173 
174  int UncorrPositivePrim = 0; /* defined in StEventUtilities/StuRefMult.hh*/
175  int UncorrNegativePrim = 0;
176 
177  for (short itrack = 0; itrack<Mult; itrack++)
178  {
179  StHbtThreeVector tmpP;
180  float Phi = pDST->fTracks_mPhiGlobal[itrack];
181  float pT = pDST->fTracks_mPtGlobal[itrack];
182  float eta = pDST->fTracks_mEtaGlobal[itrack];
183  float pX = pT*cos(Phi);
184  float pY = pT*sin(Phi);
185  float expeta = exp(-eta);
186  float theta = 2*atan(expeta);
187 
188  short charge = pDST->fTracks_mCharge[itrack];
189  bool reject = false;
190  if (charge ==0) reject = true;
191  /* Sometimes eta is nan. Can we reject such tracks ? */
192  if ( !(eta>ETAMIN) || !(eta<ETAMAX)) reject = true;
193 
194 
195  if (!reject)
196  {
197  StHbtTrack* hbtTrack = new StHbtTrack();
198  hbtTrack->SetHiddenInfo(0);
199  // cout << " good eta "<<eta<<"\n";
200 
201  /* zenith angle theta has to be non-negative, between 0 and Pi;
202  atan changes between -Pi/2 and Pi/2.
203  */
204 
205  if (theta<0) {theta = C_PI+theta;}
206  float p = pT/sin(theta);
207  float pZ = p-pT*expeta; /* because expeta = tan(theta/2)
208  = (1-cos(theta))/sin(theta) = (p-pZ)/pT */
209 
210  tmpP.setX(pX);
211  tmpP.setY(pY);
212  tmpP.setZ(pZ);
213  hbtTrack->SetP(tmpP);
214 
215  hbtTrack->SetTrackId(itrack); // ? Frank knows what it is
216  // int PID=pDST->fTracks_mMostLikelihoodPID[itrack]);
217  float dEdx = pDST->fTracks_mDedx[itrack];
218 
219  float ProbElectron = pDST->fTracks_mPidElectron[itrack];
220  float ProbPion = pDST->fTracks_mPidPion[itrack];
221  float ProbKaon = pDST->fTracks_mPidKaon[itrack];
222  float ProbProton = pDST->fTracks_mPidProton[itrack];
223 
224  hbtTrack->SetdEdx(dEdx);
225 
226  hbtTrack->SetPidProbElectron(ProbElectron);
227 
228  hbtTrack->SetPidProbPion(ProbPion);
229  hbtTrack->SetPidProbKaon(ProbKaon);
230  hbtTrack->SetPidProbProton(ProbProton);
231 
232 
233  int Nhits = pDST->fTracks_mNhits[itrack];
234 
235  float DCA = pDST->fTracks_mDcaGlobal[itrack];
236  float DCAX = pDST->fTracks_mDcaGlobalX[itrack];
237  float DCAY = pDST->fTracks_mDcaGlobalY[itrack];
238  float DCAZ = pDST->fTracks_mDcaGlobalZ[itrack];
239 
240  float DCAXY = sqrt(DCAX*DCAX+DCAY*DCAY);
241 
242  hbtTrack->SetDCAxyGlobal(DCAXY);
243  hbtTrack->SetDCAzGlobal(DCAZ);
244 
245  if (Nhits>=10 && fabs(eta)<0.5 && DCA<3.)
246  {
247  if (charge>0) {UncorrPositivePrim++;}
248  if (charge<0) {UncorrNegativePrim++;}
249  }
250  hbtTrack->SetNHits(Nhits);
251  hbtTrack->SetCharge(charge);
252  hbtTrack->SetNHitsPossible(pDST->fTracks_mMaxPts[itrack]);
253  hbtTrack->SetPt(pT);
254  hbtTrack->SetPtGlobal(pT);
255 
256  int gid = pDST->fTracks_mMostLikelihoodPID[itrack];
257  float pid_prob = pDST->fTracks_mMostLikelihoodProb[itrack];
258 
259  // Assume that this can only happen in MC
260  if (pid_prob == 1.)
261  {
262  if (gid ==2 || gid ==3)
263  {
264  hbtTrack->SetNSigmaElectron(0.);
265  hbtTrack->SetNSigmaPion(-1000.);
266  hbtTrack->SetNSigmaKaon(-1000.);
267  hbtTrack->SetNSigmaProton(-1000.);
268  }
269  else if (gid==8 || gid ==9)
270  {
271  hbtTrack->SetNSigmaElectron(1000.);
272  hbtTrack->SetNSigmaPion(0.);
273  hbtTrack->SetNSigmaKaon(-1000.);
274  hbtTrack->SetNSigmaProton(-1000.);
275  }
276  else if (gid==11 || gid==12)
277  {
278  hbtTrack->SetNSigmaElectron(1000.);
279  hbtTrack->SetNSigmaPion(1000.);
280  hbtTrack->SetNSigmaKaon(0.);
281  hbtTrack->SetNSigmaProton(-1000.);
282  }
283  else if (gid==14 || gid==15)
284  {
285  hbtTrack->SetNSigmaElectron(1000.);
286  hbtTrack->SetNSigmaPion(1000.);
287  hbtTrack->SetNSigmaKaon(1000.);
288  hbtTrack->SetNSigmaProton(0.);
289  }
290  else
291  {
292  hbtTrack->SetNSigmaElectron(1000.);
293  hbtTrack->SetNSigmaPion(0.);
294  hbtTrack->SetNSigmaKaon(-1000.);
295  hbtTrack->SetNSigmaProton(-1000.);
296  }
297 
298  }
299 
300  // define helix:
301 
302  const StPhysicalHelixD& mHelix =
303  StPhysicalHelixD(tmpP,VertexPosition,BTesla*tesla,charge);
304 
305  hbtTrack->SetHelix(mHelix);
306 
307  hbtEvent->TrackCollection()->push_back(hbtTrack);
308  }
309  }
310 
311  hbtEvent->SetUncorrectedNumberOfPositivePrimaries(UncorrPositivePrim);
312  hbtEvent->SetUncorrectedNumberOfNegativePrimaries(UncorrNegativePrim);
313 
314  crrnt_entry++;
315  crrnt_eventI++;
316  cout << "StHbtFlowPicoReader return event # "<<crrnt_eventI<<"\n";
317  // hbtEvent->RandomizeTrackOrder();
318  return hbtEvent;
319  }
320  else
321  {
322  mReaderStatus = 1;
323  delete hbtEvent;
324  return 0;
325  }
326 }
328 /*
329 int StHbtFlowPicoReader::WriteHbtEvent(StHbtEvent*)
330 {
331  cout << " calling my own StHbtFlowPicoReader::WriteHbtEvent(StHbtEvent*)\n";
332  return 0;
333 }
334 */
336 
337 StHbtString StHbtFlowPicoReader::Report()
338 {
339 return (StHbtString)" Here is the reader report \n";
340 }
342 StHbtFlowPicoReader::~StHbtFlowPicoReader()
343 {
344 }
345 
346 
347 
348 
349