File indexing completed on 2025-02-22 09:36:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <DDSegmentation/PolarGridRPhi2.h>
0019
0020 namespace dd4hep {
0021 namespace DDSegmentation {
0022
0023
0024 PolarGridRPhi2::PolarGridRPhi2(const std::string& cellEncoding) :
0025 PolarGrid(cellEncoding) {
0026
0027 _type = "PolarGridRPhi2";
0028 _description = "Polar RPhi segmentation in the local XY-plane";
0029
0030
0031 registerParameter("grid_r_values", "Vector of R values", _gridRValues, std::vector<double>(), SegmentationParameter::LengthUnit, true);
0032 registerParameter("grid_phi_values", "Cell size in Phi", _gridPhiValues, std::vector<double>(), SegmentationParameter::AngleUnit);
0033 registerParameter("offset_r", "Cell offset in R", _offsetR, double(0.), SegmentationParameter::LengthUnit, true);
0034 registerParameter("offset_phi", "Cell offset in Phi", _offsetPhi, double(0.), SegmentationParameter::AngleUnit, true);
0035 registerIdentifier("identifier_r", "Cell ID identifier for R", _rId, "r");
0036 registerIdentifier("identifier_phi", "Cell ID identifier for Phi", _phiId, "phi");
0037 }
0038
0039
0040 PolarGridRPhi2::PolarGridRPhi2(const BitFieldCoder* decode) :
0041 PolarGrid(decode) {
0042
0043 _type = "PolarGridRPhi2";
0044 _description = "Polar RPhi segmentation in the local XY-plane";
0045
0046
0047 registerParameter("grid_r_values", "Vector of R values", _gridRValues, std::vector<double>(), SegmentationParameter::LengthUnit, true);
0048 registerParameter("grid_phi_values", "Cell size in Phi", _gridPhiValues, std::vector<double>(), SegmentationParameter::AngleUnit);
0049 registerParameter("offset_r", "Cell offset in R", _offsetR, double(0.), SegmentationParameter::LengthUnit, true);
0050 registerParameter("offset_phi", "Cell offset in Phi", _offsetPhi, double(0.), SegmentationParameter::AngleUnit, true);
0051 registerIdentifier("identifier_r", "Cell ID identifier for R", _rId, "r");
0052 registerIdentifier("identifier_phi", "Cell ID identifier for Phi", _phiId, "phi");
0053 }
0054
0055
0056 PolarGridRPhi2::~PolarGridRPhi2() {
0057
0058 }
0059
0060
0061 Vector3D PolarGridRPhi2::position(const CellID& cID) const {
0062 Vector3D cellPosition;
0063 const int rBin = _decoder->get(cID,_rId);
0064 double R = binToPosition(rBin, _gridRValues, _offsetR);
0065 double phi = binToPosition(_decoder->get(cID,_phiId), _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5);
0066
0067 if ( phi < _offsetPhi) {
0068 phi += 2*M_PI;
0069 }
0070
0071 cellPosition.X = R * cos(phi);
0072 cellPosition.Y = R * sin(phi);
0073
0074 return cellPosition;
0075 }
0076
0077
0078 CellID PolarGridRPhi2::cellID(const Vector3D& localPosition, const Vector3D& , const VolumeID& vID) const {
0079
0080 double phi = atan2(localPosition.Y,localPosition.X);
0081 double R = sqrt( localPosition.X * localPosition.X + localPosition.Y * localPosition.Y );
0082
0083 const int rBin = positionToBin(R, _gridRValues, _offsetR);
0084
0085 CellID cID = vID ;
0086 _decoder->set(cID,_rId, rBin);
0087
0088 if ( phi < _offsetPhi) {
0089 phi += 2*M_PI;
0090 }
0091 const int pBin = positionToBin(phi, _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5);
0092 _decoder->set(cID,_phiId,pBin);
0093
0094 return cID;
0095 }
0096
0097
0098 std::vector<double> PolarGridRPhi2::cellDimensions(const CellID& cID) const {
0099
0100 const int rBin = _decoder->get(cID,_rId);
0101 const double rCenter = binToPosition(rBin, _gridRValues, _offsetR);
0102
0103 const double rPhiSize = _gridPhiValues[rBin]*rCenter;
0104 const double rSize = _gridRValues[rBin+1]-_gridRValues[rBin];
0105
0106 #if __cplusplus >= 201103L
0107 return {rSize, rPhiSize};
0108 #else
0109 std::vector<double> cellDims(2,0.0);
0110 cellDims[0] = rSize;
0111 cellDims[1] = rPhiSize;
0112 return cellDims;
0113 #endif
0114 }
0115
0116
0117 }
0118 }