From 98f76ee87ddb6ceec1bf604e8be53059e6b65a96 Mon Sep 17 00:00:00 2001
From: P-A Loizeau <p.-a.loizeau@gsi.de>
Date: Tue, 25 Oct 2022 10:27:02 +0200
Subject: [PATCH] [mCBM] add setter for RICH ICD  base path + fix RICH par path
 in 2022 reco macro

---
 macro/beamtime/mcbm2022/mcbm_event_reco_L1.C       |  4 +++-
 reco/detectors/psd/CbmPsdMCbmHitProducer.cxx       | 10 +++++-----
 reco/detectors/rich/CbmRichReconstruction.cxx      |  6 +++---
 .../detectors/rich/mcbm/CbmRichMCbmHitProducer.cxx | 14 ++++++++------
 reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.h  |  7 +++++++
 5 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C b/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
index 367a2bdddf..3977aacb5f 100644
--- a/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
+++ b/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
@@ -479,7 +479,9 @@ Bool_t mcbm_event_reco_L1(UInt_t uRunId                   = 2391,
   if (bRICH && geoSetup->IsActive(ECbmModuleId::kRich)) {
     // -----   Local reconstruction of RICH Hits ------------------------------
     CbmRichMCbmHitProducer* hitProd = new CbmRichMCbmHitProducer();
-    hitProd->SetMappingFile("mRICH_Mapping_vert_20190318_elView.geo");
+    hitProd->SetMappingFile(std::string(srcDir.Data())
+                            + "/macro/rich/mcbm/beamtime/mRICH_Mapping_vert_20190318_elView.geo");
+    hitProd->SetIcdFilenameBase(std::string(srcDir.Data()) + "/macro/beamtime/mcbm2022/icd_offset_it");
     hitProd->setToTLimits(23.7, 30.0);
     hitProd->applyToTCut();
     hitProd->applyICDCorrection();
diff --git a/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx b/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx
index 9d2d823c82..8bf210be1a 100644
--- a/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx
+++ b/reco/detectors/psd/CbmPsdMCbmHitProducer.cxx
@@ -39,9 +39,9 @@ InitStatus CbmPsdMCbmHitProducer::Init()
   FairRootManager* manager = FairRootManager::Instance();
 
   fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
-  if (fCbmEvents == nullptr) { LOG(info) << ": CbmEvent NOT found \n \n \n"; }
+  if (fCbmEvents == nullptr) { LOG(info) << GetName() << "::Init() CbmEvent NOT found \n"; }
   else {
-    LOG(info) << ": CbmEvent found \n \n \n";
+    LOG(info) << GetName() << "::Init() CbmEvent found";
   }
 
   fDigiMan = CbmDigiManager::Instance();
@@ -67,7 +67,7 @@ void CbmPsdMCbmHitProducer::InitMapping() //TODO change for psd
     }
 
     fPsdMapping.clear();
-        
+
     while ( getline (file,line) ) {
 
         istringstream iss(line);
@@ -80,9 +80,9 @@ void CbmPsdMCbmHitProducer::InitMapping() //TODO change for psd
         data.fX = stod(results[6]);
         data.fY = stod(results[7]);
         data.fZ = 348.;
-        
+
         data.fX -= 6.3; //Shift by 1Pmt + PmtGap + 1cm
-        
+
         Int_t adr = ((data.fTrbId << 16) | (data.fChannel & 0x00FF));
 
        // cout <<  data.fTrbId << " " << data.fChannel << " " << data.fX << " " << data.fY << " " << adr << endl;
diff --git a/reco/detectors/rich/CbmRichReconstruction.cxx b/reco/detectors/rich/CbmRichReconstruction.cxx
index 0093410499..68d2e066fd 100644
--- a/reco/detectors/rich/CbmRichReconstruction.cxx
+++ b/reco/detectors/rich/CbmRichReconstruction.cxx
@@ -69,9 +69,9 @@ InitStatus CbmRichReconstruction::Init()
   if (nullptr == manager) LOG(fatal) << "CbmRichReconstruction::Init(): FairRootManager is nullptr.";
 
   fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
-  if (fCbmEvents == nullptr) { LOG(info) << ": CbmEvent NOT found \n \n \n"; }
+  if (fCbmEvents == nullptr) { LOG(info) << GetName() << "::Init() CbmEvent NOT found \n"; }
   else {
-    LOG(info) << ": CbmEvent found \n \n \n";
+    LOG(info) << GetName() << "::Init() CbmEvent found";
   }
 
   if (fRunExtrapolation) {
@@ -201,7 +201,7 @@ void CbmRichReconstruction::InitFinder()
      fRingFinder = new CbmL1RichENNRingFinder(0);
      }
      else if ((fFinderName == "enn_parallel")) {
-     
+
      fRingFinder = new CbmL1RichENNRingFinderParallel(0);
      } else if (fFinderName == "hough_prototype") {
      fRingFinder = new CbmRichProtRingFinderHough();
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.cxx
index 3c6d919f16..5f57e28118 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.cxx
@@ -47,9 +47,9 @@ InitStatus CbmRichMCbmHitProducer::Init()
   FairRootManager* manager = FairRootManager::Instance();
 
   fCbmEvents = dynamic_cast<TClonesArray*>(manager->GetObject("CbmEvent"));
-  if (fCbmEvents == nullptr) { LOG(info) << ": CbmEvent NOT found \n \n \n"; }
+  if (fCbmEvents == nullptr) { LOG(info) << GetName() << "::Init() CbmEvent NOT found \n"; }
   else {
-    LOG(info) << ": CbmEvent found \n \n \n";
+    LOG(info) << GetName() << "::Init() CbmEvent found";
   }
 
   fDigiMan = CbmDigiManager::Instance();
@@ -290,7 +290,9 @@ bool CbmRichMCbmHitProducer::RestrictToAerogelAccDec2019(Double_t x, Double_t y)
 void CbmRichMCbmHitProducer::read_ICD(std::array<Double_t, 2304>& ICD_offsets, unsigned int iteration)
 {
   std::string line;
-  std::ifstream icd_file(Form("icd_offset_it_%u.data", iteration));
+  std::string filename = ("" == fIcdFilenameBase ? "icd_offset_it" : fIcdFilenameBase);
+  filename += Form("_%u.data", iteration);
+  std::ifstream icd_file(filename);
   unsigned int lineCnt = 0;
   if (icd_file.is_open()) {
     while (getline(icd_file, line)) {
@@ -299,17 +301,17 @@ void CbmRichMCbmHitProducer::read_ICD(std::array<Double_t, 2304>& ICD_offsets, u
       unsigned int addr = 0;
       Double_t value;
       if (!(iss >> addr >> value)) {
-        LOG(info) << "A Problem accured in line " << lineCnt << "\n";
+        LOG(info) << "A Problem accured in line " << lineCnt;
         break;
       }  // error
       lineCnt++;
       ICD_offsets.at(addr) += value;
     }
     icd_file.close();
-    LOG(info) << "Loaded inter channel delay file icd_offset_it_" << iteration << ".data for RICH.\n";
+    LOG(info) << "Loaded inter channel delay file " << filename << " for RICH.";
   }
   else {
-    LOG(info) << "Unable to open inter channel delay file icd_offset_it_" << iteration << ".data\n";
+    LOG(info) << "Unable to open inter channel delay file " << filename;
   }
 }
 
diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.h b/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.h
index fa48567ff2..c51a7a98ac 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.h
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmHitProducer.h
@@ -76,6 +76,12 @@ public:
   void SetMappingFile(const std::string& mappingFile) { fMappingFile = mappingFile; }
 
 
+  /**
+     * Set ICD base-file path.
+     */
+  void SetIcdFilenameBase(const std::string& icdFileBase) { fIcdFilenameBase = icdFileBase; }
+
+
   /**
     * Set ToT Limits.
     */
@@ -143,6 +149,7 @@ private:
 
   std::string fMappingFile;
 
+  std::string fIcdFilenameBase = "";
   std::array<Double_t, 2304> fICD_offset_read;
 
   void InitMapping();
-- 
GitLab