DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
TiledLayerGridXY.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  * TiledLayerGridXY.cpp
13  *
14  * Created on: November 12, 2015
15  * Author: Shaojun Lu, DESY
16  */
17 
19 #include <DD4hep/Printout.h>
20 
21 // C/C++ includes
22 #include <algorithm>
23 #include <sstream>
24 #include <stdexcept>
25 #include <cmath>
26 
27 namespace dd4hep {
28 namespace DDSegmentation {
29 
31 TiledLayerGridXY::TiledLayerGridXY(const std::string& cellEncoding) :
32  CartesianGrid(cellEncoding) {
33  // define type and description
34  _type = "TiledLayerGridXY";
35  _description = "Cartesian segmentation in the local XY-plane using optimal tiling depending on the layer dimensions";
36 
37  printout(INFO, "TiledLayerGridXY", " ######### dd4hep::DDSegmentation::TiledLayerGridXY() ");
38 
39  // register all necessary parameters
40  registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
41  registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
42  registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
43  registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
44  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
45  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
46  registerIdentifier("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, "layer");
47  registerParameter("layer_offsetX", "List of layer x offset", _layerOffsetX, std::vector<double>(),
49  registerParameter("layer_offsetY", "List of layer y offset", _layerOffsetY, std::vector<double>(),
51 }
52 
55  // define type and description
56  _type = "TiledLayerGridXY";
57  _description = "Cartesian segmentation in the local XY-plane using optimal tiling depending on the layer dimensions";
58 
59  printout(INFO, "TiledLayerGridXY", " ######### dd4hep::DDSegmentation::TiledLayerGridXY() ");
60 
61  // register all necessary parameters
62  registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
63  registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
64  registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
65  registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
66  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
67  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
68  registerIdentifier("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, "layer");
69  registerParameter("layer_offsetX", "List of layer x offset", _layerOffsetX, std::vector<double>(),
71  registerParameter("layer_offsetY", "List of layer y offset", _layerOffsetY, std::vector<double>(),
73 }
74 
77 
78 }
79 
82  unsigned int _layerIndex;
83  Vector3D cellPosition;
84 
85  // AHcal: _layerIndex is [1,48], _layerOffsetX is [0,47]
86  _layerIndex = _decoder->get(cID,_identifierLayer);
87 
88  if ( _layerOffsetX.size() != 0 && _layerIndex <=_layerOffsetX.size() ) {
89  cellPosition.X = binToPosition(_decoder->get(cID,_xId), _gridSizeX, _layerOffsetX[_layerIndex - 1]*_gridSizeX/2.);
90  // check the integer cell boundary in x,
91  if ( ( _layerDimX.size() != 0 && _layerIndex <= _layerDimX.size() )
92  &&( _fractCellSizeXPerLayer.size() != 0 && _layerIndex <= _fractCellSizeXPerLayer.size() )
93  &&(std::fabs( cellPosition.X ) > ( _layerDimX.at(_layerIndex - 1) - _fractCellSizeXPerLayer.at(_layerIndex - 1) ))
94  )
95  {
96  // and correct the fraction cell center position in x.
97  cellPosition.X = cellPosition.X/std::fabs(cellPosition.X)
98  *(_layerDimX.at(_layerIndex - 1) - _fractCellSizeXPerLayer.at(_layerIndex - 1)/2.0) ;
99  }
100  } else {
101  cellPosition.X = binToPosition(_decoder->get(cID,_xId), _gridSizeX, _offsetX);
102  }
103  cellPosition.Y = binToPosition(_decoder->get(cID,_yId), _gridSizeY, _offsetY);
104  return cellPosition;
105 }
106 
108  CellID TiledLayerGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
109  CellID cID = vID ;
110  unsigned int _layerIndex;
111 
112  // AHcal: _layerIndex is [1,48], _layerOffsetX is [0,47]
113  _layerIndex = _decoder->get(cID,_identifierLayer);
114 
115  if ( _layerOffsetX.size() != 0 && _layerIndex <=_layerOffsetX.size() ) {
116  _decoder->set(cID,_xId,positionToBin(localPosition.X, _gridSizeX, _layerOffsetX[_layerIndex - 1]*_gridSizeX/2.));
117  } else {
118  _decoder->set(cID,_xId,positionToBin(localPosition.X, _gridSizeX, _offsetX));
119  }
120  _decoder->set(cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY));
121  return cID;
122 }
123 
124 std::vector<double> TiledLayerGridXY::cellDimensions(const CellID&) const {
125 #if __cplusplus >= 201103L
126  return {_gridSizeX, _gridSizeY};
127 #else
128  std::vector<double> cellDims(2,0.0);
129  cellDims[0] = _gridSizeX;
130  cellDims[1] = _gridSizeY;
131  return cellDims;
132 #endif
133 }
134 
135 
136 } /* namespace DDSegmentation */
137 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::TiledLayerGridXY::_yId
std::string _yId
the field name used for Y
Definition: TiledLayerGridXY.h:158
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::TiledLayerGridXY::_offsetX
double _offsetX
the coordinate offset in X
Definition: TiledLayerGridXY.h:150
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::TiledLayerGridXY::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: TiledLayerGridXY.cpp:81
dd4hep::DDSegmentation::BitFieldCoder::get
FieldID get(CellID bitfield, size_t idx) const
Definition: BitFieldCoder.h:165
dd4hep::DDSegmentation::TiledLayerGridXY::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: TiledLayerGridXY.cpp:108
dd4hep::DDSegmentation::TiledLayerGridXY::_gridSizeX
double _gridSizeX
the grid size in X
Definition: TiledLayerGridXY.h:148
dd4hep::DDSegmentation::SegmentationParameter::NoUnit
@ NoUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::TiledLayerGridXY::_xId
std::string _xId
the field name used for X
Definition: TiledLayerGridXY.h:156
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::TiledLayerGridXY::TiledLayerGridXY
TiledLayerGridXY(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: TiledLayerGridXY.cpp:31
dd4hep::DDSegmentation::TiledLayerGridXY::_layerOffsetX
std::vector< double > _layerOffsetX
list of layer x offset
Definition: TiledLayerGridXY.h:162
dd4hep::DDSegmentation::TiledLayerGridXY::~TiledLayerGridXY
virtual ~TiledLayerGridXY()
destructor
Definition: TiledLayerGridXY.cpp:76
dd4hep::DDSegmentation::TiledLayerGridXY::_layerOffsetY
std::vector< double > _layerOffsetY
list of layer y offset
Definition: TiledLayerGridXY.h:164
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:71
dd4hep::DDSegmentation::TiledLayerGridXY::_identifierLayer
std::string _identifierLayer
encoding field used for the layer
Definition: TiledLayerGridXY.h:160
dd4hep::DDSegmentation::BitFieldCoder::set
void set(CellID &bitfield, size_t idx, FieldID value) const
Definition: BitFieldCoder.h:177
TiledLayerGridXY.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::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::TiledLayerGridXY::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: TiledLayerGridXY.cpp:124
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::TiledLayerGridXY::_offsetY
double _offsetY
the coordinate offset in Y
Definition: TiledLayerGridXY.h:154
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:160
dd4hep::DDSegmentation::TiledLayerGridXY::_fractCellSizeXPerLayer
std::vector< double > _fractCellSizeXPerLayer
list of the layer fraction cell size for X
Definition: TiledLayerGridXY.h:168
Printout.h
dd4hep::DDSegmentation::TiledLayerGridXY::_layerDimX
std::vector< double > _layerDimX
list of layer boundary dimension for X
Definition: TiledLayerGridXY.h:166
dd4hep::DDSegmentation::TiledLayerGridXY::_gridSizeY
double _gridSizeY
the grid size in Y
Definition: TiledLayerGridXY.h:152
dd4hep::DDSegmentation::CartesianGrid
Segmentation base class describing cartesian grid segmentation.
Definition: CartesianGrid.h:28