main.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 <TProfile2D.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. #include <qaWriter_manager.h>
  19. #include <qaWriter_analysistree2.h>
  20. #ifdef _MCINI_
  21. #include <qaReader_mcini.h>
  22. #endif
  23. #ifdef _PHQMD_
  24. #include <qaReader_phqmd.h>
  25. #endif
  26. #ifdef _HSD_ROOT_
  27. #include <qaReader_hsd_root.h>
  28. #endif
  29. // AnalysisTree headers
  30. #include <AnalysisTree/Configuration.hpp>
  31. #include <AnalysisTree/DataHeader.hpp>
  32. #include <AnalysisTree/EventHeader.hpp>
  33. #include <AnalysisTree/Detector.hpp>
  34. #include <AnalysisTree/Matching.hpp>
  35. int main(int argc, char **argv)
  36. {
  37. TString iFileName, oFileName;
  38. TString outputFormat = "analysistree_v2";
  39. if (argc < 7)
  40. {
  41. std::cerr << "./matc -i input.list -o output.root -input_format [INPUT_FORMAT] [OPTIONAL: -output_format [OUTPUT_FORMAT]]" << std::endl;
  42. std::cerr << "Available input formats:" << std::endl;
  43. std::cerr << "\tmcpico - simple custom ROOT format to store model data" << std::endl;
  44. std::cerr << "\tparticle - ROOT format that is used by the SMASH model" << std::endl;
  45. #ifdef _MCINI_
  46. std::cerr << "\tmcini - custom ROOT format to store both initial state and final state (UniGen data format) model data" << std::endl;
  47. #endif
  48. #ifdef _PHQMD_
  49. std::cerr << "\tphqmd - custom ROOT format to store PHQMD (with MST) model data" << std::endl;
  50. #endif
  51. #ifdef _HSD_ROOT_
  52. std::cerr << "\thsd - custom ROOT format to store HSD model data" << std::endl;
  53. #endif
  54. std::cerr << "Available output formats:" << std::endl;
  55. std::cerr << "\tanalysistree_v2 - AnalysisTree ver. 2 data format" << std::endl;
  56. return 1;
  57. }
  58. for (int i = 1; i < argc; i++)
  59. {
  60. if (std::string(argv[i]) != "-i" &&
  61. std::string(argv[i]) != "-o" &&
  62. std::string(argv[i]) != "-input_format" &&
  63. std::string(argv[i]) != "-output_format")
  64. {
  65. std::cerr << "\n[ERROR]: Unknown parameter " << i << ": " << argv[i] << std::endl;
  66. return 2;
  67. }
  68. else
  69. {
  70. if (std::string(argv[i]) == "-i" && i != argc - 1)
  71. {
  72. iFileName = argv[++i];
  73. continue;
  74. }
  75. if (std::string(argv[i]) == "-i" && i == argc - 1)
  76. {
  77. std::cerr << "\n[ERROR]: Input file name was not specified " << std::endl;
  78. return 1;
  79. }
  80. if (std::string(argv[i]) == "-o" && i != argc - 1)
  81. {
  82. oFileName = argv[++i];
  83. continue;
  84. }
  85. if (std::string(argv[i]) == "-o" && i == argc - 1)
  86. {
  87. std::cerr << "\n[ERROR]: Output file name was not specified " << std::endl;
  88. return 1;
  89. }
  90. if (std::string(argv[i]) == "-input_format" && i != argc - 1)
  91. {
  92. qaUtility::GetInstance()->format = argv[++i];
  93. continue;
  94. }
  95. if (std::string(argv[i]) == "-input_format" && i == argc - 1)
  96. {
  97. std::cerr << "\n[ERROR]: Input file format was not specified " << std::endl;
  98. return 1;
  99. }
  100. if (std::string(argv[i]) == "-output_format" && i != argc - 1)
  101. {
  102. outputFormat = argv[++i];
  103. continue;
  104. }
  105. if (std::string(argv[i]) == "-output_format" && i == argc - 1)
  106. {
  107. std::cerr << "\n[ERROR]: Output file format was not specified " << std::endl;
  108. return 1;
  109. }
  110. }
  111. }
  112. TStopwatch timer;
  113. timer.Start();
  114. qaReader_manager *readerManager;
  115. if (qaUtility::GetInstance()->format == "mcpico")
  116. {
  117. readerManager = new qaReader_mcpico();
  118. }
  119. #ifdef _MCINI_
  120. if (qaUtility::GetInstance()->format == "mcini")
  121. {
  122. readerManager = new qaReader_mcini();
  123. }
  124. #endif
  125. #ifdef _PHQMD_
  126. if (qaUtility::GetInstance()->format == "phqmd")
  127. {
  128. readerManager = new qaReader_phqmd();
  129. }
  130. #endif
  131. #ifdef _HSD_ROOT_
  132. if (qaUtility::GetInstance()->format == "hsd")
  133. {
  134. readerManager = new qaReader_hsd_root();
  135. }
  136. #endif
  137. if (qaUtility::GetInstance()->format == "particles")
  138. {
  139. readerManager = new qaReader_smash_root();
  140. }
  141. if (!readerManager)
  142. {
  143. std::cerr << "This input format is not found!" << std::endl;
  144. return 20;
  145. }
  146. qaWriter_manager *writerManager;
  147. if (outputFormat == "analysistree_v2")
  148. {
  149. writerManager = new qaWriter_analysistree2();
  150. }
  151. if (!writerManager)
  152. {
  153. std::cerr << "This output format is not found!" << std::endl;
  154. return 30;
  155. }
  156. readerManager->SetChain(iFileName.Data());
  157. Long64_t Nentries = readerManager->GetEntries();
  158. Int_t Nparticles;
  159. qaEvent *event = nullptr;
  160. qaParticle *particle = nullptr;
  161. writerManager->Init(oFileName.Data(), "modelTree");
  162. for (Long64_t iev = 0; iev < Nentries; iev++)
  163. {
  164. if (iev % 1000 == 0)
  165. std::cout << "Event [" << Minbias_counter << "/" << Nentries << "]" << std::endl;
  166. event = (qaEvent *)readerManager->ReadEvent(iev);
  167. if (!event)
  168. continue;
  169. writerManager->WriteEvent(event);
  170. Nparticles = event->GetNparticles();
  171. for (int iparticle = 0; iparticle < Nparticles; iparticle++)
  172. {
  173. particle = readerManager->ReadParticle(iparticle);
  174. if (!particle)
  175. continue;
  176. writerManager->WriteParticle(particle);
  177. delete particle;
  178. }
  179. writerManager->FillTree();
  180. delete event;
  181. }
  182. writerManager->WriteTree();
  183. timer.Stop();
  184. timer.Print();
  185. return 0;
  186. }