StHbtFlowPicoReader.cxx 11 KB

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