DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
CartesianGridXYStaggered.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  * CartesianGridXYStaggered.cpp
13  *
14  * Created on: Sept 15, 2023
15  * Author: Sebouh J. Paul, UCR
16  */
17 
19 
20 namespace dd4hep {
21 namespace DDSegmentation {
22 
25  : CartesianGrid(cellEncoding)
26 {
27  // define type and description
28  _type = "CartesianGridXYStaggered";
29  _description = "Cartesian segmentation in the local XY-plane, with options for staggering";
30 
31  // register all necessary parameters
32  registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
33  registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
34  registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
35  registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
36  registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)",
38  registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)",
40  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
41  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
42  registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger",
43  _staggerKeyword, (std::string)"layer", SegmentationParameter::NoUnit, true);
44 }
45 
48  CartesianGrid(decode)
49 {
50  // define type and description
51  _type = "CartesianGridXYStaggered";
52  _description = "Cartesian segmentation in the local XY-plane, with options for staggering";
53 
54  // register all necessary parameters
55  registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
56  registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
57  registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
58  registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
59  registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)",
61  registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)",
63  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
64  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
65  registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger",
66  _staggerKeyword, (std::string)"layer", SegmentationParameter::NoUnit, true);
67 }
68 
71 
72 }
73 
76  Vector3D cellPosition;
77  if (_staggerX || _staggerY){
78  int layer= _decoder->get(cID,_staggerKeyword);
79  cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX+_staggerX*_gridSizeX*(layer%2)/2.);
80  cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY+_staggerY*_gridSizeY*(layer%2)/2.);
81  } else {
82  cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX);
83  cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY);
84  }
85  return cellPosition;
86 }
87 
90  const Vector3D& /* globalPosition */,
91  const VolumeID& vID) const {
92  CellID cID = vID ;
93  if (_staggerX || _staggerY){
94  int layer= _decoder->get(cID,_staggerKeyword);
95  _decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX+_staggerX*_gridSizeX*(layer%2)/2) );
96  _decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY+_staggerY*_gridSizeY*(layer%2)/2) );
97  } else {
98  _decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX));
99  _decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY));
100  }
101  return cID ;
102 }
103 
104 std::vector<double> CartesianGridXYStaggered::cellDimensions(const CellID& /* cellID */) const {
105  return {_gridSizeX, _gridSizeY};
106 }
107 
108 } /* namespace DDSegmentation */
109 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::CartesianGridXYStaggered::_gridSizeY
double _gridSizeY
the grid size in Y
Definition: CartesianGridXYStaggered.h:131
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::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::CartesianGridXYStaggered::_staggerKeyword
std::string _staggerKeyword
the keyword used to determine which volumes to stagger
Definition: CartesianGridXYStaggered.h:141
dd4hep::DDSegmentation::BitFieldCoder::get
FieldID get(CellID bitfield, size_t idx) const
Definition: BitFieldCoder.h:165
dd4hep::DDSegmentation::CartesianGridXYStaggered::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: CartesianGridXYStaggered.cpp:89
dd4hep::DDSegmentation::CartesianGridXYStaggered::_yId
std::string _yId
the field name used for Y
Definition: CartesianGridXYStaggered.h:139
CartesianGridXYStaggered.h
dd4hep::DDSegmentation::CartesianGridXYStaggered::_gridSizeX
double _gridSizeX
the grid size in X
Definition: CartesianGridXYStaggered.h:125
dd4hep::DDSegmentation::CartesianGridXYStaggered::_staggerX
int _staggerX
staggering option in X. 0 = no staggering. 1 = stagger by _gridSizeX/2.0 in odd layers
Definition: CartesianGridXYStaggered.h:129
dd4hep::DDSegmentation::SegmentationParameter::NoUnit
@ NoUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::CartesianGridXYStaggered::_xId
std::string _xId
the field name used for X
Definition: CartesianGridXYStaggered.h:137
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::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::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::CartesianGridXYStaggered::_staggerY
int _staggerY
staggering option in Y. 0 = no staggering. 1 = stagger by _gridSizeY/2.0 in odd layers
Definition: CartesianGridXYStaggered.h:135
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::CartesianGridXYStaggered::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: CartesianGridXYStaggered.cpp:104
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::CartesianGridXYStaggered::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: CartesianGridXYStaggered.cpp:75
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::DDSegmentation::CartesianGridXYStaggered::~CartesianGridXYStaggered
virtual ~CartesianGridXYStaggered()
destructor
Definition: CartesianGridXYStaggered.cpp:70
dd4hep::DDSegmentation::CartesianGridXYStaggered::CartesianGridXYStaggered
CartesianGridXYStaggered(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: CartesianGridXYStaggered.cpp:24
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::CartesianGridXYStaggered::_offsetY
double _offsetY
the coordinate offset in Y
Definition: CartesianGridXYStaggered.h:133
dd4hep::DDSegmentation::CartesianGridXYStaggered::_offsetX
double _offsetX
the coordinate offset in X
Definition: CartesianGridXYStaggered.h:127
dd4hep::DDSegmentation::CartesianGrid
Segmentation base class describing cartesian grid segmentation.
Definition: CartesianGrid.h:28