StFemtoDstPicoRun11Maker.cxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. #include "StFemtoDstPicoRun11Maker.h"
  2. ClassImp(StFemtoDstPicoRun11Maker)
  3. //
  4. // Set maximum file size to 1.9 GB (Root has a 2GB limit)
  5. //
  6. #define MAXFILESIZE 1900000000
  7. StFemtoDstPicoRun11Maker::StFemtoDstPicoRun11Maker(StPicoDstMaker *picoMaker,
  8. const Char_t *oFileName)
  9. {
  10. std::cout << "StFemtoDstPicoRun11Maker::StFemtoDstPicoRun11Maker - Creating an instance...";
  11. mOutFileName = oFileName;
  12. //
  13. // PicoDstMaker initialization
  14. //
  15. if(!picoMaker)
  16. LOG_ERROR << "StFemtoDstPicoRun11Maker::Constructor[ERROR] - Cannot find StPicoMaker"
  17. << std::endl;
  18. mPicoMaker = picoMaker;
  19. mCompression = 9;
  20. mNEventsIn = 0;
  21. mNEventsPassed = 0;
  22. matrix = new TMatrixTSym<double>(2);
  23. mPtCut = 0.1;
  24. //
  25. // Default cut values
  26. //
  27. // initialize event cut variables
  28. mPrimVtxZ[0] = -70.;
  29. mPrimVtxZ[1] = 70.;
  30. mPrimVtxR[0] = -1.;
  31. mPrimVtxR[1] = 10.;
  32. mPrimVtxVpdVzDiff[0] = -10.;
  33. mPrimVtxVpdVzDiff[1]= 10.;
  34. mPrimVtxXShift = 0.;
  35. mPrimVtxYShift = 0.;
  36. // initialize single-particle cut variables
  37. mTrackMomentum[0] = 0.1;
  38. mTrackMomentum[1] = 2.;
  39. mTrackDcaGlobal[0] = 0.;
  40. mTrackDcaGlobal[1] = 5.;
  41. mTrackNHitsFit[0] = 15;
  42. mTrackNHitsFit[1] = 50;
  43. mTrackEta[0] = -1.1;
  44. mTrackEta[1] = 1.1;
  45. // flags and cuts for exclusion
  46. mRemovePions = false;
  47. mRemoveKaons = false;
  48. mRemoveProtons = false;
  49. mPthresh = 0.4;
  50. mTpcPionNSigma[0] = -1.5;
  51. mTpcPionNSigma[1] = 1.5;
  52. mTofPionMassSqr[0] = -0.1;
  53. mTofPionMassSqr[1] = 0.15;
  54. mTpcKaonNSigma[0] = -1.5;
  55. mTpcKaonNSigma[1] = 1.5;
  56. mTofKaonMassSqr[0] = 0.2;
  57. mTofKaonMassSqr[1] = 0.35;
  58. mTpcProtonNSigma[0] = -1.5;
  59. mTpcProtonNSigma[1] = 1.5;
  60. mTofProtonMassSqr[0] = 0.7;
  61. mTofProtonMassSqr[1] = 1.1;
  62. mRandom = new TRandom3(0);
  63. std::cout << "\t[DONE]" << std::endl;
  64. }
  65. StFemtoDstPicoRun11Maker::~StFemtoDstPicoRun11Maker()
  66. {
  67. delete matrix;
  68. }
  69. int StFemtoDstPicoRun11Maker::Init()
  70. {
  71. std::cout << "StFemtoDstPicoRun11Maker::Init - Initializing the maker"
  72. << std::endl
  73. << "Creating output file: " << mOutFileName;
  74. mFemtoEvent = new StFemtoEvent();
  75. mOutFile = new TFile(mOutFileName, "RECREATE");
  76. mOutFile->SetCompressionLevel(mCompression);
  77. std::cout << "\t[DONE]" << std::endl;
  78. mTree = new TTree("StFemtoDst","StFemtoDst");
  79. mTree->SetMaxTreeSize(MAXFILESIZE);
  80. mTree->Branch("StFemtoEvent","StFemtoEvent", &mFemtoEvent);
  81. mNBytes = 0;
  82. std::cout << "StFemtoDstPicoRun11Maker::Init - Initialization has been finished"
  83. << std::endl;
  84. return StMaker::Init();
  85. }
  86. void StFemtoDstPicoRun11Maker::Clear(Option_t *option)
  87. {
  88. StMaker::Clear();
  89. }
  90. int StFemtoDstPicoRun11Maker::Make()
  91. {
  92. int refMult;
  93. unsigned int nTracks, nPrimTracks = 0;
  94. float vpdVz, ranking;
  95. unsigned int refMult2 = 0;
  96. unsigned int refMult2Pos = 0;
  97. StFemtoTrack *mFTrack;
  98. mNEventsIn++;
  99. //
  100. // Obtaining StPicoDst
  101. //
  102. StPicoDst *picoDst = mPicoMaker->picoDst();
  103. if (!picoDst)
  104. {
  105. std::cout << "can't obtain StPicoDst" << std::endl;
  106. return kStWarn;
  107. }
  108. //
  109. // Obtaining PicoEvent
  110. //
  111. StPicoEvent *picoEvent = picoDst->event();
  112. if (!picoEvent)
  113. {
  114. std::cout << "can't obtain StPicoEvent" << std::endl;
  115. return kStWarn;
  116. }
  117. //
  118. // Check trigger
  119. //
  120. unsigned int trig = (unsigned int)picoEvent->triggerWord();
  121. /* For now it's not needed
  122. if (trig & (!mTrigWord)) return kStOk;
  123. */
  124. refMult = picoEvent->refMult();
  125. if (refMult < 0) // multiplicity cannot be negative
  126. return kStOk;
  127. nTracks = picoDst->numberOfTracks();
  128. ranking = picoEvent->ranking();
  129. if(ranking <= 0) // positive ranking only
  130. return kStOk;
  131. //
  132. // Check that position of the primary vertex if not (0,0,0)
  133. //
  134. const StThreeVectorF &primVtxPos = picoEvent->primaryVertex();
  135. vpdVz = picoEvent->vzVpd();
  136. if (primVtxPos.x() == 0 &&
  137. primVtxPos.y() == 0 &&
  138. primVtxPos.z() == 0) return kStOk;
  139. if (!AcceptPrimVtx(primVtxPos, vpdVz)) return kStOk;
  140. mNEventsPassed++;
  141. mFemtoEvent->SetEventId(picoEvent->eventId());
  142. mFemtoEvent->SetRunId(picoEvent->runId());
  143. mFemtoEvent->SetCollisionType(false); // false means p+p
  144. mFemtoEvent->SetRefMult(refMult);
  145. mFemtoEvent->SetRefMultCorr((double)refMult);
  146. mFemtoEvent->SetRefMultCorrWeight(-999.);
  147. mFemtoEvent->SetRefMultPos(picoEvent->refMultPos());
  148. mFemtoEvent->SetCent16(-1);
  149. mFemtoEvent->SetNumberOfBTofHit(picoEvent->btofTrayMultiplicity());
  150. mFemtoEvent->SetNumberOfPrimaryTracks(nPrimTracks);
  151. mFemtoEvent->SetNumberOfGlobalTracks(picoEvent->numberOfGlobalTracks());
  152. mFemtoEvent->SetMagneticField(picoEvent->bField());
  153. mFemtoEvent->SetPrimaryVertexPosition(primVtxPos.x(),
  154. primVtxPos.y(),
  155. primVtxPos.z());
  156. mFemtoEvent->SetVpdVz(vpdVz);
  157. mFemtoEvent->SetTriggerId(trig);
  158. mFemtoEvent->SetPrimaryVertexRanking(ranking);
  159. //
  160. // Calculate sphericity
  161. //
  162. float sph = -999.;
  163. float pt_full = 0.0;
  164. matrix->Zero();
  165. for (unsigned int i = 0; i < nTracks; i++)
  166. {
  167. mPicoTrack = picoDst->track(i);
  168. const StThreeVectorF &p = mPicoTrack->pMom();
  169. float pt = p.perp();
  170. if (fabs(p.pseudoRapidity()) < 1.0 && pt > mPtCut)
  171. {
  172. float px = p.x();
  173. float py = p.y();
  174. (*matrix)(0, 0) += px*px/pt;
  175. (*matrix)(1, 1) += py*py/pt;
  176. (*matrix)(0, 1) += px*py/pt;
  177. (*matrix)(1, 0) += px*py/pt;
  178. pt_full += pt;
  179. }
  180. }
  181. *matrix *= 1./pt_full;
  182. TMatrixDSymEigen death_machine(*matrix);
  183. TVectorD eigen = death_machine.GetEigenValues();
  184. sph = 2.*eigen.Min()/(eigen[0] + eigen[1]);
  185. mFemtoEvent->SetSphericity(sph);
  186. //
  187. // Loop over primary tracks
  188. //
  189. for (unsigned int iTrk = 0; iTrk < nTracks; iTrk++)
  190. {
  191. mPicoTrack = picoDst->track(iTrk);
  192. mPrimP = mPicoTrack->pMom();
  193. mGlobP = mPicoTrack->gMom();
  194. short charge = mPicoTrack->charge();
  195. float beta = mPicoTrack->btofBeta();
  196. if (AcceptRefMult2())
  197. {
  198. refMult2++;
  199. if(charge > 0) refMult2Pos++;
  200. }
  201. if(!AcceptTrack()) continue;
  202. //
  203. // Calculate mass square
  204. //
  205. mIsTofTrack = beta >= 1e-10;
  206. if(mIsTofTrack)
  207. {
  208. mMassSqr = mPrimP.mag2()*(1./(beta*beta) - 1.);
  209. //
  210. // Next lines are cheat. But we should remove garbage
  211. //
  212. if(mMassSqr < -0.02) continue;
  213. if(mPrimP.mag() > 0.5) // in this range TOF efficienty ~>98%
  214. {
  215. if(mMassSqr > 0.06 && mMassSqr < 0.18) continue;
  216. if(mMassSqr > 0.35 && mMassSqr < 0.8) continue;
  217. if(mMassSqr > 1.) continue;
  218. }
  219. }
  220. else
  221. {
  222. beta = -999.;
  223. mMassSqr = -999.;
  224. }
  225. //
  226. // Remove unwanted particles
  227. //
  228. if(mRemovePions)
  229. if (IsTpcPion() || IsTofPion()) continue;
  230. if(mRemoveKaons)
  231. if (IsTpcKaon() || IsTofKaon()) continue;
  232. if(mRemoveProtons)
  233. if (IsTpcProton() || IsTofProton()) continue;
  234. //
  235. // Add new femto track and fill it with data
  236. //
  237. mFTrack = mFemtoEvent->AddFemtoTrack();
  238. mFTrack->SetId(mPicoTrack->id());
  239. mFTrack->SetNHits((Char_t)(charge*mPicoTrack->nHitsFit()));
  240. mFTrack->SetNHitsPoss(mPicoTrack->nHitsMax());
  241. mFTrack->SetNSigmaElectron(mPicoTrack->nSigmaElectron());
  242. mFTrack->SetNSigmaPion(mPicoTrack->nSigmaPion());
  243. mFTrack->SetNSigmaKaon(mPicoTrack->nSigmaKaon());
  244. mFTrack->SetNSigmaProton(mPicoTrack->nSigmaProton());
  245. mFTrack->SetDedx(mPicoTrack->dEdx()*1e-6);
  246. //
  247. // Calculate topology map
  248. //
  249. TopologyMapCalc();
  250. mFTrack->SetMap0(mTmap0);
  251. mFTrack->SetMap1(mTmap1);
  252. mFTrack->SetP(mPrimP.x(), mPrimP.y(), mPrimP.z());
  253. //
  254. // Calculate DCA
  255. //
  256. StPhysicalHelixD globHelix(mGlobP,
  257. mPicoTrack->origin(),
  258. picoEvent->bField()*kilogauss,
  259. charge);
  260. CalcDca(globHelix, primVtxPos);
  261. mFTrack->SetDCAxGlobal(mDca.x());
  262. mFTrack->SetDCAyGlobal(mDca.y());
  263. mFTrack->SetDCAzGlobal(mDca.z());
  264. mFTrack->SetGlobalP(mGlobP.x(), mGlobP.y(), mGlobP.z());
  265. mFTrack->SetBeta(beta);
  266. }
  267. mFemtoEvent->SetRefMult2(refMult2);
  268. mFemtoEvent->SetRefMult2Pos(refMult2Pos);
  269. mNBytes += mTree->Fill();
  270. mFemtoEvent->Clear();
  271. return kStOk;
  272. }
  273. bool StFemtoDstPicoRun11Maker::AcceptPrimVtx(const StThreeVectorF &vtxPos,
  274. float vpdVz)
  275. {
  276. float vtxR = vtxPos.perp();
  277. float vpdDiff = vtxPos.z() - vpdVz;
  278. return vtxPos.z() >= mPrimVtxZ[0] &&
  279. vtxPos.z() <= mPrimVtxZ[1] &&
  280. vtxR >= mPrimVtxR[0] &&
  281. vtxR <= mPrimVtxR[1] &&
  282. vpdDiff >= mPrimVtxVpdVzDiff[0] &&
  283. vpdDiff <= mPrimVtxVpdVzDiff[1];
  284. }
  285. bool StFemtoDstPicoRun11Maker::AcceptTrack()
  286. {
  287. return mPrimP.mag() >= mTrackMomentum[0] && mPrimP.mag() <= mTrackMomentum[1] &&
  288. mPrimP.pseudoRapidity() >= mTrackEta[0] && mPrimP.pseudoRapidity() <= mTrackEta[1] &&
  289. mPicoTrack->nHitsFit() >= mTrackNHitsFit[0] && mPicoTrack->nHitsFit() <= mTrackNHitsFit[1] &&
  290. mPicoTrack->dca() >= mTrackDcaGlobal[0] && mPicoTrack->dca() <= mTrackDcaGlobal[1];
  291. }
  292. bool StFemtoDstPicoRun11Maker::AcceptRefMult2()
  293. {
  294. return mPicoTrack->charge() != 0 &&
  295. mPicoTrack->nHitsFit() >= 10 &&
  296. mPicoTrack->dca() < 3.0 &&
  297. mPrimP.mag() >= 1e-10 &&
  298. TMath::Abs(mPrimP.pseudoRapidity()) <= 1.0;
  299. }
  300. int StFemtoDstPicoRun11Maker::Finish()
  301. {
  302. mOutFile->cd();
  303. mOutFile->Write();
  304. //mTree->Write();
  305. mOutFile->Close();
  306. std::cout << "*************************************" << std::endl
  307. << "StFemtoDstPicoRun11Maker has been finished" << std::endl
  308. << "\t nEventsPassed : " << mNEventsPassed << std::endl
  309. << "\t nEventsProcessed: " << mNEventsIn << std::endl
  310. << "*************************************" << std::endl;
  311. return kStOk;
  312. }
  313. void StFemtoDstPicoRun11Maker::TopologyMapCalc()
  314. {
  315. if (mPrimP.mag() < 0.15) // tracks only in the inner sector. R = 1 m
  316. {
  317. mTmap0 = 0;
  318. mTmap1 = 0;
  319. for (int iBit = 0; iBit < 32; iBit++)
  320. {
  321. if (mRandom->Rndm() < 0.95) mTmap0 |= 1 << iBit;
  322. else mTmap0 |= 0 << iBit;
  323. }
  324. mTmap0 |= 1 << 0; // default set to the first bit: primary-vertex-used
  325. }
  326. else
  327. {
  328. if (mPrimP.mag() < 0.3) // tracks may come to the end of the outer sector: R = 2 m
  329. {
  330. mTmap0 = 0;
  331. mTmap1 = 0;
  332. for (int iBit=0; iBit<32; iBit++)
  333. {
  334. if (mRandom->Rndm() < 0.95) mTmap0 |= 1 << iBit;
  335. else mTmap0 |= 0 << iBit;
  336. if (iBit < 27)
  337. {
  338. if (mRandom->Rndm() < 0.85) mTmap1 |= 1 << iBit;
  339. else mTmap1 |= 0 << iBit;
  340. }
  341. }
  342. mTmap0 |= 1 << 0; // default set to the first bit: primary-vertex-used
  343. }
  344. else
  345. {
  346. mTmap0 = 0;
  347. mTmap1 = 0;
  348. for (int iBit=0; iBit<32; iBit++)
  349. {
  350. if (mRandom->Rndm() < 0.95) mTmap0 |= 1 << iBit;
  351. else mTmap0 |= 0 << iBit;
  352. if (iBit < 27)
  353. {
  354. if (mRandom->Rndm() < 0.95) mTmap1 |= 1 << iBit;
  355. else mTmap1 |= 0 << iBit;
  356. }
  357. }
  358. mTmap0 |= 1 << 0; // default set to the first bit: primary-vertex-used
  359. }
  360. }
  361. }
  362. bool StFemtoDstPicoRun11Maker::IsTpcPion()
  363. {
  364. return mPrimP.mag() <= mPthresh &&
  365. mPicoTrack->nSigmaPion() >= mTpcPionNSigma[0] &&
  366. mPicoTrack->nSigmaPion() <= mTpcPionNSigma[1];
  367. }
  368. bool StFemtoDstPicoRun11Maker::IsTpcKaon()
  369. {
  370. return mPrimP.mag() <= mPthresh &&
  371. mPicoTrack->nSigmaKaon() >= mTpcKaonNSigma[0] &&
  372. mPicoTrack->nSigmaKaon() <= mTpcKaonNSigma[1];
  373. }
  374. bool StFemtoDstPicoRun11Maker::IsTpcProton()
  375. {
  376. return mPrimP.mag() <= mPthresh &&
  377. mPicoTrack->nSigmaProton() >= mTpcProtonNSigma[0] &&
  378. mPicoTrack->nSigmaProton() <= mTpcProtonNSigma[1];
  379. }
  380. bool StFemtoDstPicoRun11Maker::IsTofPion()
  381. {
  382. return mIsTofTrack && mPrimP.mag() > mPthresh &&
  383. mMassSqr >= mTofPionMassSqr[0] &&
  384. mMassSqr <= mTofPionMassSqr[1];
  385. }
  386. bool StFemtoDstPicoRun11Maker::IsTofKaon()
  387. {
  388. return mIsTofTrack && mPrimP.mag() > mPthresh &&
  389. mMassSqr >= mTofKaonMassSqr[0] &&
  390. mMassSqr <= mTofKaonMassSqr[1];
  391. }
  392. bool StFemtoDstPicoRun11Maker::IsTofProton()
  393. {
  394. return mIsTofTrack && mPrimP.mag() > mPthresh &&
  395. mMassSqr >= mTofProtonMassSqr[0] &&
  396. mMassSqr <= mTofProtonMassSqr[1];
  397. }
  398. void StFemtoDstPicoRun11Maker::CalcDca(const StPhysicalHelixD &helix,
  399. const StThreeVectorF &vtxPos)
  400. {
  401. double pathLen = helix.pathLength(vtxPos, false);
  402. mDca = helix.at(pathLen) - vtxPos;
  403. }