From 04053e19fc3e38ea12c0622f1ed00ae770febe79 Mon Sep 17 00:00:00 2001
From: slebedev <s.lebedev@gsi.de>
Date: Fri, 18 Feb 2022 15:36:25 +0100
Subject: [PATCH] RICH: Automatically set Z position for extrapolation of STS
 tracks using geometry.

---
 macro/rich/geotest/run_one.py                 | 15 +++++++++------
 reco/detectors/rich/CbmRichReconstruction.cxx | 12 ++++++++++++
 reco/detectors/rich/CbmRichReconstruction.h   |  3 ++-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/macro/rich/geotest/run_one.py b/macro/rich/geotest/run_one.py
index 143ee7bb80..d829513834 100755
--- a/macro/rich/geotest/run_one.py
+++ b/macro/rich/geotest/run_one.py
@@ -16,9 +16,12 @@ def main():
   resultDir = "results_" + runId + "_"+ energy +"/" 
   
   #runId = "0"
-  geoSetup = "sis100_electron"
-  nEvents = 1000
-  testType = "urqmdTest" # urqmdTest or geoTest
+  geoSetup = "sis100_electron_APR21"
+  nEvents = 10
+  testType = "geoTest" # urqmdTest or geoTest
+
+  if testType == "geoTest":
+    urqmdFile = ""
 
   traFile = dataDir + "/tra." + runId + ".root"  
   parFile = dataDir + "/param." + runId + ".root"
@@ -32,9 +35,9 @@ def main():
   recoCmd = ('root -l -b -q run_reco.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{}\)').format(testType, traFile, parFile, digiFile, recoFile, geoSetup, nEvents)
   qaCmd = ('root -l -b -q run_qa.C\(\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",\\"{}\\",{}\)').format(testType, traFile, parFile, digiFile, recoFile, qaFile, geoSetup, resultDir, nEvents)
 
-  # os.system((". /{} -a; {}").format(cbmrootConfigPath, traCmd))
-  # os.system((". /{} -a; {}").format(cbmrootConfigPath, digiCmd))
-  # os.system((". /{} -a; {}").format(cbmrootConfigPath, recoCmd))
+  os.system((". /{} -a; {}").format(cbmrootConfigPath, traCmd))
+  os.system((". /{} -a; {}").format(cbmrootConfigPath, digiCmd))
+  os.system((". /{} -a; {}").format(cbmrootConfigPath, recoCmd))
   os.system((". /{} -a; {}").format(cbmrootConfigPath, qaCmd))
 
 # def make_args():
diff --git a/reco/detectors/rich/CbmRichReconstruction.cxx b/reco/detectors/rich/CbmRichReconstruction.cxx
index 6881b558e7..d13ed49aa1 100644
--- a/reco/detectors/rich/CbmRichReconstruction.cxx
+++ b/reco/detectors/rich/CbmRichReconstruction.cxx
@@ -30,6 +30,7 @@
 #include "CbmEvent.h"
 #include "CbmGlobalTrack.h"
 #include "CbmRichConverter.h"
+#include "CbmRichGeoManager.h"
 #include "CbmRichRingFitterCOP.h"
 #include "CbmRichRingFitterCircle.h"
 #include "CbmRichRingFitterEllipseMinuit.h"
@@ -92,6 +93,17 @@ InitStatus CbmRichReconstruction::Init()
   fRichRings = new TClonesArray("CbmRichRing", 100);
   manager->Register("RichRing", "RICH", fRichRings, IsOutputBranchPersistent("RichRing"));
 
+  // This was checked for v17a, v21a geometries. The offset was chosen that
+  // the value for v17a is 260 cm and the value for v21a is 220 cm
+  double offset        = 205.7331;
+  fZTrackExtrapolation = CbmRichGeoManager::GetInstance().fGP->fMirrorZ + offset;
+  LOG(info) << "CbmRichReconstruction::Init() fZTrackExtrapolation = " << fZTrackExtrapolation;
+  if (fZTrackExtrapolation < 200. || fZTrackExtrapolation > 300.) {
+    LOG(fatal) << "CbmRichReconstruction::Init() fZTrackExtrapolation = " << fZTrackExtrapolation
+               << " The value of fZTrackExtrapolation is not correct. It must be in the range [200, 300] cm."
+               << " Probably the RICH geometry is not correct or it is not supported.";
+  }
+
   if (fRunExtrapolation) InitExtrapolation();
   if (fRunProjection) InitProjection();
   if (fRunFinder) InitFinder();
diff --git a/reco/detectors/rich/CbmRichReconstruction.h b/reco/detectors/rich/CbmRichReconstruction.h
index 2882828821..d2b6626b7a 100644
--- a/reco/detectors/rich/CbmRichReconstruction.h
+++ b/reco/detectors/rich/CbmRichReconstruction.h
@@ -133,7 +133,8 @@ private:
   string fTrackAssignName   = "closest_distance";
 
   // Z coordinate where STS tracks will be extrapolated.
-  Double_t fZTrackExtrapolation = 260.;
+  // Initialized later using geometry.
+  Double_t fZTrackExtrapolation = -1;  //260.
 
   /**
     * \brief
-- 
GitLab