Skip to content

Commit

Permalink
Bug fix in Segmentation's CylindricalGridPhiZ: phi range
Browse files Browse the repository at this point in the history
    is now set to [-pi,pi] instead of [0,2pi] if phi IDdescriptor field is signed.
  • Loading branch information
ybedfer authored and andresailer committed Nov 21, 2024
1 parent 665f7c4 commit 4a42233
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion DDCore/include/DDSegmentation/CylindricalGridPhiZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ namespace dd4hep {
*/
virtual std::vector<double> 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;
Expand All @@ -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 */
Expand Down
9 changes: 8 additions & 1 deletion DDCore/src/segmentations/CylindricalGridPhiZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> localPosition(3);
Expand All @@ -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 ;
Expand Down

0 comments on commit 4a42233

Please sign in to comment.