From 75552e28a3021e6e5eddab55fc8c4ad197f3461c Mon Sep 17 00:00:00 2001
From: Jens Kroeger <kroeger@physi.uni-heidelberg.de>
Date: Mon, 9 Mar 2020 18:22:22 +0100
Subject: [PATCH] Detector: correct getRow/getColumn and getLocalPosition
 memeber functions

---
 src/core/detector/Detector.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/core/detector/Detector.cpp b/src/core/detector/Detector.cpp
index 41ff8ec96..e0213870a 100644
--- a/src/core/detector/Detector.cpp
+++ b/src/core/detector/Detector.cpp
@@ -385,13 +385,14 @@ bool Detector::hitMasked(Track* track, int tolerance) const {
 
 // Functions to get row and column from local position
 double Detector::getRow(const PositionVector3D<Cartesian3D<double>> localPosition) const {
-    // (1-m_nPixelsX%2)/2. --> add 1/2 pixel pitch if even number of rows
-    double row = localPosition.Y() / m_pitch.Y() + static_cast<double>(m_nPixels.Y()) / 2. + (1 - m_nPixels.Y() % 2) / 2.;
+
+    double row = localPosition.Y() / m_pitch.Y() + static_cast<double>(m_nPixels.Y() - 1) / 2.;
     return row;
 }
+
 double Detector::getColumn(const PositionVector3D<Cartesian3D<double>> localPosition) const {
-    // (1-m_nPixelsX%2)/2. --> add 1/2 pixel pitch if even number of columns
-    double column = localPosition.X() / m_pitch.X() + static_cast<double>(m_nPixels.X()) / 2. + (1 - m_nPixels.X() % 2) / 2.;
+
+    double column = localPosition.X() / m_pitch.X() + static_cast<double>(m_nPixels.X() - 1) / 2.;
     return column;
 }
 
@@ -399,7 +400,7 @@ double Detector::getColumn(const PositionVector3D<Cartesian3D<double>> localPosi
 PositionVector3D<Cartesian3D<double>> Detector::getLocalPosition(double column, double row) const {
 
     return PositionVector3D<Cartesian3D<double>>(
-        m_pitch.X() * (column - m_nPixels.X() / 2), m_pitch.Y() * (row - m_nPixels.Y() / 2), 0.);
+        m_pitch.X() * (column - (m_nPixels.X() - 1) / 2.), m_pitch.Y() * (row - (m_nPixels.Y() - 1) / 2.), 0.);
 }
 
 // Function to get in-pixel position
-- 
GitLab