From b47c31838aaf9e1c625eac08222bccf0a345f531 Mon Sep 17 00:00:00 2001
From: P-A Loizeau <p.-a.loizeau@gsi.de>
Date: Mon, 8 Feb 2021 18:03:38 +0100
Subject: [PATCH] [mCBM 2020] try to unify defaults of sim macros + add
 MatchReco check

---
 macro/mcbm/.gitignore             |  4 ++
 macro/mcbm/data/.gitignore        |  1 +
 macro/mcbm/mcbm_digi.C            | 16 +++---
 macro/mcbm/mcbm_hadron_analysis.C |  4 +-
 macro/mcbm/mcbm_match_check.C     | 84 +++++++++++++++++++++++++++++++
 macro/mcbm/mcbm_reco_event.C      |  2 +-
 macro/mcbm/mcbm_transport.C       |  2 +-
 7 files changed, 101 insertions(+), 12 deletions(-)
 create mode 100644 macro/mcbm/.gitignore
 create mode 100644 macro/mcbm/mcbm_match_check.C

diff --git a/macro/mcbm/.gitignore b/macro/mcbm/.gitignore
new file mode 100644
index 0000000000..e1545030f1
--- /dev/null
+++ b/macro/mcbm/.gitignore
@@ -0,0 +1,4 @@
+all_*.par
+core_dump_*
+TRhistos.root
+gphysi.dat
diff --git a/macro/mcbm/data/.gitignore b/macro/mcbm/data/.gitignore
index e69de29bb2..4ea40f8315 100644
--- a/macro/mcbm/data/.gitignore
+++ b/macro/mcbm/data/.gitignore
@@ -0,0 +1 @@
+*.root
diff --git a/macro/mcbm/mcbm_digi.C b/macro/mcbm/mcbm_digi.C
index d166927b18..037bdf65a3 100644
--- a/macro/mcbm/mcbm_digi.C
+++ b/macro/mcbm/mcbm_digi.C
@@ -4,8 +4,8 @@
  ** data, which serves as input for reconstruction. Raw data will
  ** be delivered in time-slice format (one tree entry per time-slice).
  **
- ** The first five arguments to the macro call represent the minimal 
- ** information to be passed to the digitization run. In addition, 
+ ** The first five arguments to the macro call represent the minimal
+ ** information to be passed to the digitization run. In addition,
  ** the mode (time-based as default, or event-by-event) can be specified.
  ** By default, already existing output files will not be overwritten
  ** to prevent accidental data loss.
@@ -22,17 +22,17 @@
  **
  ** For further options to modify the run settings, consult
  ** the documentation of the CbmDigitization class.
- ** 
+ **
  ** @author Volker Friese <v.friese@gsi.de>
  ** @date 8 June 2018
  **/
 
 
