DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ProjectiveCylinder.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  * ProjectiveCylinder.cpp
13  *
14  * Created on: Oct 31, 2013
15  * Author: Christian Grefe, CERN
16  */
17 
20 
21 #define _USE_MATH_DEFINES
22 #include <cmath>
23 
24 namespace dd4hep {
25 namespace DDSegmentation {
26 
27 using Util::thetaFromXYZ;
28 using Util::phiFromXYZ;
29 
31 ProjectiveCylinder::ProjectiveCylinder(const std::string& cellEncoding) :
32  CylindricalSegmentation(cellEncoding) {
33  // define type and description
34  _type = "ProjectiveCylinder";
35  _description = "Projective segmentation in the global coordinates";
36 
37  // register all necessary parameters
38  registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1);
39  registerParameter("phi_bins", "Number of bins phi", _phiBins, 1);
40  registerParameter("offset_theta", "Angular offset in theta", _offsetTheta, 0., SegmentationParameter::AngleUnit, true);
41  registerParameter("offset_phi", "Angular offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true);
42  registerIdentifier("identifier_theta", "Cell ID identifier for theta", _thetaID, "theta");
43  registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiID, "phi");
44 }
45 
46 
49  // define type and description
50  _type = "ProjectiveCylinder";
51  _description = "Projective segmentation in the global coordinates";
52 
53  // register all necessary parameters
54  registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1);
55  registerParameter("phi_bins", "Number of bins phi", _phiBins, 1);
56  registerParameter("offset_theta", "Angular offset in theta", _offsetTheta, 0., SegmentationParameter::AngleUnit, true);
57  registerParameter("offset_phi", "Angular offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true);
58  registerIdentifier("identifier_theta", "Cell ID identifier for theta", _thetaID, "theta");
59  registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiID, "phi");
60 }
61 
64 
65 }
66 
69  return Util::positionFromRThetaPhi(1.0, theta(cID), phi(cID));
70 }
71 
73 CellID ProjectiveCylinder::cellID(const Vector3D& /* localPosition */, const Vector3D& globalPosition, const VolumeID& vID) const {
74  CellID cID = vID ;
75  double lTheta = thetaFromXYZ(globalPosition);
76  double lPhi = phiFromXYZ(globalPosition);
77  _decoder->set(cID,_thetaID, positionToBin(lTheta, M_PI / (double) _thetaBins, _offsetTheta));
78  _decoder->set(cID,_phiID , positionToBin(lPhi, 2 * M_PI / (double) _phiBins, _offsetPhi));
79  return cID;
80 }
81 
83 double ProjectiveCylinder::theta(const CellID& cID) const {
84  CellID thetaIndex = _decoder->get(cID,_thetaID);
85  return M_PI * ((double) thetaIndex + 0.5) / (double) _thetaBins;
86 }
88 double ProjectiveCylinder::phi(const CellID& cID) const {
89  CellID phiIndex = _decoder->get(cID,_phiID);
90  return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
91 }
92 
93 
94 } /* namespace DDSegmentation */
95 } /* namespace dd4hep */
96 
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::ProjectiveCylinder::_offsetPhi
double _offsetPhi
the coordinate offset in phi
Definition: ProjectiveCylinder.h:102
dd4hep::DDSegmentation::Util::positionFromRThetaPhi
Vector3D positionFromRThetaPhi(double r, double theta, double phi)
Conversions from spherical to Cartesian coordinates ///.
Definition: SegmentationUtil.h:113
dd4hep::DDSegmentation::ProjectiveCylinder::_thetaID
std::string _thetaID
the field name used for theta
Definition: ProjectiveCylinder.h:104
dd4hep::DDSegmentation::ProjectiveCylinder::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: ProjectiveCylinder.cpp:73
SegmentationUtil.h
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:168
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
dd4hep::DDSegmentation::CylindricalSegmentation
Segmentation base class describing a cylindrical grid segmentation.
Definition: CylindricalSegmentation.h:30
M_PI
#define M_PI
Definition: Handle.h:33
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::ProjectiveCylinder::~ProjectiveCylinder
virtual ~ProjectiveCylinder()
destructor
Definition: ProjectiveCylinder.cpp:63
dd4hep::DDSegmentation::ProjectiveCylinder::ProjectiveCylinder
ProjectiveCylinder(const std::string &cellEncoding)
default constructor using an arbitrary type
Definition: ProjectiveCylinder.cpp:31
dd4hep::DDSegmentation::Util::thetaFromXYZ
double thetaFromXYZ(const Vector3D &position)
calculates the polar angle theta from Cartesian coordinates
Definition: SegmentationUtil.h:59
ProjectiveCylinder.h
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::Util::phiFromXYZ
double phiFromXYZ(const Vector3D &position)
calculates the azimuthal angle phi from Cartesian coordinates
Definition: SegmentationUtil.h:64
dd4hep::DDSegmentation::BitFieldCoder::set
void set(CellID &bitfield, size_t idx, FieldID value) const
Definition: BitFieldCoder.h:177
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
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::ProjectiveCylinder::_offsetTheta
double _offsetTheta
the coordinate offset in theta
Definition: ProjectiveCylinder.h:100
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
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::ProjectiveCylinder::_thetaBins
int _thetaBins
the number of bins in theta
Definition: ProjectiveCylinder.h:96
dd4hep::DDSegmentation::ProjectiveCylinder::phi
double phi(const CellID &cellID) const
determine the azimuthal angle phi based on the cell ID
Definition: ProjectiveCylinder.cpp:88
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::ProjectiveCylinder::theta
double theta(const CellID &cellID) const
determine the polar angle theta based on the cell ID
Definition: ProjectiveCylinder.cpp:83
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::ProjectiveCylinder::_phiBins
int _phiBins
the number of bins in phi
Definition: ProjectiveCylinder.h:98
dd4hep::DDSegmentation::ProjectiveCylinder::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: ProjectiveCylinder.cpp:68
dd4hep::DDSegmentation::ProjectiveCylinder::_phiID
std::string _phiID
the field name used for phi
Definition: ProjectiveCylinder.h:106