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