DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProjectiveCylinder.cpp
Go to the documentation of this file.
1 /*
2  * ProjectiveCylinder.cpp
3  *
4  * Created on: Oct 31, 2013
5  * Author: Christian Grefe, CERN
6  */
7 
10 
11 #define _USE_MATH_DEFINES
12 #include <cmath>
13 
14 namespace DD4hep {
15 namespace DDSegmentation {
16 
17 using Util::thetaFromXYZ;
18 using Util::phiFromXYZ;
19 
21 ProjectiveCylinder::ProjectiveCylinder(const std::string& cellEncoding) :
22  CylindricalSegmentation(cellEncoding) {
23  // define type and description
24  _type = "ProjectiveCylinder";
25  _description = "Projective segmentation in the global coordinates";
26 
27  // register all necessary parameters
28  registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1);
29  registerParameter("phi_bins", "Number of bins phi", _phiBins, 1);
30  registerParameter("offset_theta", "Angular offset in theta", _offsetTheta, 0., SegmentationParameter::AngleUnit, true);
31  registerParameter("offset_phi", "Angular offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true);
32  registerIdentifier("identifier_theta", "Cell ID identifier for theta", _thetaID, "theta");
33  registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiID, "phi");
34 }
35 
36 
39  // define type and description
40  _type = "ProjectiveCylinder";
41  _description = "Projective segmentation in the global coordinates";
42 
43  // register all necessary parameters
44  registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1);
45  registerParameter("phi_bins", "Number of bins phi", _phiBins, 1);
46  registerParameter("offset_theta", "Angular offset in theta", _offsetTheta, 0., SegmentationParameter::AngleUnit, true);
47  registerParameter("offset_phi", "Angular offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true);
48  registerIdentifier("identifier_theta", "Cell ID identifier for theta", _thetaID, "theta");
49  registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiID, "phi");
50 }
51 
54 
55 }
56 
59  _decoder->setValue(cID);
60  return Util::positionFromRThetaPhi(1.0, theta(), phi());
61 }
62 
64 CellID ProjectiveCylinder::cellID(const Vector3D& /* localPosition */, const Vector3D& globalPosition, const VolumeID& vID) const {
65  _decoder->setValue(vID);
66  double lTheta = thetaFromXYZ(globalPosition);
67  double lPhi = phiFromXYZ(globalPosition);
68  (*_decoder)[_thetaID] = positionToBin(lTheta, M_PI / (double) _thetaBins, _offsetTheta);
69  (*_decoder)[_phiID] = positionToBin(lPhi, 2 * M_PI / (double) _phiBins, _offsetPhi);
70  return _decoder->getValue();
71 }
72 
74 double ProjectiveCylinder::theta() const {
75  CellID thetaIndex = (*_decoder)[_thetaID].value();
76  return M_PI * ((double) thetaIndex + 0.5) / (double) _thetaBins;
77 }
79 double ProjectiveCylinder::phi() const {
80  CellID phiIndex = (*_decoder)[_phiID].value();
81  return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
82 }
83 
85 double ProjectiveCylinder::theta(const CellID& cID) const {
86  _decoder->setValue(cID);
87  CellID thetaIndex = (*_decoder)[_thetaID].value();
88  return M_PI * ((double) thetaIndex + 0.5) / (double) _thetaBins;
89 }
91 double ProjectiveCylinder::phi(const CellID& cID) const {
92  _decoder->setValue(cID);
93  CellID phiIndex = (*_decoder)[_phiID].value();
94  return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
95 }
96 
98 
99 } /* namespace DDSegmentation */
100 } /* namespace DD4hep */
long long int CellID
Useful typedefs to differentiate cell IDs and volume IDs.
Definition: Primitives.h:32
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...
std::string _phiID
the field name used for phi
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
#define M_PI
Definition: Handle.h:39
BitField64 * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:161
#define REGISTER_SEGMENTATION(classname)
Macro to instantiate a new SegmentationCreator by its type name.
Definition: Segmentation.h:170
int _phiBins
the number of bins in phi
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
double thetaFromXYZ(const Vector3D &position)
calculates the polar angle theta from Cartesian coordinates
int _thetaBins
the number of bins in theta
double phiFromXYZ(const Vector3D &position)
calculates the azimuthal angle phi from Cartesian coordinates
Simple container for a physics vector.
Definition: Segmentation.h:41
std::string _thetaID
the field name used for theta
std::string _description
The description of the segmentation.
Definition: Segmentation.h:155
static int positionToBin(double position, double cellSize, double offset=0.)
Helper method to convert a 1D position to a cell ID.
double theta() const
determine the polar angle theta based on the current cell ID
double phi() const
determine the azimuthal angle phi based on the current cell ID
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:131
std::string _type
The segmentation type.
Definition: Segmentation.h:153
long long int VolumeID
Definition: Primitives.h:35
ProjectiveCylinder(const std::string &cellEncoding)
default constructor using an arbitrary type
double _offsetTheta
the coordinate offset in theta
Vector3D positionFromRThetaPhi(double r, double theta, double phi)
Conversions from spherical to Cartesian coordinates ///.
double _offsetPhi
the coordinate offset in phi