StO97DstQAMaker.cxx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #include "StO97DstQAMaker.h"
  2. ClassImp(StO97DstQAMaker)
  3. //_________________
  4. StO97DstQAMaker::StO97DstQAMaker(const char *dirName,
  5. const char *fileName,
  6. const char *filter,
  7. int maxFiles) {
  8. mDir = string(dirName);
  9. mFileName = string(fileName);
  10. mFilter = string(filter);
  11. mTree = 0;
  12. mChain = 0;
  13. mO97Event = 0;
  14. mEventId = 0;
  15. }
  16. //_________________
  17. Int_t StO97DstQAMaker::Init() {
  18. std::cout << "[StO97DstQAMaker]: Initialization... ";
  19. InitRead(mDir, mFileName, mFilter, mMaxFiles);
  20. mNEvents = (unsigned int)mChain->GetEntries();
  21. mOutFile = new TFile(mOutFileName, "RECREATE");
  22. if (!mOutFile) {
  23. std::cout << "FAIL" << std::endl;
  24. return kStErr;
  25. }
  26. else
  27. std::cout << "OK" << std::endl;
  28. //
  29. // Load PDG database
  30. //
  31. pdgDb = new TDatabasePDG;
  32. pdgDb->ReadPDGTable("StRoot/StFemtoDstMaker/pdg_table.txt");
  33. //
  34. // Creating event histograms
  35. //
  36. int refMultBins = 500;
  37. float refMultLo = 0.;
  38. float refMultHi = 500;
  39. hRefMultP90 = new TH1F("hRefMultP90", "reference multiplicity (greg) p_{#perp} > 0.09 GeV/c;RefMult;#", refMultBins, refMultLo, refMultHi);
  40. hRefMultP100 = new TH1F("hRefMultP100", "reference multiplicity (greg) p_{#perp} > 0.1 GeV/c;RefMult;#", refMultBins, refMultLo, refMultHi);
  41. hRefMultP120 = new TH1F("hRefMultP120", "reference multiplicity (greg) p_{#perp} > 0.12 GeV/c;RefMult;#", refMultBins, refMultLo, refMultHi);
  42. hRefMultP150 = new TH1F("hRefMultP150", "reference multiplicity (greg) p_{#perp} > 0.15 GeV/c;RefMult;#", refMultBins, refMultLo, refMultHi);
  43. hImpPar = new TH1F("hImpPar", "impact parameter;imp (fm/c);#", 100, 0., 20.);
  44. hSph = new TH1F("hSph",
  45. "Transverse sphericity (|#eta| < 0.5, p_{#perp} > 0.15 GeV/c);S_{#perp},#frac{dN}{dS_{#perp}}",
  46. 100, 0., 1.);
  47. hSph = new TH1F("hSph",
  48. "Transverse sphericity (|#eta| < 0.5, p_{#perp} > 0.15 GeV/c);S_{#perp},#frac{dN}{dS_{#perp}}",
  49. 100, 0., 1.);
  50. hSph2 = new TH1F("hSph2",
  51. "Transverse sphericity (|#eta| < 1.0, p_{#perp} > 0.15 GeV/c);S_{#perp},#frac{dN}{dS_{#perp}}",
  52. 100, 0., 1.);
  53. hImpVsRef = new TH2F("hImpVsRef", "p_{#perp} > 0.15 [GeV/c] && |#eta| < 0.5;b [fm];RefMult", 100, 0., 20., refMultBins, refMultLo, refMultHi);
  54. //
  55. // Creating track histograms
  56. //
  57. hVx = new TH1F("hVx", "x freeze-out position;V_{x} (fm);#", 500, -50., 50.);
  58. hVy = new TH1F("hVy", "y freeze-out position;V_{y} (fm);#", 500, -50., 50.);
  59. hVz = new TH1F("hVz", "z freeze-out position;V_{z} (fm);#", 500, -50., 50.);
  60. hPx = new TH1F("hPx", "single particle p_{x};p_{x} (GeV/c);#", 200, -2., 2.);
  61. hPy = new TH1F("hPy", "single particle p_{y};p_{y} (GeV/c);#", 200, -2., 2.);
  62. hPz = new TH1F("hPz", "single particle p_{z};p_{z} (GeV/c);#", 200, -2., 2.);
  63. hP = new TH1F("hP", "single particle p;p (GeV/c);#", 400, 0., 2.);
  64. hPt = new TH1F("hPt", "single particle p_{T};p_{T} (GeV/c);#", 400, 0., 2.);
  65. hEta = new TH1F("hEta", ";#eta;#", 200, -10., 10.);
  66. hEtaInt = new TH1F("hEtaInt", ";#eta;#", 200, -10., 10.);
  67. hMSqrVsPt = new TH2F("hMSqrVsPt",
  68. "m^{2} vs p_{T};p_{T}*charge (GeV/c);m^{2} (GeV^{2})",
  69. 200, -2., 2., // Pt
  70. 100, 0., 2.); // msqr
  71. hMomElectron = new TH1F("hMomElectron", "Momentum of e^{#pm};p (GeV/c);#frac{dN}{dp}",
  72. 250, 0., 2.5);
  73. hMomPion = new TH1F("hMomPion", "Momentum of #pi^{#pm};p (GeV/c);#frac{dN}{dp}",
  74. 250, 0., 2.5);
  75. hMomKaon = new TH1F("hMomKaon", "Momentum of K^{#pm};p (GeV/c);#frac{dN}{dp}",
  76. 250, 0., 2.5);
  77. hMomProton = new TH1F("hMomProton", "Momentum of p^{#pm};p (GeV/c);#frac{dN}{dp}",
  78. 250, 0., 2.5);
  79. hRfrVsTfr_pion = new TH2F("hRfrVsTfr_pion", ";R^{#pi^{ch}}_{freeze out} [fm];#tau^{#pi^{ch}}_{freeze out} [fm/c]",
  80. 300, 0., 15.,
  81. 300, 0., 15.);
  82. hRfrVsTfr_kaon = new TH2F("hRfrVsTfr_kaon", ";R^{K^{ch}}_{freeze out} [fm];#tau^{K^{ch}}_{freeze out} [fm/c]",
  83. 300, 0., 15.,
  84. 300, 0., 15.);
  85. hRfrVsTfr_proton = new TH2F("hRfrVsTfr_proton", ";R^{p^{#pm}}_{freeze out} [fm];#tau^{p^{#pm}}_{freeze out} [fm/c]",
  86. 300, 0., 15.,
  87. 300, 0., 15.);
  88. hdNdTfr_pion = new TH1F("hdNdTfr_pion", ";#frac{dN}{d#tau^{#pi^{ch}_{freezeout}}};#tau^{#pi^{ch}}_{freezeout} [fm/c]",
  89. 1000, 0., 1000.);
  90. hdNdTfr_kaon = new TH1F("hdNdTfr_kaon", ";#frac{dN}{d#tau^{K^{ch}_{freezeout}}};#tau^{K^{ch}}_{freezeout} [fm/c]",
  91. 1000, 0., 1000.);
  92. hdNdTfr_proton = new TH1F("hdNdTfr_proton", ";#frac{dN}{d#tau^{p^{ch}_{freezeout}}};#tau^{p^{ch}}_{freezeout} [fm/c]",
  93. 1000, 0., 1000.);
  94. return kStOk;
  95. }
  96. //_________________
  97. Int_t StO97DstQAMaker::Finish() {
  98. UninitRead();
  99. mOutFile->Write();
  100. mOutFile->Close();
  101. delete pdgDb;
  102. return kStOk;
  103. }
  104. //_________________
  105. int StO97DstQAMaker::FillChain(TChain *chain, char *dir,
  106. const char *filter, int maxFiles) {
  107. TSystem *gSystem = new TSystem();
  108. if (!gSystem) {
  109. std::cout << "[StO97DstQAMaker]: can't allocate memory for TSystem" << std::endl;;
  110. return 0;
  111. }
  112. void *gDir = gSystem->OpenDirectory(dir);
  113. if (!gDir) {
  114. std::cout << "[StO97DstQAMaker]: can't open directory "
  115. << dir << std::endl;
  116. delete gSystem;
  117. return 0;
  118. }
  119. int count = 0;
  120. char *file;
  121. while ((file = (char *)gSystem->GetDirEntry(dir))) {
  122. if (strcmp(file, ".") == 0 || strcmp(file, "..") == 0)
  123. continue;
  124. if (strstr(file, filter)) {
  125. char *gFullName = gSystem->ConcatFileName(dir, file);
  126. std::cout << "[StO97DstQAMaker]: Adding "
  127. << gFullName << " to the chain" << std::endl;
  128. chain->Add(gFullName);
  129. delete gFullName;
  130. count++;
  131. if ((maxFiles > 0) && (count > maxFiles)) break;
  132. }
  133. }
  134. std::cout << "[StO97DstQAMaker]: Added " << count
  135. << " files to the chain" << std::endl;
  136. delete gSystem;
  137. return count;
  138. }
  139. //_________________
  140. int StO97DstQAMaker::FillChain(TChain *chain, const char *fileName,
  141. int maxFiles) {
  142. std::ifstream inStream(fileName);
  143. if (!inStream.is_open()) {
  144. std::cout << "[StFemtoDstQAMaker]: can't open file list: "
  145. << fileName << std::endl;
  146. return 0;
  147. }
  148. std::cout << "[StFemtoDstQAMaker]: using file list: "
  149. << fileName << std::endl;
  150. int count = 0;
  151. char buf[0xFF];
  152. for ( ; inStream.good(); ) {
  153. inStream.getline(buf, 0xFF);
  154. TString lFileName(buf);
  155. if (lFileName.Contains("root")) {
  156. chain->Add(buf);
  157. count++;
  158. if ((maxFiles > 0) && (count > maxFiles)) break;
  159. }
  160. }
  161. std::cout << "[StO97DstQAMaker]: Added " << count
  162. << " files to the chain" << std::endl;
  163. return count;
  164. }
  165. //_________________
  166. int StO97DstQAMaker::InitRead(string dir, string fileName,
  167. string filter, int maxFiles) {
  168. mEventId = 0;
  169. mChain = new TChain("StO97Dst", "StO97Dst");
  170. std::cout << "[StO97DstQAMaker]: Call InitRead" << std::endl;
  171. int numFiles = 0;
  172. if (!fileName.empty()) {
  173. if (strstr(fileName.c_str(), ".lis") ||
  174. strstr(fileName.c_str(), ".list")) {
  175. numFiles = FillChain(mChain,
  176. (dir + fileName).c_str(),
  177. maxFiles);
  178. }
  179. else {
  180. mChain->Add((dir + fileName).c_str());
  181. numFiles++;
  182. }
  183. } else {
  184. numFiles = FillChain(mChain, (char *)dir.c_str(), // not cool
  185. filter.c_str(), maxFiles);
  186. }
  187. mChain->SetBranchAddress("StO97Event", &mO97Event);
  188. mNEvents = (unsigned int)mChain->GetEntries();
  189. return numFiles;
  190. }
  191. //_________________
  192. void StO97DstQAMaker::UninitRead() {
  193. if (mChain) delete mChain;
  194. mO97Event = 0;
  195. mChain = 0;
  196. }
  197. //_________________
  198. int StO97DstQAMaker::GetNEvents() {
  199. if (mChain)
  200. return mNEvents;
  201. else
  202. return -1;
  203. }
  204. //_________________
  205. Int_t StO97DstQAMaker::Make() {
  206. if (!mNEvents) {
  207. std::cout << "[StO97DstQAMaker]: no events to read" << std::endl;
  208. return 0;
  209. }
  210. mO97Event->Clear();
  211. int bytes = mChain->GetEntry(mEventId++);
  212. if (mNEvents < mEventId) {
  213. std::cout << "[StO97DstQAMaker]: EOF" << std::endl;
  214. return 0;
  215. }
  216. if (!bytes) {
  217. std::cout << "[StO97DstQAMaker]: no event" << std::endl;
  218. return 0;
  219. }
  220. if (mO97Event) {
  221. int refMultP90 = 0;
  222. int refMultP100 = 0;
  223. int refMultP120 = 0;
  224. int refMultP150 = 0;
  225. float imp = mO97Event->GetImpactPar();
  226. TClonesArray *tracks = mO97Event->GetTracks();
  227. if (tracks) {
  228. int nTracks = tracks->GetEntries();
  229. for (int i = 0; i < nTracks; i++) {
  230. StO97Track *track = (StO97Track *)tracks->At(i);
  231. float px = track->GetPx();
  232. float py = track->GetPy();
  233. float pz = track->GetPz();
  234. float pt = sqrt(px*px + py*py);
  235. float p = sqrt(px*px + py*py + pz*pz);
  236. float massSqr = track->GetMass()*track->GetMass();
  237. float vx = track->GetXfr();
  238. float vy = track->GetYfr();
  239. float vz = track->GetZfr();
  240. float Rfr = TMath::Sqrt(vx*vx + vy*vy);
  241. float Tfr = track->GetTfr();
  242. float eta = pt > 0.05 /* i.e. pt > 0 */ ? 0.5*log((p + pz)/(p - pz)) : -999.;
  243. int pdg = track->GetPdgId();
  244. int charge = track->GetCharge(pdgDb);
  245. hEtaInt->Fill(eta);
  246. if (pt < 0.075 || fabs(eta) >= 0.5 /* STAR TPC acceptance */ ||
  247. charge == 0. /* only charged particles */ ||
  248. track->GetIsSpec()) {
  249. continue;
  250. }
  251. if (pt >= 0.09) refMultP90++;
  252. if (pt >= 0.10) refMultP100++;
  253. if (pt >= 0.12) refMultP120++;
  254. if (pt >= 0.15) refMultP150++;
  255. if (pt >= 0.1 /* STAR TPC lower momentum limit from STAR TPC NIM */) {
  256. hMSqrVsPt->Fill(pt*charge, massSqr);
  257. hVx->Fill(vx);
  258. hVy->Fill(vy);
  259. hVz->Fill(vz);
  260. hPx->Fill(px);
  261. hPy->Fill(py);
  262. hPz->Fill(pz);
  263. hPt->Fill(pt);
  264. hP->Fill(p);
  265. hEta->Fill(eta);
  266. }
  267. switch (abs(pdg)) {
  268. case 11: // Electron
  269. hMomElectron->Fill(p);
  270. break;
  271. case 211: // Pion
  272. hMomPion->Fill(p);
  273. hdNdTfr_pion->Fill(Tfr);
  274. hRfrVsTfr_pion->Fill(Rfr, Tfr);
  275. break;
  276. case 321: // Kaon
  277. hMomKaon->Fill(p);
  278. hdNdTfr_kaon->Fill(Tfr);
  279. hRfrVsTfr_kaon->Fill(Rfr, Tfr);
  280. break;
  281. case 2212: // Proton
  282. hMomProton->Fill(p);
  283. hdNdTfr_proton->Fill(Tfr);
  284. hRfrVsTfr_proton->Fill(Rfr, Tfr);
  285. } // switch (abs(pdg))
  286. } // for (int i = 0; i < nTracks; i++)
  287. } // if (tracks)
  288. else {
  289. std::cout << "[StO97DstQAMaker]: tracks == NULL" << std::endl;
  290. }
  291. if (refMultP90)
  292. hRefMultP90->Fill(refMultP90);
  293. if (refMultP100)
  294. hRefMultP100->Fill(refMultP100);
  295. if (refMultP120)
  296. hRefMultP120->Fill(refMultP120);
  297. if (refMultP150)
  298. hRefMultP150->Fill(refMultP150);
  299. hSph->Fill(mO97Event->GetTransverseSphericity());
  300. hSph2->Fill(mO97Event->GetTransverseSphericity2());
  301. hImpPar->Fill(imp);
  302. hImpVsRef->Fill(imp, refMultP150);
  303. } // if (mO97Event)
  304. return kStOk;
  305. }