StO97FemtoDstMaker.cxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #include "StO97FemtoDstMaker.h"
  2. #include "TBranch.h"
  3. ClassImp(StO97FemtoDstMaker)
  4. //
  5. // Magnetic field -- values obtainted from StFemtoDstPythia6Maker
  6. //
  7. const Float_t BFIELD = 4.510600000;
  8. const Float_t RBFIELD = -4.510600000;
  9. //
  10. // Set maximum file size to 1.9 GB (Root has a 2GB limit)
  11. //
  12. #define MAXFILESIZE 1900000000
  13. //_________________
  14. StO97FemtoDstMaker::StO97FemtoDstMaker(const Char_t *iFileName,
  15. const Char_t *oFileName)
  16. {
  17. std::cout << "[StO97FemtoDstMaker] Creating an instance... ";
  18. mOutFileName = oFileName;
  19. mInFileName = iFileName;
  20. mTree = 0;
  21. mOutFile = 0;
  22. mInFile = 0;
  23. mCompression = 9;
  24. mNEvents = 0;
  25. mStop = false;
  26. mDb = TDatabasePDG::Instance();
  27. mRandy = new TRandom3(0);
  28. //
  29. // RefMult counters
  30. //
  31. mRefMult = 0;
  32. mRefMult2 = 0;
  33. mRefMultPos = 0;
  34. mRefMult2Pos = 0;
  35. //
  36. // Setup sphericity matrix
  37. //
  38. mMatrix = new TMatrixTSym<double>(2);
  39. mPtCut = 0.1;
  40. //
  41. // Setup default cut's
  42. //
  43. mTrackMomentum[0] = 0.05;
  44. mTrackMomentum[1] = 2.1;
  45. mTrackDca[0] = 0.;
  46. mTrackDca[1] = 3.;
  47. mTrackEta[0] = -1.1;
  48. mTrackEta[1] = 1.1;
  49. std::cout << "[OK]" << std::endl;
  50. }
  51. StO97FemtoDstMaker::~StO97FemtoDstMaker()
  52. {
  53. delete mMatrix;
  54. }
  55. Int_t StO97FemtoDstMaker::Init()
  56. {
  57. std::cout << "[StO97FemtoDstMaker] ---=== Initializing maker ===---" << std::endl;
  58. mEvent = new StFemtoEvent();
  59. //
  60. // Input file
  61. //
  62. std::cout << "[StO97FemtoDstMaker] Openning an input file... ";
  63. if (mInFile)
  64. fclose(mInFile);
  65. mInFile = fopen(mInFileName, "r");
  66. if (mInFile)
  67. std::cout << "[OK]" << std::endl;
  68. else
  69. {
  70. std::cout << "[FAIL]" << std::endl;
  71. return kStFatal;
  72. }
  73. //
  74. // Output file
  75. //
  76. std::cout << "[StO97FemtoDstMaker] Creating output file... ";
  77. if (mOutFile)
  78. {
  79. mOutFile->Close();
  80. mOutFile->Open(mOutFileName, "RECREATE");
  81. }
  82. else
  83. mOutFile = new TFile(mOutFileName, "RECREATE");
  84. if (mOutFile)
  85. std::cout << "[OK]" << std::endl;
  86. else
  87. {
  88. std::cout << "[FAIL]" << std::endl;
  89. return kStFatal;
  90. }
  91. SetCompressionlevel(mCompression); // default value from constructor
  92. //
  93. // TTree setup
  94. //
  95. std::cout << "[StO97FemtoDstMaker] Creating TTree... ";
  96. if (mTree)
  97. delete mTree;
  98. mTree = new TTree("StFemtoDst", "StFemtoDst");
  99. if (!mTree) {
  100. std::cout << "[FAIL]" << std::endl;
  101. return kStFatal;
  102. }
  103. mTree->SetMaxTreeSize(MAXFILESIZE);
  104. mTree->Branch("StFemtoEvent", "StFemtoEvent", &mEvent);
  105. mNBytes = 0;
  106. std::cout << "[OK]" << std::endl;
  107. //
  108. // Finalization of initialization :)
  109. //
  110. std::cout << "[StO97FemtoDstMaker] ---=== Initialization complite ===---" << std::endl;
  111. return StMaker::Init();
  112. }
  113. void StO97FemtoDstMaker::SetCompressionlevel(Int_t comp)
  114. {
  115. mCompression = comp;
  116. std::cout << "[StO97FemtoDstMaker] Compression level = " << mCompression << std::endl;
  117. mOutFile->SetCompressionLevel(mCompression);
  118. }
  119. Int_t StO97FemtoDstMaker::Make()
  120. {
  121. //
  122. // Read event
  123. //
  124. mNEvents++;
  125. mStop = ReadEvent();
  126. if (mStop)
  127. return kStOk;
  128. //
  129. // Read tracks
  130. //
  131. mStop = ReadTracks();
  132. if (!mStop)
  133. mNBytes += mTree->Fill();
  134. return kStOk;
  135. }
  136. Int_t StO97FemtoDstMaker::Finish()
  137. {
  138. std::cout << "[StO97FemtoDstMaker] ---=== Finalization of maker ===---"
  139. << "[StO97FemtoDstMaker] total number of events = "
  140. << mNEvents << std::endl
  141. << "[StO97FemtoDstMaker] total bytes = "
  142. << mNBytes
  143. << std::endl;
  144. if (mInFile)
  145. {
  146. fclose(mInFile);
  147. mInFile = 0;
  148. }
  149. if (mTree)
  150. {
  151. if (mOutFile)
  152. mOutFile->Write();
  153. delete mTree;
  154. mTree = 0;
  155. }
  156. if (mOutFile)
  157. {
  158. mOutFile->Close();
  159. delete mOutFile;
  160. mOutFile = 0;
  161. }
  162. return kStOk;
  163. }
  164. Bool_t StO97FemtoDstMaker::ReadEvent()
  165. {
  166. Int_t eventNumber;
  167. Float_t impPar;
  168. Float_t rot;
  169. Char_t buf[128];
  170. while (1)
  171. {
  172. Int_t ret = fscanf(mInFile, " %i %i %f %f",
  173. &eventNumber, &mNTracks, &impPar, &rot);
  174. if (ret <= 0) // if can't read a line
  175. fgets(buf, 127, mInFile); // skip it
  176. else if (ret == 4)
  177. { // 4 - total number of event parameters
  178. mEvent->Clear();
  179. mEvent->SetEventId(eventNumber);
  180. mEvent->SetRunId(0xDEADBEEF);
  181. mEvent->SetCollisionType(false);
  182. mEvent->SetCent16(0);
  183. mEvent->SetMagneticField(BFIELD);
  184. mEvent->SetPrimaryVertexPosition(impPar, rot, 0.); // why not?
  185. mEvent->SetVpdVz(0.);
  186. mEvent->SetTriggerId(0);
  187. mEvent->SetPrimaryVertexRanking(1e4);
  188. return false;
  189. }
  190. if (feof(mInFile)) // if EOF then return stop flag
  191. return true;
  192. }
  193. }
  194. Bool_t StO97FemtoDstMaker::ReadTracks()
  195. {
  196. Int_t id;
  197. Int_t pdgId;
  198. Float_t px, py, pz;
  199. Float_t energy, mass;
  200. Float_t xFr, yFr, zFr, tFr;
  201. mSphericity = 0;
  202. float pt_full = 0;
  203. mRefMult2Pos = 0;
  204. mRefMultPos = 0;
  205. mRefMult2 = 0;
  206. mRefMult = 0;
  207. int goodTracks = 0;
  208. mMatrix->Zero();
  209. for (Int_t iTrack = 0; iTrack < mNTracks; iTrack++)
  210. {
  211. Int_t ret = fscanf(mInFile, " %i %i %f %f %f %f %f %f %f %f %f",
  212. &id, &pdgId, &px, &py, &pz,
  213. &energy, &mass, &xFr, &yFr, &zFr, &tFr);
  214. if (ret != 11)
  215. return true;
  216. else
  217. {
  218. TParticlePDG *partPdg = mDb->GetParticle(pdgId);
  219. if (partPdg == 0x0) continue;
  220. int charge = TDatabasePDG::Instance()->GetParticle(pdgId)->Charge();
  221. float ptot = sqrt(px*px + py*py + pz*pz);
  222. float pt = sqrt(px*px + py*py);
  223. float eta = ptot > 0. && pz > 0. ? 0.5*log((ptot + pz)/(ptot - pz)) : -999.;
  224. float dca = sqrt(xFr*xFr + yFr*yFr)*1.e-13; // DCA of track to 0 in [cm]
  225. float beta = ptot/energy;
  226. if (charge == 0) continue;
  227. charge /= abs(charge);
  228. if (fabs(eta) < 1.0 && dca < 3.0)
  229. {
  230. mRefMult2++;
  231. if (charge > 0) mRefMult2Pos++;
  232. if (fabs(eta) < 0.5)
  233. {
  234. mRefMult++;
  235. if (charge > 0) mRefMultPos++;
  236. }
  237. }
  238. //
  239. // Calculate sphericity
  240. //
  241. if (pt > mPtCut)
  242. {
  243. if (fabs(eta) < 1.0)
  244. {
  245. (*mMatrix)(0, 0) += px*px/pt;
  246. (*mMatrix)(1, 1) += py*py/pt;
  247. (*mMatrix)(0, 1) += px*py/pt;
  248. (*mMatrix)(1, 0) += py*px/pt;
  249. pt_full += pt;
  250. }
  251. }
  252. float nSigmaElectron = -999.;
  253. float nSigmaPion = -999.;
  254. float nSigmaKaon = -999.;
  255. float nSigmaProton = -999.;
  256. switch (abs(pdgId))
  257. {
  258. case 211:
  259. nSigmaPion = 0.0;
  260. break;
  261. case 321:
  262. nSigmaKaon = 0.0;
  263. break;
  264. case 2212:
  265. nSigmaProton = 0.0;
  266. break;
  267. default:
  268. continue;
  269. }
  270. if (ptot > mTrackMomentum[0] && ptot < mTrackMomentum[1] &&
  271. eta > mTrackEta[0] && eta < mTrackEta[1] &&
  272. charge != 0 &&
  273. dca > mTrackDca[0] && dca < mTrackDca[1])
  274. {
  275. unsigned int tmap0 = 0; // This is
  276. unsigned int tmap1 = 0; // topology map
  277. float dedx = dedxMean(mass, ptot);
  278. TopologyMap(&tmap0, &tmap1, ptot);
  279. StFemtoTrack *track = mEvent->AddFemtoTrack();
  280. track->SetId(iTrack);
  281. track->SetNHits(45*charge);
  282. track->SetNHitsPoss(45);
  283. track->SetNSigmaElectron(nSigmaElectron);
  284. track->SetNSigmaPion(nSigmaPion);
  285. track->SetNSigmaKaon(nSigmaKaon);
  286. track->SetNSigmaProton(nSigmaProton);
  287. track->SetDedx(dedx);
  288. track->SetMap0(tmap0);
  289. track->SetMap1(tmap1);
  290. track->SetP(px, py, pz);
  291. track->SetDCAGlobal(xFr*1.e-13, yFr*1.e-13, zFr*1.e-13);
  292. track->SetGlobalP(px, py, pz);
  293. track->SetBeta(beta);
  294. goodTracks++;
  295. }
  296. }
  297. }
  298. //
  299. // Calculate eigenvalues
  300. //
  301. *mMatrix *= 1./pt_full;
  302. TMatrixDSymEigen death_machine(*mMatrix);
  303. TVectorD eigen = death_machine.GetEigenValues();
  304. float mSphericity = 2.*eigen.Min()/(eigen[0] + eigen[1]);
  305. mEvent->SetSphericity(mSphericity);
  306. mEvent->SetRefMult(mRefMult);
  307. mEvent->SetRefMultCorr(mRefMult);
  308. mEvent->SetRefMultCorrWeight(1.0);
  309. mEvent->SetRefMultPos(mRefMultPos);
  310. mEvent->SetNumberOfBTofHit(mRefMult);
  311. mEvent->SetNumberOfPrimaryTracks(goodTracks);
  312. mEvent->SetNumberOfGlobalTracks(goodTracks);
  313. mEvent->SetRefMult2(mRefMult2);
  314. mEvent->SetRefMult2Pos(mRefMult2Pos);
  315. return false;
  316. }
  317. Double_t StO97FemtoDstMaker::dedxMean(Double_t mass, Double_t momentum)
  318. {
  319. Double_t dedxMean;
  320. Double_t tpcDedxGain = 0.174325e-06;
  321. Double_t tpcDedxOffset = -2.71889;
  322. Double_t tpcDedxRise = 776.626;
  323. Double_t gamma = TMath::Sqrt(momentum*momentum/(mass*mass)+1.);
  324. Double_t beta = TMath::Sqrt(1. - 1./(gamma*gamma));
  325. Double_t rise = tpcDedxRise* beta*beta*gamma*gamma;
  326. if ( beta > 0)
  327. dedxMean = tpcDedxGain/(beta*beta) * (0.5*TMath::Log(rise) - beta*beta
  328. - tpcDedxOffset);
  329. else
  330. dedxMean = 1000.;
  331. return dedxMean;
  332. }
  333. void StO97FemtoDstMaker::TopologyMap(unsigned int *tmap1, unsigned int *tmap2, float ptot)
  334. {
  335. if (ptot < 0.15) // tracks only in the inner sector. R=1m
  336. {
  337. *tmap1 = 0;
  338. *tmap2 = 0;
  339. for (int iBit = 0; iBit < 32; iBit++)
  340. {
  341. if (mRandy->Rndm() < 0.95)
  342. *tmap1 |= 1 << iBit;
  343. else
  344. *tmap1 |= 0 << iBit;
  345. }
  346. *tmap1 |= 1 << 0; // default set to the first bit: primary-vertex-used
  347. }
  348. else
  349. {
  350. if (ptot < 0.3) // tracks may come to the end of the outer sector: R = 2m
  351. {
  352. *tmap1 = 0;
  353. *tmap2 = 0;
  354. for (int iBit = 0; iBit < 32; iBit++)
  355. {
  356. if (mRandy->Rndm() < 0.95)
  357. *tmap1 |= 1 << iBit;
  358. else
  359. *tmap1 |= 0 << iBit;
  360. if (iBit < 27)
  361. {
  362. if (mRandy->Rndm() < 0.85)
  363. *tmap2 |= 1 << iBit;
  364. else
  365. *tmap2 |= 0 << iBit;
  366. }
  367. }
  368. *tmap1 |= 1 << 0; // default set to the first bit: primary-vertex-used
  369. }
  370. else
  371. {
  372. *tmap1 = 0;
  373. *tmap2 = 0;
  374. for (int iBit = 0; iBit < 32; iBit++)
  375. {
  376. if (mRandy->Rndm() < 0.95)
  377. *tmap1 |= 1 << iBit;
  378. else
  379. *tmap1 |= 0 << iBit;
  380. if(iBit < 27)
  381. {
  382. if(mRandy->Rndm() < 0.95)
  383. *tmap2 |= 1 << iBit;
  384. else
  385. *tmap2 |= 0 << iBit;
  386. }
  387. }
  388. *tmap1 |= 1 << 0; // default set to the first bit: primary-vertex-used
  389. }
  390. }
  391. }