StQGSMdstMaker.cxx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #include "StQGSMdstMaker.h"
  2. ClassImp(StQGSMdstMaker)
  3. //
  4. // Set maximum file size to 1.9 GB (Root has a 2GB limit)
  5. //
  6. #define MAXFILESIZE 1900000000
  7. //_________________
  8. StQGSMdstMaker::StQGSMdstMaker(const Char_t *iFileName,
  9. const Char_t *oFileName)
  10. {
  11. std::cout << "[StQGSMdstMaker] Creating an instance... ";
  12. TDatime d;
  13. mOutFileName = oFileName;
  14. mInFileName = iFileName;
  15. mTree = 0;
  16. mOutFile = 0;
  17. mInEventFile = 0;
  18. mInTrackFile = 0;
  19. mCompression = 9;
  20. mNEvents = 0;
  21. mStop = false;
  22. matrix = new TMatrixTSym<double>(2); // matrix for calculation of transverse sphericity
  23. matrix2 = new TMatrixTSym<double>(2); // matrix for calculation of transverse sphericity 2
  24. std::cout << "[OK]" << std::endl;
  25. }
  26. //_________________
  27. StQGSMdstMaker::~StQGSMdstMaker()
  28. {
  29. /* nothing to do */
  30. }
  31. //_________________
  32. Int_t StQGSMdstMaker::Init()
  33. {
  34. std::cout << "[StQGSMdstMaker] ---=== Initializing maker ===---" << std::endl;
  35. mEvent = new StO97Event();
  36. //
  37. // Input file
  38. //
  39. std::cout << "[StQGSMdstMaker] Openning an input file... ";
  40. if (mInEventFile) fclose(mInEventFile);
  41. if (mInTrackFile) fclose(mInTrackFile);
  42. mInEventFile = fopen(Form("%s/B_MULT", mInFileName), "r");
  43. mInTrackFile = fopen(Form("%s/finalpr.data", mInFileName), "r");
  44. if (mInEventFile && mInTrackFile)
  45. std::cout << "[OK]" << std::endl;
  46. else
  47. {
  48. std::cout << "[FAIL]" << std::endl;
  49. return kStFatal;
  50. }
  51. //
  52. // Output file
  53. //
  54. std::cout << "[StQGSMdstMaker] Creating output file... ";
  55. if (mOutFile)
  56. {
  57. mOutFile->Close();
  58. mOutFile->Open(mOutFileName, "RECREATE");
  59. }
  60. else
  61. mOutFile = new TFile(mOutFileName, "RECREATE");
  62. if (mOutFile)
  63. std::cout << "[OK]" << std::endl;
  64. else
  65. {
  66. std::cout << "[FAIL]" << std::endl;
  67. return kStFatal;
  68. }
  69. SetCompressionlevel(mCompression); // default value from constructor
  70. //
  71. // TTree setup
  72. //
  73. std::cout << "[StQGSMdstMaker] Creating TTree... ";
  74. if (mTree)
  75. delete mTree;
  76. mTree = new TTree("StO97Dst", "StO97Dst");
  77. if (!mTree)
  78. {
  79. std::cout << "[FAIL]" << std::endl;
  80. return kStFatal;
  81. }
  82. mTree->SetMaxTreeSize(MAXFILESIZE);
  83. mTree->Branch("StO97Event", "StO97Event", &mEvent);
  84. mNBytes = 0;
  85. std::cout << "[OK]" << std::endl;
  86. //
  87. // Finalization of initialization :)
  88. //
  89. std::cout << "[StQGSMdstMaker] ---=== Initialization complite ===---" << std::endl;
  90. return StMaker::Init();
  91. }
  92. //_________________
  93. void StQGSMdstMaker::SetCompressionlevel(Int_t comp)
  94. {
  95. mCompression = comp;
  96. std::cout << "[StQGSMdstMaker] Compression level = " << mCompression << std::endl;
  97. mOutFile->SetCompressionLevel(mCompression);
  98. }
  99. //_________________
  100. Int_t StQGSMdstMaker::Make()
  101. {
  102. //
  103. // Read event
  104. //
  105. mNEvents++;
  106. mStop = !mStop;
  107. mStop = ReadEvent();
  108. if (mStop)
  109. return kStOk;
  110. //
  111. // Read tracks
  112. //
  113. mStop = ReadTracks();
  114. if (!mStop)
  115. {
  116. mEvent->SetTransverseSphericity(mSperp);
  117. mEvent->SetTransverseSphericity2(mSperp2);
  118. mNBytes += mTree->Fill();
  119. }
  120. return kStOk;
  121. }
  122. //_________________
  123. Int_t StQGSMdstMaker::Finish()
  124. {
  125. std::cout << "[StQGSMdstMaker] ---=== Finalization of maker ===---"
  126. << "[StQGSMdstMaker] total number of events = "
  127. << mNEvents << std::endl
  128. << "[StQGSMdstMaker] total bytes = "
  129. << mNBytes
  130. << std::endl;
  131. // close event file
  132. if (mInEventFile)
  133. {
  134. fclose(mInEventFile);
  135. mInEventFile = 0;
  136. }
  137. // close track file
  138. if (mInTrackFile)
  139. {
  140. fclose(mInTrackFile);
  141. mInTrackFile = 0;
  142. }
  143. // write tree to output file
  144. if (mTree)
  145. {
  146. if (mOutFile)
  147. mOutFile->Write();
  148. delete mTree;
  149. mTree = 0;
  150. }
  151. // close output file
  152. if (mOutFile)
  153. {
  154. mOutFile->Close();
  155. delete mOutFile;
  156. mOutFile = 0;
  157. }
  158. return kStOk;
  159. }
  160. //_________________
  161. Bool_t StQGSMdstMaker::ReadEvent()
  162. {
  163. Int_t eventNumber;
  164. Float_t impPar;
  165. Char_t buf[128];
  166. while (1)
  167. {
  168. Int_t ret = fscanf(mInEventFile, " %i %f %i",
  169. &eventNumber, &impPar, &mNTracks);
  170. if (ret <= 0) // if can't read a line
  171. fgets(buf, 127, mInEventFile); // skip it
  172. else
  173. {
  174. if (ret == 3) // 3 - total number of event parameters
  175. {
  176. mEvent->Clear();
  177. mEvent->SetEventNumber(eventNumber);
  178. mEvent->SetImpactPar(impPar);
  179. return false;
  180. }
  181. }
  182. if (feof(mInEventFile)) // if EOF then return stop flag
  183. return true;
  184. }
  185. }
  186. //_________________
  187. Bool_t StQGSMdstMaker::ReadTracks()
  188. {
  189. Float_t px, py, pz; // [GeV/c]
  190. Float_t energy; // [GeV]
  191. Float_t mass; // [GeV/c^2]
  192. Float_t xFreeze, yFreeze, zFreeze; // [fm]
  193. Float_t tFreeze; // [fm/c]
  194. Float_t xFormation, yFormation, zFormation; // [fm]
  195. Float_t tFormation; // [fm/c]
  196. Float_t tForm; /* [fm/c] this is life time of resonance (?)
  197. * for primary particles this time equals 0
  198. */
  199. Int_t ident; // particle code in ISAJET 7.79
  200. Int_t idiag; // Feynman diagram code
  201. Int_t iorig; // charge*|KP(see QGSM code, it is like orig)|*10^4 + IPAD (decayed particle number in event)
  202. Int_t ib, is, ich; // baryon, strangeness, charge
  203. TLorentzVector particle;
  204. Float_t pt_full = 0.0;
  205. Float_t pt_full2 = 0.0;
  206. mSperp = -999.;
  207. mSperp2 = -999.;
  208. matrix->Zero();
  209. matrix2->Zero();
  210. for (Int_t iTrack = 0; iTrack < mNTracks; iTrack++)
  211. {
  212. Int_t ret = fscanf(mInTrackFile,
  213. " %f %f %f %f" // tfr, xfr, yfr, zfr
  214. " %f %f %f %f %f" // E, px, py, pz, mass
  215. " %i %i %i %i %i" // ident, idiag, B, S, Q
  216. " %f %f %f %f" // tForm, xForm, yForm, zForm
  217. " %i %f ", // iorig and resonance life time
  218. &tFreeze, &xFreeze, &yFreeze, &zFreeze,
  219. &energy, &px, &py, &pz, &mass,
  220. &ident, &idiag, &ib, &is, &ich,
  221. &tFormation, &xFormation, &yFormation, &zFormation,
  222. &iorig, &tForm);
  223. if (ret != 20)
  224. return true;
  225. else
  226. {
  227. StO97Track *track = mEvent->AddOscar97Track();
  228. track->SetId(iTrack);
  229. track->SetPdgId(ident);
  230. track->SetPx(px);
  231. track->SetPy(py);
  232. track->SetPz(pz);
  233. track->SetMass(mass);
  234. track->SetXfr(xFreeze);
  235. track->SetYfr(yFreeze);
  236. track->SetZfr(zFreeze);
  237. track->SetTfr(tFreeze);
  238. if (ich == 0) continue;
  239. /*
  240. * Transverse sphericity calculation with following cuts:
  241. * * |eta| < 0.5 && |eta| < 1.0
  242. * * pT > 0.15 GeV/c
  243. */
  244. // setup particle vector
  245. particle.SetPxPyPzE(px, py, pz, energy);
  246. Float_t pt = particle.Pt();
  247. if (pt > 0.15)
  248. {
  249. Float_t eta = particle.PseudoRapidity(); // it heals pt = 0 case
  250. if (TMath::Abs(eta) < 0.5)
  251. {
  252. (*matrix)(0, 0) += px*px/pt;
  253. (*matrix)(1, 1) += py*py/pt;
  254. (*matrix)(0, 1) += px*py/pt;
  255. (*matrix)(1, 0) += px*py/pt;
  256. pt_full += pt;
  257. }
  258. if (TMath::Abs(eta) < 1.0)
  259. {
  260. (*matrix2)(0, 0) += px*px/pt;
  261. (*matrix2)(1, 1) += py*py/pt;
  262. (*matrix2)(0, 1) += px*py/pt;
  263. (*matrix2)(1, 0) += px*py/pt;
  264. pt_full2 += pt;
  265. }
  266. }
  267. }
  268. }
  269. if (pt_full != 0.0)
  270. {
  271. // |eta| < 0.5 case
  272. *matrix *= 1./pt_full;
  273. TMatrixDSymEigen death_machine(*matrix);
  274. TVectorD eigen = death_machine.GetEigenValues();
  275. mSperp = 2.*eigen.Min()/(eigen[0] + eigen[1]);
  276. // |eta| < 1.0 case
  277. *matrix2 *= 1./pt_full2;
  278. TMatrixDSymEigen death_machine2(*matrix2);
  279. TVectorD eigen2 = death_machine2.GetEigenValues();
  280. mSperp2 = 2.*eigen2.Min()/(eigen2[0] + eigen2[1]);
  281. }
  282. return false;
  283. }