readRes.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #include <iostream>
  2. #include <fstream>
  3. #include <TStopwatch.h>
  4. #include <TString.h>
  5. #include <TChain.h>
  6. #include <TH2F.h>
  7. #include <TProfile.h>
  8. #include "fmcTypes.h"
  9. #include "fmcReader.h"
  10. #include "fmcEvent.h"
  11. #include "fmcEventHeader.h"
  12. #include "fmcParticle.h"
  13. #include "fmcParticleLoopInfo.h"
  14. #include "fmcLoopProcess.h"
  15. #include "fmcLoopOption.h"
  16. #include "fmcQvector.h"
  17. #include "fmcConstants.h"
  18. #include "fmcFunctions.cxx"
  19. #ifndef _MCINI_
  20. const char *_TREENAME_ = "mctree";
  21. #endif
  22. #ifdef _MCINI_
  23. const char *_TREENAME_ = "events";
  24. #endif
  25. int main(int argc, char **argv)
  26. {
  27. TString inFilelistName, outFileName, refMultFileName, histMultName = "hRefMultSTAR";
  28. if (argc < 7)
  29. {
  30. std::cerr << "./readRes -i filelist -o output -refMult refMultFile" << std::endl;
  31. return 10;
  32. }
  33. for (int i = 1; i < argc; i++)
  34. {
  35. if (std::string(argv[i]) != "-i" &&
  36. std::string(argv[i]) != "-o" &&
  37. std::string(argv[i]) != "-refMult")
  38. {
  39. std::cerr << "\nreadRes: Unknown parameter " << i
  40. << ": " << argv[i] << std::endl;
  41. return 11;
  42. }
  43. else
  44. {
  45. if (std::string(argv[i]) == "-i" && i != argc - 1)
  46. {
  47. inFilelistName = argv[++i];
  48. }
  49. if (std::string(argv[i]) == "-i" && i == argc - 1)
  50. {
  51. std::cerr << "\nreadRes: Input file name was not specified!" << std::endl;
  52. return 20;
  53. }
  54. if (std::string(argv[i]) == "-o" && i != argc - 1)
  55. {
  56. outFileName = argv[++i];
  57. }
  58. if (std::string(argv[i]) == "-o" && i == argc - 1)
  59. {
  60. std::cerr << "\nreadRes: Output file name was not specified!" << std::endl;
  61. return 21;
  62. }
  63. if (std::string(argv[i]) == "-refMult" && i != argc - 1)
  64. {
  65. refMultFileName = argv[++i];
  66. }
  67. if (std::string(argv[i]) == "-refMult" && i == argc - 1)
  68. {
  69. std::cerr << "\nreadRes: Output file name was not specified!" << std::endl;
  70. return 22;
  71. }
  72. }
  73. }
  74. TChain *chain = new TChain(_TREENAME_);
  75. std::fstream file(inFilelistName.Data());
  76. std::string str;
  77. int nfiles = 0;
  78. while (std::getline(file, str))
  79. {
  80. if (chain->Add(str.c_str()))
  81. nfiles++;
  82. }
  83. std::cout << "Processing readRes..." << std::endl;
  84. std::cout << "Found " << nfiles << " files in the filelist." << std::endl;
  85. fmcReader *reader = new fmcReader();
  86. reader->Init(chain);
  87. fmcLong Nevents = reader->GetEntries();
  88. std::cout << "readRes: found " << Nevents << " events." << std::endl;
  89. // SetOptions for particle loop
  90. fmcLoopOption *loopOption = new fmcLoopOption();
  91. loopOption->ProcessRefMult();
  92. loopOption->ProcessQv();
  93. // Init particle loop info
  94. fmcParticleLoopInfo *loopInfo = nullptr;
  95. // Init particle loop process
  96. fmcLoopProcess *process = new fmcLoopProcess();
  97. process->SetLoopOptions(loopOption);
  98. process->SetReader(reader);
  99. // Prepare centrality selection
  100. fmc::Lim lim;
  101. fmcInt centrality;
  102. TFile *fiMult = new TFile(refMultFileName.Data(), "read");
  103. TH1I *hMult = (TH1I *)fiMult->Get(histMultName.Data());
  104. if (!hMult)
  105. return 30;
  106. fmcDouble CentEff = (histMultName == "hRefMultSTAR") ? 1. : 0.93;
  107. lim = fmc::CentralityBorders(hMult, CentEff);
  108. delete hMult;
  109. fiMult->Close();
  110. delete fiMult;
  111. // Init output
  112. TH2F *hQxEastTPC[fmc::nTpcEtaGaps];
  113. TH2F *hQxWestTPC[fmc::nTpcEtaGaps];
  114. TH2F *hQyEastTPC[fmc::nTpcEtaGaps];
  115. TH2F *hQyWestTPC[fmc::nTpcEtaGaps];
  116. TProfile *presTPC[fmc::nTpcEtaGaps];
  117. TH2F *hQxEastRXN, *hQxEastFHCal;
  118. TH2F *hQxWestRXN, *hQxWestFHCal;
  119. TH2F *hQyEastRXN, *hQyEastFHCal;
  120. TH2F *hQyWestRXN, *hQyWestFHCal;
  121. TProfile *presRXN, *presFHCal;
  122. for (int i = 0; i < fmc::nTpcEtaGaps; i++)
  123. {
  124. hQxEastTPC[i] = new TH2F(Form("hQxEastTPC_gap%i", i),
  125. Form("hQxEastTPC_gap%i", i), 500, -50., 50., 10, 0., 100.);
  126. hQxWestTPC[i] = new TH2F(Form("hQxWestTPC_gap%i", i),
  127. Form("hQxWestTPC_gap%i", i), 500, -50., 50., 10, 0., 100.);
  128. hQyEastTPC[i] = new TH2F(Form("hQyEastTPC_gap%i", i),
  129. Form("hQyEastTPC_gap%i", i), 500, -50., 50., 10, 0., 100.);
  130. hQyWestTPC[i] = new TH2F(Form("hQyWestTPC_gap%i", i),
  131. Form("hQyWestTPC_gap%i", i), 500, -50., 50., 10, 0., 100.);
  132. presTPC[i] = new TProfile(Form("presTPC_gap%i", i),
  133. Form("presTPC_gap%i", i), 10, 0., 100.);
  134. }
  135. hQxEastRXN = new TH2F(Form("hQxEastRXN"),
  136. Form("hQxEastRXN"), 500, -50., 50., 10, 0., 100.);
  137. hQxWestRXN = new TH2F(Form("hQxWestRXN"),
  138. Form("hQxWestRXN"), 500, -50., 50., 10, 0., 100.);
  139. hQyEastRXN = new TH2F(Form("hQyEastRXN"),
  140. Form("hQyEastRXN"), 500, -50., 50., 10, 0., 100.);
  141. hQyWestRXN = new TH2F(Form("hQyWestRXN"),
  142. Form("hQyWestRXN"), 500, -50., 50., 10, 0., 100.);
  143. presRXN = new TProfile(Form("presRXN"),
  144. Form("presRXN"), 10, 0., 100.);
  145. hQxEastFHCal = new TH2F(Form("hQxEastFHCal"),
  146. Form("hQxEastFHCal"), 500, -50., 50., 10, 0., 100.);
  147. hQxWestFHCal = new TH2F(Form("hQxWestFHCal"),
  148. Form("hQxWestFHCal"), 500, -50., 50., 10, 0., 100.);
  149. hQyEastFHCal = new TH2F(Form("hQyEastFHCal"),
  150. Form("hQyEastFHCal"), 500, -50., 50., 10, 0., 100.);
  151. hQyWestFHCal = new TH2F(Form("hQyWestFHCal"),
  152. Form("hQyWestFHCal"), 500, -50., 50., 10, 0., 100.);
  153. presFHCal = new TProfile(Form("presFHCal"),
  154. Form("presFHCal"), 10, 0., 100.);
  155. TStopwatch timer;
  156. timer.Start();
  157. fmcInt k;
  158. for (fmcLong iEv = 0; iEv < Nevents; iEv++)
  159. {
  160. if (iEv % 1000 == 0)
  161. std::cout << "readRes: Event [" << iEv << "/"
  162. << Nevents << "]" << std::endl;
  163. loopInfo = process->ProcessParticleLoop(iEv);
  164. if (!loopInfo)
  165. continue;
  166. // Define centrality bin
  167. if (loopInfo->GetMultSTAR() == 0)
  168. {
  169. delete loopInfo;
  170. continue;
  171. }
  172. centrality = fmc::GetCentrality(lim, loopInfo->GetMultSTAR());
  173. if ( (centrality/10.) > lim.L.size() ||
  174. (centrality/10.) > lim.H.size()) continue;
  175. fmcQvector *qvEastTPC[fmc::nTpcEtaGaps], *qvWestTPC[fmc::nTpcEtaGaps];
  176. fmcQvector *qvEastRXN, *qvWestRXN;
  177. fmcQvector *qvEastFHCal, *qvWestFHCal;
  178. // Define Qvectors
  179. k = 0;
  180. for (int i = 0; i < fmc::nTpcEtaGaps; i++)
  181. {
  182. qvEastTPC[i] = loopInfo->GetQv(k);
  183. k++;
  184. qvWestTPC[i] = loopInfo->GetQv(k);
  185. k++;
  186. }
  187. qvEastRXN = loopInfo->GetQv(k);
  188. k++;
  189. qvWestRXN = loopInfo->GetQv(k);
  190. k++;
  191. qvEastFHCal = loopInfo->GetQv(k);
  192. k++;
  193. qvWestFHCal = loopInfo->GetQv(k);
  194. for (int i = 0; i < fmc::nTpcEtaGaps; i++)
  195. {
  196. hQxEastTPC[i]->Fill(qvEastTPC[i]->GetX(), centrality);
  197. hQyEastTPC[i]->Fill(qvEastTPC[i]->GetY(), centrality);
  198. hQxWestTPC[i]->Fill(qvWestTPC[i]->GetX(), centrality);
  199. hQyWestTPC[i]->Fill(qvWestTPC[i]->GetY(), centrality);
  200. presTPC[i]->Fill(centrality, TMath::Cos(2 * (qvEastTPC[i]->GetPhi() - qvWestTPC[i]->GetPhi())));
  201. }
  202. hQxEastRXN->Fill(qvEastRXN->GetX(), centrality);
  203. hQyEastRXN->Fill(qvEastRXN->GetY(), centrality);
  204. hQxWestRXN->Fill(qvWestRXN->GetX(), centrality);
  205. hQyWestRXN->Fill(qvWestRXN->GetY(), centrality);
  206. presRXN->Fill(centrality, TMath::Cos(2 * (qvEastRXN->GetPhi() - qvWestRXN->GetPhi())));
  207. hQxEastFHCal->Fill(qvEastFHCal->GetX(), centrality);
  208. hQyEastFHCal->Fill(qvEastFHCal->GetY(), centrality);
  209. hQxWestFHCal->Fill(qvWestFHCal->GetX(), centrality);
  210. hQyWestFHCal->Fill(qvWestFHCal->GetY(), centrality);
  211. presFHCal->Fill(centrality, TMath::Cos(1 * (qvEastFHCal->GetPhi() - qvWestFHCal->GetPhi())));
  212. delete loopInfo;
  213. }
  214. // Write output
  215. TFile *fo = new TFile(outFileName.Data(), "recreate");
  216. fo->mkdir("Qv");
  217. fo->mkdir("Res2");
  218. fo->cd("Qv");
  219. for (int i = 0; i < fmc::nTpcEtaGaps; i++)
  220. {
  221. hQxEastTPC[i]->Write();
  222. hQyEastTPC[i]->Write();
  223. hQxWestTPC[i]->Write();
  224. hQyWestTPC[i]->Write();
  225. }
  226. hQxEastRXN->Write();
  227. hQyEastRXN->Write();
  228. hQxWestRXN->Write();
  229. hQyWestRXN->Write();
  230. hQxEastFHCal->Write();
  231. hQyEastFHCal->Write();
  232. hQxWestFHCal->Write();
  233. hQyWestFHCal->Write();
  234. fo->cd("Res2");
  235. for (int i = 0; i < fmc::nTpcEtaGaps; i++)
  236. {
  237. presTPC[i]->Write();
  238. }
  239. presRXN->Write();
  240. presFHCal->Write();
  241. fo->Close();
  242. timer.Stop();
  243. timer.Print();
  244. return 0;
  245. }