DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PolarGridRPhi2.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 /*
12  * PolarGridRPhi2.cpp
13  *
14  * Created on: March 17, 2015
15  * Author: Marko Petric, Andre Sailer
16  */
17 
19 
20 namespace dd4hep {
21 namespace DDSegmentation {
22 
24 PolarGridRPhi2::PolarGridRPhi2(const std::string& cellEncoding) :
25  PolarGrid(cellEncoding) {
26  // define type and description
27  _type = "PolarGridRPhi2";
28  _description = "Polar RPhi segmentation in the local XY-plane";
29 
30  // register all necessary parameters
31  registerParameter("grid_r_values", "Vector of R values", _gridRValues, std::vector<double>(), SegmentationParameter::LengthUnit, true);
32  registerParameter("grid_phi_values", "Cell size in Phi", _gridPhiValues, std::vector<double>(), SegmentationParameter::AngleUnit);
33  registerParameter("offset_r", "Cell offset in R", _offsetR, double(0.), SegmentationParameter::LengthUnit, true);
34  registerParameter("offset_phi", "Cell offset in Phi", _offsetPhi, double(0.), SegmentationParameter::AngleUnit, true);
35  registerIdentifier("identifier_r", "Cell ID identifier for R", _rId, "r");
36  registerIdentifier("identifier_phi", "Cell ID identifier for Phi", _phiId, "phi");
37 }
38 
41  PolarGrid(decode) {
42  // define type and description
43  _type = "PolarGridRPhi2";
44  _description = "Polar RPhi segmentation in the local XY-plane";
45 
46  // register all necessary parameters
47  registerParameter("grid_r_values", "Vector of R values", _gridRValues, std::vector<double>(), SegmentationParameter::LengthUnit, true);
48  registerParameter("grid_phi_values", "Cell size in Phi", _gridPhiValues, std::vector<double>(), SegmentationParameter::AngleUnit);
49  registerParameter("offset_r", "Cell offset in R", _offsetR, double(0.), SegmentationParameter::LengthUnit, true);
50  registerParameter("offset_phi", "Cell offset in Phi", _offsetPhi, double(0.), SegmentationParameter::AngleUnit, true);
51  registerIdentifier("identifier_r", "Cell ID identifier for R", _rId, "r");
52  registerIdentifier("identifier_phi", "Cell ID identifier for Phi", _phiId, "phi");
53 }
54 
57 
58 }
59 
62  Vector3D cellPosition;
63  const int rBin = _decoder->get(cID,_rId);
64  double R = binToPosition(rBin, _gridRValues, _offsetR);
65  double phi = binToPosition(_decoder->get(cID,_phiId), _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5);
66 
67  if ( phi < _offsetPhi) {
68  phi += 2*M_PI;
69  }
70 
71  cellPosition.X = R * cos(phi);
72  cellPosition.Y = R * sin(phi);
73 
74  return cellPosition;
75 }
76 
78  CellID PolarGridRPhi2::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
79 
80  double phi = atan2(localPosition.Y,localPosition.X);
81  double R = sqrt( localPosition.X * localPosition.X + localPosition.Y * localPosition.Y );
82 
83  const int rBin = positionToBin(R, _gridRValues, _offsetR);
84 
85  CellID cID = vID ;
86  _decoder->set(cID,_rId, rBin);
87 
88  if ( phi < _offsetPhi) {
89  phi += 2*M_PI;
90  }
91  const int pBin = positionToBin(phi, _gridPhiValues[rBin], _offsetPhi+_gridPhiValues[rBin]*0.5);
92  _decoder->set(cID,_phiId,pBin);
93 
94  return cID;
95 }
96 
97 
98 std::vector<double> PolarGridRPhi2::cellDimensions(const CellID& cID) const {
99 
100  const int rBin = _decoder->get(cID,_rId);
101  const double rCenter = binToPosition(rBin, _gridRValues, _offsetR);
102 
103  const double rPhiSize = _gridPhiValues[rBin]*rCenter;
104  const double rSize = _gridRValues[rBin+1]-_gridRValues[rBin];
105 
106 #if __cplusplus >= 201103L
107  return {rSize, rPhiSize};
108 #else
109  std::vector<double> cellDims(2,0.0);
110  cellDims[0] = rSize;
111  cellDims[1] = rPhiSize;
112  return cellDims;
113 #endif
114 }
115 
116 
117 } /* namespace DDSegmentation */
118 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:168
PolarGridRPhi2.h
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
M_PI
#define M_PI
Definition: Handle.h:33
dd4hep::DDSegmentation::SegmentationParameter::LengthUnit
@ LengthUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::DDSegmentation::SegmentationParameter::AngleUnit
@ AngleUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::BitFieldCoder::get
FieldID get(CellID bitfield, size_t idx) const
Definition: BitFieldCoder.h:165
dd4hep::DDSegmentation::PolarGridRPhi2::_rId
std::string _rId
the field name used for R
Definition: PolarGridRPhi2.h:153
dd4hep::DDSegmentation::PolarGridRPhi2::_offsetR
double _offsetR
the coordinate offset in R
Definition: PolarGridRPhi2.h:147
dd4hep::DDSegmentation::PolarGridRPhi2::~PolarGridRPhi2
virtual ~PolarGridRPhi2()
destructor
Definition: PolarGridRPhi2.cpp:56
dd4hep::DDSegmentation::Segmentation::registerParameter
void registerParameter(const std::string &nam, const std::string &desc, TYPE &param, const TYPE &defaultVal, UnitType unitTyp=SegmentationParameter::NoUnit, bool isOpt=false)
Add a parameter to this segmentation. Used by derived classes to define their parameters.
Definition: Segmentation.h:138
dd4hep::DDSegmentation::PolarGridRPhi2::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: PolarGridRPhi2.cpp:78
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:71
dd4hep::DDSegmentation::BitFieldCoder::set
void set(CellID &bitfield, size_t idx, FieldID value) const
Definition: BitFieldCoder.h:177
dd4hep::DDSegmentation::PolarGrid
Segmentation base class for polar grids.
Definition: PolarGrid.h:28
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::PolarGridRPhi2::PolarGridRPhi2
PolarGridRPhi2(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: PolarGridRPhi2.cpp:24
dd4hep::DDSegmentation::Segmentation::registerIdentifier
void registerIdentifier(const std::string &nam, const std::string &desc, std::string &ident, const std::string &defaultVal)
Add a cell identifier to this segmentation. Used by derived classes to define their required identifi...
Definition: Segmentation.cpp:135
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::PolarGridRPhi2::_offsetPhi
double _offsetPhi
the coordinate offset in Phi
Definition: PolarGridRPhi2.h:151
dd4hep::DDSegmentation::Segmentation::positionToBin
static int positionToBin(double position, double cellSize, double offset=0.)
Helper method to convert a 1D position to a cell ID.
Definition: Segmentation.cpp:150
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Segmentation::binToPosition
static double binToPosition(FieldID bin, double cellSize, double offset=0.)
Helper method to convert a bin number to a 1D position.
Definition: Segmentation.cpp:145
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::PolarGridRPhi2::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: PolarGridRPhi2.cpp:61
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::PolarGridRPhi2::cellDimensions
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions: d...
Definition: PolarGridRPhi2.cpp:98
dd4hep::DDSegmentation::PolarGridRPhi2::_phiId
std::string _phiId
the field name used for Phi
Definition: PolarGridRPhi2.h:155
dd4hep::DDSegmentation::PolarGridRPhi2::_gridPhiValues
std::vector< double > _gridPhiValues
the grid sizes in Phi
Definition: PolarGridRPhi2.h:149
dd4hep::DDSegmentation::PolarGridRPhi2::_gridRValues
std::vector< double > _gridRValues
the grid boundaries in R
Definition: PolarGridRPhi2.h:145