DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
CartesianGridXYZ.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  * CartesianGridXYZ.cpp
13  *
14  * Created on: Jun 28, 2013
15  * Author: Christian Grefe, CERN
16  */
17 
19 
20 namespace dd4hep {
21 namespace DDSegmentation {
22 
24 CartesianGridXYZ::CartesianGridXYZ(const std::string& cellEncoding) :
25  CartesianGridXY(cellEncoding) {
26  // define type and description
27  _type = "CartesianGridXYZ";
28  _description = "Cartesian segmentation in the local coordinates";
29 
30  // register all necessary parameters
31  registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit);
32  registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true);
33  registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z");
34 }
35 
38  CartesianGridXY(decode) {
39  // define type and description
40  _type = "CartesianGridXYZ";
41  _description = "Cartesian segmentation in the local coordinates";
42 
43  // register all necessary parameters
44  registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit);
45  registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true);
46  registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z");
47 }
48 
51 
52 }
53 
56  Vector3D cellPosition;
57  cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX);
58  cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY);
59  cellPosition.Z = binToPosition( _decoder->get(cID,_zId ), _gridSizeZ, _offsetZ);
60  return cellPosition;
61 }
62 
64  CellID CartesianGridXYZ::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
65  CellID cID = vID ;
66  _decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX) );
67  _decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY) );
68  _decoder->set( cID,_zId, positionToBin(localPosition.Z, _gridSizeZ, _offsetZ) );
69  return cID ;
70 }
71 
72 std::vector<double> CartesianGridXYZ::cellDimensions(const CellID&) const {
73 #if __cplusplus >= 201103L
74  return {_gridSizeX, _gridSizeY, _gridSizeZ};
75 #else
76  std::vector<double> cellDims(3,0.0);
77  cellDims[0] = _gridSizeX;
78  cellDims[1] = _gridSizeY;
79  cellDims[2] = _gridSizeZ;
80  return cellDims;
81 #endif
82 }
83 
84 
85 } /* namespace DDSegmentation */
86 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::CartesianGridXYZ::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: CartesianGridXYZ.cpp:55
dd4hep::DDSegmentation::CartesianGridXY::_offsetY
double _offsetY
the coordinate offset in Y
Definition: CartesianGridXY.h:107
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:168
dd4hep::DDSegmentation::CartesianGridXY
Segmentation base class describing cartesian grid segmentation in the X-Y plane.
Definition: CartesianGridXY.h:27
dd4hep::DDSegmentation::CartesianGridXY::_yId
std::string _yId
the field name used for Y
Definition: CartesianGridXY.h:111
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
dd4hep::DDSegmentation::CartesianGridXY::_gridSizeY
double _gridSizeY
the grid size in Y
Definition: CartesianGridXY.h:105
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::BitFieldCoder::get
FieldID get(CellID bitfield, size_t idx) const
Definition: BitFieldCoder.h:165
dd4hep::DDSegmentation::CartesianGridXYZ::CartesianGridXYZ
CartesianGridXYZ(const std::string &cellEncoding)
default constructor using an arbitrary type
Definition: CartesianGridXYZ.cpp:24
dd4hep::DDSegmentation::CartesianGridXY::_offsetX
double _offsetX
the coordinate offset in X
Definition: CartesianGridXY.h:103
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::CartesianGridXYZ::_offsetZ
double _offsetZ
the coordinate offset in Z
Definition: CartesianGridXYZ.h:80
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
CartesianGridXYZ.h
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::CartesianGridXYZ::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: CartesianGridXYZ.cpp:64
dd4hep::DDSegmentation::CartesianGridXYZ::_zId
std::string _zId
the field name used for Z
Definition: CartesianGridXYZ.h:82
dd4hep::DDSegmentation::CartesianGridXYZ::~CartesianGridXYZ
virtual ~CartesianGridXYZ()
destructor
Definition: CartesianGridXYZ.cpp:50
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::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::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::CartesianGridXY::_gridSizeX
double _gridSizeX
the grid size in X
Definition: CartesianGridXY.h:101
dd4hep::DDSegmentation::CartesianGridXY::_xId
std::string _xId
the field name used for X
Definition: CartesianGridXY.h:109
dd4hep::DDSegmentation::CartesianGridXYZ::_gridSizeZ
double _gridSizeZ
the grid size in Z
Definition: CartesianGridXYZ.h:78
dd4hep::DDSegmentation::CartesianGridXYZ::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,...
Definition: CartesianGridXYZ.cpp:72
dd4hep::DDSegmentation::Vector3D::Z
double Z
Definition: Segmentation.h:71