From 4a42233e8871d0e17c8473b0d5cdf14260b9fd72 Mon Sep 17 00:00:00 2001 From: ybedfer Date: Thu, 21 Nov 2024 13:00:52 +0100 Subject: [PATCH] Bug fix in Segmentation's CylindricalGridPhiZ: phi range is now set to [-pi,pi] instead of [0,2pi] if phi IDdescriptor field is signed. --- DDCore/include/DDSegmentation/CylindricalGridPhiZ.h | 6 +++++- DDCore/src/segmentations/CylindricalGridPhiZ.cpp | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h b/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h index 54a836934..d81ce3702 100644 --- a/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h +++ b/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h @@ -104,6 +104,9 @@ namespace dd4hep { */ virtual std::vector cellDimensions(const CellID& cellID) const; + /// Set the underlying decoder (setting, inter alia, whether phi isSigned) + virtual void setDecoder(const BitFieldCoder* decoder); + protected: /// the grid size in phi double _gridSizePhi; @@ -119,7 +122,8 @@ namespace dd4hep { std::string _phiId; /// the field name used for Z std::string _zId; - /// encoding field used for the module + /// the isSigned attribute of the bitfield used for phi + bool _phiIsSigned; }; } /* namespace DDSegmentation */ diff --git a/DDCore/src/segmentations/CylindricalGridPhiZ.cpp b/DDCore/src/segmentations/CylindricalGridPhiZ.cpp index 36e731ff3..3945b57f0 100644 --- a/DDCore/src/segmentations/CylindricalGridPhiZ.cpp +++ b/DDCore/src/segmentations/CylindricalGridPhiZ.cpp @@ -62,6 +62,13 @@ CylindricalGridPhiZ::~CylindricalGridPhiZ() { } +/// Set the underlying decoder and assign isSigned attribute to phi identifier +void CylindricalGridPhiZ::setDecoder(const BitFieldCoder* newDecoder) { + this->Segmentation::setDecoder(newDecoder); + const BitFieldElement* m_phi = &((*_decoder)[_phiId]); + _phiIsSigned = m_phi->isSigned(); +} + /// determine the position based on the cell ID Vector3D CylindricalGridPhiZ::position(const CellID& cID) const { vector localPosition(3); @@ -80,7 +87,7 @@ Vector3D CylindricalGridPhiZ::position(const CellID& cID) const { CellID CylindricalGridPhiZ::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const { double phi = atan2(localPosition.Y,localPosition.X); double Z = localPosition.Z; - if ( phi < _offsetPhi) { + if (!_phiIsSigned && phi < _offsetPhi) { phi += 2*M_PI; } CellID cID = vID ;