From 90c9f55821d991de5f90a716f62d3c60c0b682bd Mon Sep 17 00:00:00 2001
From: Vikas Singhal <vsinghal@gsi.de>
Date: Fri, 7 Jul 2023 18:13:06 +0530
Subject: [PATCH] For mMuCh Hit position correction according to tag value.

---
 reco/detectors/much/CbmMuchFindHitsGem.cxx | 46 ++++++++++++++++++----
 reco/detectors/much/CbmMuchFindHitsGem.h   |  9 +++++
 2 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/reco/detectors/much/CbmMuchFindHitsGem.cxx b/reco/detectors/much/CbmMuchFindHitsGem.cxx
index 9fdf3861ea..9c7027a66f 100644
--- a/reco/detectors/much/CbmMuchFindHitsGem.cxx
+++ b/reco/detectors/much/CbmMuchFindHitsGem.cxx
@@ -126,6 +126,32 @@ InitStatus CbmMuchFindHitsGem::Init()
   LOG_IF(fatal, !file) << "Could not open file " << fDigiFile;
   TObjArray* stations = file->Get<TObjArray>("stations");
   LOG_IF(fatal, !stations) << "TObjArray stations not found in file " << fDigiFile;
+
+  //For X, Y position correction according to different geometry file and its tag.
+
+  if (fDigiFile.Contains("mcbm")) {
+    if (fDigiFile.Contains("v19a")) {
+      fGemTX = 18.5;
+      fGemTY = 80.5;
+    }
+    else if (fDigiFile.Contains("v20a")) {
+      fGemTX = 18.5;
+      fGemTY = 80.0;
+    }
+    else if (fDigiFile.Contains("v22j")) {  // for high intensity runs during June 2022 mMuCh in acceptance
+      fGemTX = 8.0;
+      fGemTY = 81.5;
+      fRpcTX = 66.25;  //RPC introduced during 2022 data taking
+      fRpcTY = -70.5;
+    }
+    else if (fDigiFile.Contains("v22k")) {  // during benchmark runs. mMuCh is out of acceptance
+      fGemTX = -44.5;
+      fGemTY = 81.5;
+      fRpcTX = 48.0;
+      fRpcTY = -70.0;
+    }
+  }
+
   file->Close();
   file->Delete();
   /// Restore old global file and folder pointer to avoid messing with FairRoot
@@ -584,7 +610,8 @@ void CbmMuchFindHitsGem::ExecClusteringPeaks(CbmMuchCluster* cluster, Int_t iClu
 void CbmMuchFindHitsGem::CreateHits(CbmMuchCluster* cluster, Int_t iCluster, CbmEvent* event)
 {
   Int_t nDigis  = cluster->GetNofDigis();
-  Double_t sumq = 0, sumx = 0, sumy = 0, sumt = 0, sumdx2 = 0, sumdy2 = 0, sumdxy2 = 0, sumdt2 = 0;
+  Double_t sumq = 0, sumx = 0, sumy = 0, sumdx2 = 0, sumdy2 = 0, sumdxy2 = 0,
+           sumdt2 = 0;  // , sumt =0 // not used FU 22.03.23
   Double_t q = 0, x = 0, y = 0, t = 0, z = 0, dx = 0, dy = 0, dxy = 0, dt = 0;
   Double_t nX = 0, nY = 0, nZ = 0;
   Int_t address            = 0;
@@ -653,7 +680,7 @@ void CbmMuchFindHitsGem::CreateHits(CbmMuchCluster* cluster, Int_t iCluster, Cbm
     sumq += q;
     sumx += q * x;
     sumy += q * y;
-    sumt += q * t;
+    //sumt += q * t; // not used FU 22.03.23
     sumdx2 += q * q * dx * dx;
     sumdy2 += q * q * dy * dy;
     sumdxy2 += q * q * dxy * dxy;
@@ -677,20 +704,23 @@ void CbmMuchFindHitsGem::CreateHits(CbmMuchCluster* cluster, Int_t iCluster, Cbm
   //Double_t tX =18.5 , tY = 80.0 ;
   if (module->GetDetectorType() == 3)  // GEM
   {
-    tX = 8.5;
-    tY = 81.0;
+    tX = fGemTX;
+    tY = fGemTY;
   }
   else if (module->GetDetectorType() == 4)  // RPC
   {
-    tX = -66.5;
-    tY = 72.0;
+    tX = fRpcTX;
+    tY = fRpcTY;
+    //tX = -66.5;
+    //tY = 72.0;
   }
   else {
     LOG(error) << "Unknown detector type";
   }
 
-  nX = x + tX;  // Ajit + OS + Apar -> For miniMUCH setup in March 2019
-  nY = y + tY;  // Ajit + OS + Apar -> For miniMUCH setup in March 2019
+  nX = x + tX;  // for miniCBM setup set these according to the geometry
+                // tag and in line number 125 during initialization.
+  nY = y + tY;  //
   nZ = z;
 
   if (fFlag == 1) {
diff --git a/reco/detectors/much/CbmMuchFindHitsGem.h b/reco/detectors/much/CbmMuchFindHitsGem.h
index 2ef31f995e..18a6d7a69c 100644
--- a/reco/detectors/much/CbmMuchFindHitsGem.h
+++ b/reco/detectors/much/CbmMuchFindHitsGem.h
@@ -106,6 +106,15 @@ private:
   UInt_t fuClusters    = 0;       //Number of Clusters.
   Bool_t bBeamTimeDigi = kFALSE;  // Boolean for Using Beam Time Digi
 
+  //Below variables are applying X, Y correction for different mCBM geometries.
+  //In future we'll remove these and try to read directly from Geometry file.
+  // For GEM
+  Double_t fGemTX = 0.0;
+  Double_t fGemTY = 0.0;
+  // For RPC
+  Double_t fRpcTX = 0.0;
+  Double_t fRpcTY = 0.0;
+
   CbmMuchFindHitsGem(const CbmMuchFindHitsGem&);
   CbmMuchFindHitsGem operator=(const CbmMuchFindHitsGem&);
 
-- 
GitLab