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/include/DDSegmentation/PolarGridRPhi2.h b/DDCore/include/DDSegmentation/PolarGridRPhi2.h index 0e859027c..57d53fa33 100644 --- a/DDCore/include/DDSegmentation/PolarGridRPhi2.h +++ b/DDCore/include/DDSegmentation/PolarGridRPhi2.h @@ -140,6 +140,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 boundaries in R std::vector _gridRValues; @@ -153,6 +156,8 @@ namespace dd4hep { std::string _rId; /// the field name used for Phi std::string _phiId; + /// 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..c17a45c0f 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 isPrimed 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 ; diff --git a/DDCore/src/segmentations/PolarGridRPhi2.cpp b/DDCore/src/segmentations/PolarGridRPhi2.cpp index b294315ae..744ce6b7e 100644 --- a/DDCore/src/segmentations/PolarGridRPhi2.cpp +++ b/DDCore/src/segmentations/PolarGridRPhi2.cpp @@ -55,6 +55,13 @@ PolarGridRPhi2::PolarGridRPhi2(const BitFieldCoder* decode) : /// destructor PolarGridRPhi2::~PolarGridRPhi2() { +} + + /// Set the underlying decoder and assign isPrimed attribute to Phi identifier +void PolarGridRPhi2::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 @@ -64,10 +71,6 @@ Vector3D PolarGridRPhi2::position(const CellID& cID) const { double R = binToPosition(rBin, _gridRValues, _offsetR); double phi = binToPosition(_decoder->get(cID,_phiId), _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5); - if ( phi < _offsetPhi) { - phi += 2*M_PI; - } - cellPosition.X = R * cos(phi); cellPosition.Y = R * sin(phi); @@ -85,7 +88,7 @@ Vector3D PolarGridRPhi2::position(const CellID& cID) const { CellID cID = vID ; _decoder->set(cID,_rId, rBin); - if ( phi < _offsetPhi) { + if (!_phiIsSigned && phi < _offsetPhi) { phi += 2*M_PI; } const int pBin = positionToBin(phi, _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5);