Skip to content

Commit

Permalink
Bug fix in Segmentation's CylindricalGridPhiZ and PolarGridRPhi2: phi…
Browse files Browse the repository at this point in the history
… range

is now set to [-pi,pi] instead of [0,2pi] if phi IDdescriptor field is signed.
  • Loading branch information
ybedfer committed Nov 14, 2024
1 parent a39add6 commit 102ec1b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 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
5 changes: 5 additions & 0 deletions DDCore/include/DDSegmentation/PolarGridRPhi2.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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 boundaries in R
std::vector<double> _gridRValues;
Expand All @@ -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 */
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 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<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
13 changes: 8 additions & 5 deletions DDCore/src/segmentations/PolarGridRPhi2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 102ec1b

Please sign in to comment.