main.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include <iostream>
  2. #include <vector>
  3. #include <TString.h>
  4. #include <TH1D.h>
  5. #include <TH1I.h>
  6. #include <TH2D.h>
  7. #include <TProfile.h>
  8. #include <TProfile3D.h>
  9. #include <TFile.h>
  10. #include <TStopwatch.h>
  11. #include <qaParticle.h>
  12. #include <qaParticleLight.h>
  13. #include <qaEvent.h>
  14. #include <qaReader_manager.h>
  15. #include <qaReader_smash_root.h>
  16. #include <qaReader_mcpico.h>
  17. #include <Utility.h>
  18. #ifdef _MCINI_
  19. #include <qaReader_mcini.h>
  20. #endif
  21. #ifdef _PHQMD_
  22. #include <qaReader_phqmd.h>
  23. #endif
  24. #ifdef _HSD_ROOT_
  25. #include <qaReader_hsd_root.h>
  26. #endif
  27. int main(int argc, char **argv)
  28. {
  29. TString iFileName, oFileName, configFileName = "";
  30. if (argc < 7)
  31. {
  32. std::cerr << "./mConvert -i input.list -o qa_output.root -format [FORMAT] [OPTIONAL: -config qa.cfg]" << std::endl;
  33. std::cerr << "Available formats:" << std::endl;
  34. std::cerr << "\tmcpico - simple custom ROOT format to store model data." << std::endl;
  35. std::cerr << "\tparticle - ROOT format that is used by the SMASH model." << std::endl;
  36. #ifdef _MCINI_
  37. std::cerr << "\tmcini - custom ROOT format to store both initial state and final state (UniGen data format) model data. Fully compatible with UniGen format." << std::endl;
  38. #endif
  39. #ifdef _PHQMD_
  40. std::cerr << "\tphqmd - custom ROOT format to store PHQMD (with MST) model data." << std::endl;
  41. #endif
  42. #ifdef _HSD_ROOT_
  43. std::cerr << "\thsd - custom ROOT format to store HSD model data." << std::endl;
  44. #endif
  45. return 1;
  46. }
  47. for (int i = 1; i < argc; i++)
  48. {
  49. if (std::string(argv[i]) != "-i" &&
  50. std::string(argv[i]) != "-o" &&
  51. std::string(argv[i]) != "-format" &&
  52. std::string(argv[i]) != "-config")
  53. {
  54. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  55. return 2;
  56. }
  57. else
  58. {
  59. if (std::string(argv[i]) == "-i" && i != argc - 1)
  60. {
  61. iFileName = argv[++i];
  62. continue;
  63. }
  64. if (std::string(argv[i]) == "-i" && i == argc - 1)
  65. {
  66. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  67. return 1;
  68. }
  69. if (std::string(argv[i]) == "-o" && i != argc - 1)
  70. {
  71. oFileName = argv[++i];
  72. continue;
  73. }
  74. if (std::string(argv[i]) == "-o" && i == argc - 1)
  75. {
  76. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  77. return 1;
  78. }
  79. if (std::string(argv[i]) == "-format" && i != argc - 1)
  80. {
  81. qaUtility::GetInstance()->format = argv[++i];
  82. continue;
  83. }
  84. if (std::string(argv[i]) == "-format" && i == argc - 1)
  85. {
  86. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  87. return 1;
  88. }
  89. if (std::string(argv[i]) == "-config" && i != argc - 1)
  90. {
  91. configFileName = argv[++i];
  92. continue;
  93. }
  94. if (std::string(argv[i]) == "-config" && i == argc - 1)
  95. {
  96. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  97. return 1;
  98. }
  99. }
  100. }
  101. TStopwatch timer;
  102. timer.Start();
  103. Bool_t IsRead = true;
  104. if (configFileName.Length() > 0)
  105. {
  106. IsRead = qaUtility::GetInstance()->ReadConfig(configFileName);
  107. }
  108. if (!IsRead)
  109. {
  110. std::cerr << "Error while reading config file. Exiting..." << std::endl;
  111. return 2;
  112. }
  113. TFile *fo = new TFile(oFileName, "recreate");
  114. const int ntracks_max = 15000;
  115. Float_t d_bimp;
  116. Float_t d_phi2;
  117. Float_t d_phi3;
  118. Float_t d_ecc2;
  119. Float_t d_ecc3;
  120. Int_t d_npart;
  121. Int_t d_nh;
  122. Float_t d_momx[ntracks_max]; //[nh]
  123. Float_t d_momy[ntracks_max]; //[nh]
  124. Float_t d_momz[ntracks_max]; //[nh]
  125. Float_t d_ene[ntracks_max]; //[nh]
  126. Int_t d_hid[ntracks_max]; //[nh]
  127. Int_t d_pdg[ntracks_max]; //[nh]
  128. Short_t d_charge[ntracks_max]; //[nh]
  129. TTree *oTree = new TTree("mctree","mcpico format");
  130. oTree->Branch("bimp",&d_bimp,"bimp/F"); // impact parametr
  131. oTree->Branch("phi2",&d_phi2,"phi2/F"); // phiRP2
  132. oTree->Branch("phi3",&d_phi3,"phi3/F"); // phiRP3
  133. oTree->Branch("ecc2",&d_ecc2,"ecc2/F"); // eccentricity2
  134. oTree->Branch("ecc3",&d_ecc3,"ecc3/F"); // eccentricity3
  135. oTree->Branch("npart",&d_npart,"npart/I"); // number of participants
  136. oTree->Branch("nh",&d_nh,"nh/I"); // number of particles
  137. oTree->Branch("momx",&d_momx,"momx[nh]/F");
  138. oTree->Branch("momy",&d_momy,"momy[nh]/F");
  139. oTree->Branch("momz",&d_momz,"momz[nh]/F");
  140. oTree->Branch("ene",&d_ene,"ene[nh]/F");//[energy]
  141. oTree->Branch("hid",&d_hid,"hid[nh]/I");//[histrory id]
  142. oTree->Branch("pdg",&d_pdg,"pdg[nh]/I");//[particle data group code]
  143. oTree->Branch("charge",&d_charge,"charge[nh]/S");//[electric charge]
  144. qaReader_manager *readerManager;
  145. if (qaUtility::GetInstance()->format == "mcpico")
  146. {
  147. readerManager = new qaReader_mcpico();
  148. }
  149. #ifdef _MCINI_
  150. if (qaUtility::GetInstance()->format == "mcini")
  151. {
  152. readerManager = new qaReader_mcini();
  153. }
  154. #endif
  155. #ifdef _PHQMD_
  156. if (qaUtility::GetInstance()->format == "phqmd")
  157. {
  158. readerManager = new qaReader_phqmd();
  159. }
  160. #endif
  161. #ifdef _HSD_ROOT_
  162. if (qaUtility::GetInstance()->format == "hsd")
  163. {
  164. readerManager = new qaReader_hsd_root();
  165. }
  166. #endif
  167. if (qaUtility::GetInstance()->format == "particles")
  168. {
  169. readerManager = new qaReader_smash_root();
  170. }
  171. if (!readerManager)
  172. {
  173. std::cerr << "This input format is not found!" << std::endl;
  174. return 20;
  175. }
  176. readerManager->SetChain(iFileName.Data());
  177. Long64_t Nentries_chain = readerManager->GetEntries();
  178. Long64_t Nentries = (qaUtility::GetInstance()->Nevents > Nentries_chain) ? Nentries_chain : qaUtility::GetInstance()->Nevents;
  179. if (qaUtility::GetInstance()->Nevents == -1)
  180. Nentries = Nentries_chain;
  181. Int_t Nparticles;
  182. qaEvent *event = nullptr;
  183. qaParticle *particle = nullptr;
  184. Long64_t Absolute_counter = 0;
  185. Long64_t Minbias_counter = 0;
  186. while (Minbias_counter < Nentries)
  187. {
  188. //if (Minbias_counter % 1000 == 0)
  189. std::cout << "Event [" << Minbias_counter << "/" << Nentries << "]" << std::endl;
  190. event = (qaEvent *)readerManager->ReadEvent(Absolute_counter);
  191. Absolute_counter++;
  192. if (Absolute_counter > Nentries_chain)
  193. break;
  194. if (!event)
  195. continue;
  196. Minbias_counter++;
  197. d_bimp = event->GetB();
  198. d_phi2 = event->GetPhiRP();
  199. d_nh = event->GetNparticles();
  200. d_npart= 0;
  201. d_ecc2 = 0.;
  202. d_ecc3 = 0.;
  203. Nparticles = event->GetNparticles();
  204. for (int iparticle = 0; iparticle < Nparticles; iparticle++)
  205. {
  206. particle = readerManager->ReadParticle(iparticle);
  207. if (!particle)
  208. {
  209. particle = new qaParticle();
  210. particle->SetPx(qaUtility::GetInstance()->error_code);
  211. particle->SetPy(qaUtility::GetInstance()->error_code);
  212. particle->SetPz(qaUtility::GetInstance()->error_code);
  213. particle->SetX(qaUtility::GetInstance()->error_code);
  214. particle->SetY(qaUtility::GetInstance()->error_code);
  215. particle->SetZ(qaUtility::GetInstance()->error_code);
  216. }
  217. d_momx[iparticle] = particle->GetPx();
  218. d_momy[iparticle] = particle->GetPy();
  219. d_momz[iparticle] = particle->GetPz();
  220. d_ene[iparticle] = particle->GetEnergy();
  221. d_pdg[iparticle] = particle->GetPdg();
  222. d_hid[iparticle] = 0.;
  223. d_charge[iparticle] = particle->GetCharge();
  224. delete particle;
  225. }
  226. oTree->Fill();
  227. delete event;
  228. }
  229. std::cout << "Loop is closed, " << Minbias_counter << " events were counted." << std::endl;
  230. std::cout << "Writing output." << std::endl;
  231. fo->cd();
  232. oTree->Write();
  233. oTree->Print();
  234. fo->Close();
  235. timer.Stop();
  236. timer.Print();
  237. return 0;
  238. }