From fb037516fe7d02ea8d470a13809d86f2bfa69657 Mon Sep 17 00:00:00 2001
From: Wouter Hulsbergen <wouter.hulsbergen@nikhef.nl>
Date: Thu, 27 Feb 2025 11:06:35 +0100
Subject: [PATCH] move function that computes global cluster position from
 VPMicroClustersToVPLightClustersConverter into VPMicroCluster such that it
 can also be used from the VP monitoring algs.

---
 Event/DigiEvent/CMakeLists.txt                |  1 +
 .../DigiEvent/include/Event/VPMicroCluster.h  | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/Event/DigiEvent/CMakeLists.txt b/Event/DigiEvent/CMakeLists.txt
index 6e4b9940a08..216e9a5a108 100644
--- a/Event/DigiEvent/CMakeLists.txt
+++ b/Event/DigiEvent/CMakeLists.txt
@@ -25,6 +25,7 @@ gaudi_add_library(DigiEvent
             LHCb::EventBase
             LHCb::LHCbMathLib
             LHCb::UTDetLib
+            LHCb::VPDetLib
 )
 
 gaudi_add_dictionary(DigiEventDict
diff --git a/Event/DigiEvent/include/Event/VPMicroCluster.h b/Event/DigiEvent/include/Event/VPMicroCluster.h
index 0f61d8762b9..5da5f646718 100644
--- a/Event/DigiEvent/include/Event/VPMicroCluster.h
+++ b/Event/DigiEvent/include/Event/VPMicroCluster.h
@@ -12,7 +12,9 @@
 
 // Include files
 #include "Detector/VP/VPChannelID.h"
+#include "GaudiKernel/Point3DTypes.h"
 #include "Kernel/VPConstants.h"
+#include "VPDet/DeVP.h"
 
 #include <cstdint>
 #include <ostream>
@@ -81,6 +83,24 @@ namespace LHCb {
                channelID() == other.channelID() );
     }
 
+    auto localPosition( const DeVP& devp ) const {
+      const float    fx      = m_fx / 255.;
+      const float    fy      = m_fy / 255.;
+      const uint32_t cx      = m_vpID.scol();
+      const float    local_x = devp.local_x( cx ) + fx * devp.x_pitch( cx );
+      const float    local_y = ( 0.5f + fy + to_unsigned( m_vpID.row() ) ) * devp.pixel_size();
+      return std::make_tuple( local_x, local_y );
+    }
+
+    auto globalPosition( const DeVP& devp ) const {
+      const auto [local_x, local_y] = localPosition( devp );
+      const auto& ltg               = devp.ltg( m_vpID.sensor() );
+      const float gx                = ( ltg[0] * local_x + ltg[1] * local_y + ltg[9] );
+      const float gy                = ( ltg[3] * local_x + ltg[4] * local_y + ltg[10] );
+      const float gz                = ( ltg[6] * local_x + ltg[7] * local_y + ltg[11] );
+      return Gaudi::XYZPointF{ gx, gy, gz };
+    }
+
   private:
     FracType              m_fx{ 0 }; ///< inter-pixel fraction in x coordinate
     FracType              m_fy{ 0 }; ///< inter-pixel fraction in y coordinate
-- 
GitLab