-void mcbm_digi(Int_t nEvents            = 3,  // Number of events to process
-               TString dataSet          = "test",  // Data set for file names
-               Double_t eventRate       = 1.e7,    // Interaction rate [1/s]
-               Double_t timeSliceLength = 1.e4,    // Length of time-slice [ns]
-               Bool_t eventMode         = kTRUE    // Event-by-event mode
+void mcbm_digi(Int_t nEvents      = 3,            // Number of events to process
+               TString dataSet    = "data/test",  // Data set for file names
+               Double_t eventRate = 1.e7,         // Interaction rate [1/s]
+               Double_t timeSliceLength = 1.e4,   // Length of time-slice [ns]
+               Bool_t eventMode         = kTRUE   // Event-by-event mode
 ) {
 
   // --- Logger settings ----------------------------------------------------
diff --git a/macro/mcbm/mcbm_hadron_analysis.C b/macro/mcbm/mcbm_hadron_analysis.C
index 2e7335855c..4d8fa753e1 100644
--- a/macro/mcbm/mcbm_hadron_analysis.C
+++ b/macro/mcbm/mcbm_hadron_analysis.C
@@ -1,6 +1,6 @@
 void mcbm_hadron_analysis(Int_t nEvents      = 10,
-                          TString setup      = "mcbm_beam_2019_11",
-                          const char* output = "test") {
+                          TString setup      = "mcbm_beam_2020_03",
+                          const char* output = "data/test") {
   TString dataset(output);
   TString InputFile = dataset + ".tra.root";
   TString DigiFile  = dataset + ".event.raw.root";
diff --git a/macro/mcbm/mcbm_match_check.C b/macro/mcbm/mcbm_match_check.C
new file mode 100644
index 0000000000..17d2ed54c1
--- /dev/null
+++ b/macro/mcbm/mcbm_match_check.C
@@ -0,0 +1,84 @@
+void mcbm_match_check(Int_t nEvents      = 10,
+                      TString setup      = "mcbm_beam_2020_03",
+                      const char* output = "data/test") {
+  TString dataset(output);
+  TString InputFile = dataset + ".tra.root";
+  TString DigiFile  = dataset + ".event.raw.root";
+  TString RecoFile  = dataset + ".rec.root";
+  TString ParFile   = dataset + ".par.root";
+  TString OutFile   = dataset + ".match_check.root";
+
+  FairLogger::GetLogger()->SetLogScreenLevel("DEBUG");
+  FairLogger::GetLogger()->SetLogVerbosityLevel("HIGH");
+
+  // -----   Timer   --------------------------------------------------------
+  TStopwatch timer;
+  timer.Start();
+  // ------------------------------------------------------------------------
+
+  // -----   Reconstruction run   -------------------------------------------
+  FairFileSource* inputFiles = new FairFileSource(InputFile.Data());
+  inputFiles->AddFriend(DigiFile.Data());
+  inputFiles->AddFriend(RecoFile.Data());
+
+  FairRootFileSink* sink = new FairRootFileSink(OutFile.Data());
+
+  FairRunAna* fRun = new FairRunAna();
+  fRun->SetSource(inputFiles);
+  fRun->SetSink(sink);
+
+  // -----  Parameter database   --------------------------------------------
+  FairRuntimeDb* rtdb          = fRun->GetRuntimeDb();
+  FairParRootFileIo* parInput1 = new FairParRootFileIo();
+  parInput1->open(ParFile.Data());
+  rtdb->setFirstInput(parInput1);
+
+  CbmMCDataManager* mcManager = new CbmMCDataManager("MCDataManager", 1);
+  mcManager->AddFile(InputFile);
+  fRun->AddTask(mcManager);
+
+  CbmMatchRecoToMC* match = new CbmMatchRecoToMC();
+  fRun->AddTask(match);
+
+  // -----   Intialise and run   --------------------------------------------
+  fRun->Init();
+  cout << "Starting run" << endl;
+  fRun->Run(0, nEvents);
+  // ------------------------------------------------------------------------
+
+  // save histos to file
+  TFile* fHist = fRun->GetOutputFile();
+  fHist->Write();
+
+  // -----   Finish   -------------------------------------------------------
+  timer.Stop();
+  Double_t rtime = timer.RealTime();
+  Double_t ctime = timer.CpuTime();
+  std::cout << std::endl << std::endl;
+  std::cout << "Macro finished successfully." << std::endl;
+  std::cout << "Output file is " << OutFile << std::endl;
+  std::cout << "Parameter file is " << ParFile << std::endl;
+  std::cout << "Real time " << rtime << " s, CPU time " << ctime << "s"
+            << std::endl
+            << std::endl;
+  // ------------------------------------------------------------------------
+
+  // -----   Resource monitoring   ------------------------------------------
+  FairSystemInfo sysInfo;
+  Float_t maxMemory = sysInfo.GetMaxMemory();
+  std::cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
+  std::cout << maxMemory;
+  std::cout << "</DartMeasurement>" << std::endl;
+
+  Float_t cpuUsage = ctime / rtime;
+  std::cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
+  std::cout << cpuUsage;
+  std::cout << "</DartMeasurement>" << std::endl;
+
+
+  std::cout << " Test passed" << std::endl;
+  std::cout << " All ok " << std::endl;
+  // ------------------------------------------------------------------------
+
+  RemoveGeoManager();
+}
diff --git a/macro/mcbm/mcbm_reco_event.C b/macro/mcbm/mcbm_reco_event.C
index ef58d26f1b..22499e2ead 100644
--- a/macro/mcbm/mcbm_reco_event.C
+++ b/macro/mcbm/mcbm_reco_event.C
@@ -15,7 +15,7 @@
 
 void mcbm_reco_event(Int_t nEvents         = 3,
                      TString dataset       = "data/test",
-                     const char* setupName = "sis18_mcbm_25deg_long") {
+                     const char* setupName = "mcbm_beam_2020_03") {
   // ========================================================================
   //          Adjust this part according to your requirements
 
diff --git a/macro/mcbm/mcbm_transport.C b/macro/mcbm/mcbm_transport.C
index 7c2a731590..fcc3582967 100644
--- a/macro/mcbm/mcbm_transport.C
+++ b/macro/mcbm/mcbm_transport.C
@@ -20,7 +20,7 @@ void mcbm_transport(
   //                  const char* setupName = "mcbm_beam_2019_11",
   //                  const char* setupName = "mcbm_beam_2019_03",
   //                  const char* setupName = "sis18_mcbm_25deg_long",
-  const char* output    = "test",
+  const char* output    = "data/test",
   const char* inputFile = "") {
   // --- Define the beam angle ----------------------------------------------
   Double_t beamRotY = 25.;
-- 
GitLab