From 60acfcb6af35341ec8a2c6f21c4d6d8e5ee919cc Mon Sep 17 00:00:00 2001
From: Martin Beyer <martin.beyer@physik.uni-giessen.de>
Date: Mon, 14 Apr 2025 08:07:16 +0000
Subject: [PATCH] Rich: Track projection fix using the CFV

(cherry picked from commit aee5a8b8de6d93f0740150af622242b18a9062a8)
(cherry-picked from MR 2082)
---
 core/detectors/rich/CbmRichGeoManager.cxx | 16 ++++++++++++----
 core/detectors/rich/CbmRichRecGeoPar.h    |  5 ++++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/core/detectors/rich/CbmRichGeoManager.cxx b/core/detectors/rich/CbmRichGeoManager.cxx
index 1a6ff4e630..5df5923360 100644
--- a/core/detectors/rich/CbmRichGeoManager.cxx
+++ b/core/detectors/rich/CbmRichGeoManager.cxx
@@ -200,14 +200,21 @@ void CbmRichGeoManager::InitPmtCyl()
     }
   }
 
-  for (map<string, CbmRichRecGeoParPmt>::iterator it = fGP->fPmtMap.begin(); it != fGP->fPmtMap.end(); it++) {
+  for (map<string, CbmRichRecGeoParPmt>::iterator it = fGP->fPmtMap.begin(); it != fGP->fPmtMap.end();) {
     it->second.fPlaneX = mapPmtPlaneMinMax[it->first].GetMeanX();
     it->second.fPlaneY = mapPmtPlaneMinMax[it->first].GetMeanY();
     it->second.fPlaneZ = mapPmtPlaneMinMax[it->first].GetMeanZ();
 
-    //        cout << "name:" << it->first << " strip(x,y,z):" <<it->second.fX << "," << it->second.fY << "," << it->second.fZ <<
-    //         " pmtPlane(x,y,z):" <<it->second.fPlaneX << "," << it->second.fPlaneY << "," << it->second.fPlaneZ << ", " <<
-    //         "theta:" << it->second.fTheta << ", phi:" << it->second.fPhi << endl;
+    //  LOG(info) << "name:" << it->first << " strip(x,y,z):" <<it->second.fX << "," << it->second.fY << "," << it->second.fZ <<
+    //   " pmtPlane(x,y,z):" <<it->second.fPlaneX << "," << it->second.fPlaneY << "," << it->second.fPlaneZ << ", " <<
+    //   "theta:" << it->second.fTheta << ", phi:" << it->second.fPhi;
+
+    if (!mapPmtPlaneMinMax[it->first].fPointAdded) {
+      it = fGP->fPmtMap.erase(it);
+    }
+    else {
+      ++it;
+    }
   }
 
   // Calculate gap between camera_strip
@@ -220,6 +227,7 @@ void CbmRichGeoManager::InitPmtCyl()
 
       geoIterator.GetPath(nodePath);
       string nodePathStr          = string(nodePath.Data()) + "/";
+      if (fGP->fPmtMap.find(nodePathStr) == fGP->fPmtMap.end()) continue;
       const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
       const Double_t* curNodeTr   = curMatrix->GetTranslation();
       //            const Double_t* curNodeRot = curMatrix->GetRotationMatrix();
diff --git a/core/detectors/rich/CbmRichRecGeoPar.h b/core/detectors/rich/CbmRichRecGeoPar.h
index c2ebab1a73..119adbce25 100644
--- a/core/detectors/rich/CbmRichRecGeoPar.h
+++ b/core/detectors/rich/CbmRichRecGeoPar.h
@@ -262,6 +262,7 @@ public:
     fMaxPmtY = TMath::Max(fMaxPmtY, y);
     fMinPmtZ = TMath::Min(fMinPmtZ, z);
     fMaxPmtZ = TMath::Max(fMaxPmtZ, z);
+    fPointAdded = true;
   }
 
   Double_t GetMeanX() { return (fMinPmtX + fMaxPmtX) / 2.; }
@@ -270,7 +271,9 @@ public:
 
   Double_t GetMeanZ() { return (fMinPmtZ + fMaxPmtZ) / 2.; }
 
-private:
+  bool fPointAdded{false};  // true if at least one point was added
+
+ private:
   Double_t fMinPmtX;
   Double_t fMaxPmtX;
   Double_t fMinPmtY;
-- 
GitLab