From 44481679c7efec1df0787811602ed8dbb04c0594 Mon Sep 17 00:00:00 2001
From: Lukas Chlad <l.chlad@gsi.de>
Date: Fri, 22 Dec 2023 08:18:56 +0000
Subject: [PATCH] Fix FSD hit position

It was found that in ideal digitization and hit production the points position do not match hits position. This was caused by missing the rotation information in the previous FsdGeoHandler implementation. Now this issue is fixed using correction here
---
 core/detectors/fsd/CbmFsdGeoHandler.cxx | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/core/detectors/fsd/CbmFsdGeoHandler.cxx b/core/detectors/fsd/CbmFsdGeoHandler.cxx
index d1b311fbb0..1535e5e477 100644
--- a/core/detectors/fsd/CbmFsdGeoHandler.cxx
+++ b/core/detectors/fsd/CbmFsdGeoHandler.cxx
@@ -14,6 +14,7 @@
 #include <TGeoMatrix.h>   // for TGeoMatrix
 #include <TGeoNode.h>     // for TGeoIterator, TGeoNode
 #include <TGeoVolume.h>   // for TGeoVolume
+#include <TVector3.h>     // for TVector3
 #include <TVirtualMC.h>   // for TVirtualMC, gMC
 
 #include <string>   // for operator<, stoul
@@ -37,6 +38,7 @@ void CbmFsdGeoHandler::InitMaps()
   TGeoIterator geoIterator(gGeoManager->GetTopNode()->GetVolume());
 
   TGeoNode* curNode;
+  TGeoCombiTrans* unitToGlobalMatrix = nullptr;
   geoIterator.Reset();  // safety to reset to "cave" befor the loop starts
   while ((curNode = geoIterator())) {
     TString nodePath;
@@ -50,6 +52,9 @@ void CbmFsdGeoHandler::InitMaps()
     if (nodeName.Contains(fUnitStr)) {
       currentUnitId = curNode->GetNumber();
 
+      const TGeoMatrix* curUnitMatrix = geoIterator.GetCurrentMatrix();
+      unitToGlobalMatrix              = new TGeoCombiTrans(*(curUnitMatrix));
+
       CbmFsdUnitSpecs* unitSpecs = new CbmFsdUnitSpecs();
       unitSpecs->fUnitId         = currentUnitId;
       unitSpecs->fUnitName       = static_cast<TString>(curNode->GetVolume()->GetName());
@@ -58,8 +63,14 @@ void CbmFsdGeoHandler::InitMaps()
     }
     if (nodeName.Contains(fModuleStr)) {
       currentModuleId             = curNode->GetNumber();
-      const TGeoMatrix* curMatrix = geoIterator.GetCurrentMatrix();
-      const Double_t* curNodeTr   = curMatrix->GetTranslation();
+
+      TGeoMatrix* moduleToUnitMatrix = curNode->GetMatrix();
+      TVector3 localModuleCoord(moduleToUnitMatrix->GetTranslation());
+      TVector3 globalModuleCoord;
+      if (!unitToGlobalMatrix) {
+        LOG(fatal) << "No parent (unit) matrix initialized!!";
+      }
+      unitToGlobalMatrix->LocalToMaster(&localModuleCoord[0], &globalModuleCoord[0]);
 
       TGeoVolume* curScintillator = nullptr;
       for (int idn = 0; idn < curNode->GetNdaughters(); idn++) {
@@ -72,9 +83,9 @@ void CbmFsdGeoHandler::InitMaps()
       const TGeoBBox* shape = (const TGeoBBox*) (curScintillator->GetShape());
 
       CbmFsdModuleSpecs* moduleSpecs = new CbmFsdModuleSpecs();
-      moduleSpecs->fX                = curNodeTr[0];
-      moduleSpecs->fY                = curNodeTr[1];
-      moduleSpecs->fZ                = curNodeTr[2];
+      moduleSpecs->fX                = globalModuleCoord[0];
+      moduleSpecs->fY                = globalModuleCoord[1];
+      moduleSpecs->fZ                = globalModuleCoord[2];
       moduleSpecs->dX                = shape->GetDX();
       moduleSpecs->dY                = shape->GetDY();
       moduleSpecs->dZ                = shape->GetDZ();
-- 
GitLab