DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
MegatileLayerGridXY.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  * MegatileLayerGridXY.cpp
13  *
14  * Created on: April 19, 2016
15  * Author: S. Lu, DESY
16  * D Jeans UTokyo
17  */
18 
20 #include <DD4hep/Printout.h>
21 
22 #undef NDEBUG
23 #include <cmath>
24 #include <cassert>
25 #include <algorithm>
26 
27 namespace dd4hep {
28  namespace DDSegmentation {
29 
31  MegatileLayerGridXY::MegatileLayerGridXY(const std::string& cellEncoding) :
32  CartesianGrid(cellEncoding)
33  {
34  setup();
35  }
36 
38  CartesianGrid(decode) {
39  setup();
40  }
41 
44 
45  }
46 
48  // define type and description
49  _type = "MegatileLayerGridXY";
50  _description = "Cartesian segmentation in the local XY-plane: megatiles, containing integer number of tiles/strips/cells";
51 
52  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "cellX");
53  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "cellY");
54 
55  registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
57 
58  registerParameter("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, std::string("layer"),
60 
61  registerParameter("identifier_module", "Cell encoding identifier for module", _identifierModule, std::string("module"),
63 
64  registerParameter("common_nCellsX", "ncells in x (uniform)", _unif_nCellsX, int(0), SegmentationParameter::NoUnit, true);
65  registerParameter("common_nCellsY", "ncells in y (uniform)", _unif_nCellsY, int(0), SegmentationParameter::NoUnit, true);
66 
67  _nCellsX.clear();
68  _nCellsY.clear();
69  }
70 
71 
74  // this is local position within the megatile
75 
76  unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
77  unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
78  int cellIndexX = _decoder->get(cID,_xId);
79  int cellIndexY = _decoder->get(cID,_yId);
80 
81  // segmentation info for this megatile ("wafer")
82  getSegInfo(layerIndex, waferIndex);
83 
84  Vector3D cellPosition(0,0,0);
85  cellPosition.X = ( cellIndexX + 0.5 ) * (_currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) + _currentSegInfo.megaTileOffsetX;
86  cellPosition.Y = ( cellIndexY + 0.5 ) * (_currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) + _currentSegInfo.megaTileOffsetY;
87 
88  if ( fabs( cellPosition.X )>10000e0 || fabs( cellPosition.Y )>10000e0 ) {
89  printout(WARNING,"MegatileLayerGridXY", "crazy cell position: x: %f y: %f ", cellPosition.X, cellPosition.Y);
90  printout(WARNING,"MegatileLayerGridXY", "layer, wafer, cellx,y indices: %d %d %d %d",
91  layerIndex, waferIndex, cellIndexX, cellIndexY);
92  assert(0 && "crazy cell position?");
93  }
94 
95  return cellPosition;
96  }
97 
98 
101  const Vector3D& /* globalPosition */,
102  const VolumeID& vID) const
103  {
104  // this is the local position within a megatile, local coordinates
105 
106  // get the layer, wafer, module indices from the volumeID
107  unsigned int layerIndex = _decoder->get(vID,_identifierLayer);
108  unsigned int waferIndex = _decoder->get(vID,_identifierWafer);
109 
110  // segmentation info for this megatile ("wafer")
111  getSegInfo(layerIndex, waferIndex);
112 
113  double localX = localPosition.X;
114  double localY = localPosition.Y;
115 
116  // correct for offset : move origin to corner of megatile
119 
120  // the cell index (counting from the corner)
121  int _cellIndexX = int ( localX / ( _currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) );
122  int _cellIndexY = int ( localY / ( _currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) );
123 
124  CellID cID = vID ;
125  _decoder->set(cID,_xId,_cellIndexX);
126  _decoder->set(cID,_yId,_cellIndexY);
127 
128  return cID;
129  }
130 
131 
132  std::vector<double> MegatileLayerGridXY::cellDimensions(const CellID& cID) const {
133  unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
134  unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
135  return cellDimensions(layerIndex, waferIndex);
136  }
137 
138  void MegatileLayerGridXY::setSpecialMegaTile( unsigned int layer, unsigned int tile,
139  double sizex, double sizey,
140  double offsetx, double offsety,
141  unsigned int ncellsx, unsigned int ncellsy ) {
142 
143  std::pair <int, int> tileid(layer, tile);
144  segInfo sinf;
145  sinf.megaTileSizeX = sizex;
146  sinf.megaTileSizeY = sizey;
147  sinf.megaTileOffsetX = offsetx;
148  sinf.megaTileOffsetY = offsety;
149  sinf.nCellsX = ncellsx;
150  sinf.nCellsY = ncellsy;
151  specialMegaTiles_layerWafer[tileid] = sinf;
152  }
153 
154 
155  void MegatileLayerGridXY::getSegInfo( unsigned int layerIndex, unsigned int waferIndex) const {
156 
157  std::pair < unsigned int, unsigned int > tileid(layerIndex, waferIndex);
158  if ( specialMegaTiles_layerWafer.find( tileid ) == specialMegaTiles_layerWafer.end() ) { // standard megatile
163 
164  if ( _unif_nCellsX>0 && _unif_nCellsY>0 ) {
167  } else {
168  assert ( layerIndex<_nCellsX.size() && "MegatileLayerGridXY ERROR: too high layer index?" );
169  _currentSegInfo.nCellsX = _nCellsX[layerIndex];
170  _currentSegInfo.nCellsY = _nCellsY[layerIndex];
171  }
172 
173  } else { // special megatile
174  _currentSegInfo = specialMegaTiles_layerWafer.find( tileid )->second;
175  }
176  }
177 
178  std::vector<double> MegatileLayerGridXY::cellDimensions(const unsigned int layerIndex, const unsigned int waferIndex) const {
179  // calculate the cell size for a given wafer in a given layer
180 
181  getSegInfo(layerIndex, waferIndex);
182 
185 
186 #if __cplusplus >= 201103L
187  return {xsize, ysize};
188 #else
189  std::vector<double> cellDims(2,0.0);
190  cellDims[0] = xsize;
191  cellDims[1] = ysize;
192  return cellDims;
193 #endif
194  }
195 
196 
197  } /* namespace DDSegmentation */
198 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::MegatileLayerGridXY::_megaTileSizeX
double _megaTileSizeX
Definition: MegatileLayerGridXY.h:140
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::megaTileOffsetX
double megaTileOffsetX
Definition: MegatileLayerGridXY.h:121
dd4hep::DDSegmentation::MegatileLayerGridXY::setSpecialMegaTile
void setSpecialMegaTile(unsigned int layer, unsigned int tile, double sizex, double sizey, double offsetx, double offsety, unsigned int ncellsx, unsigned int ncellsy)
Definition: MegatileLayerGridXY.cpp:138
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::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::MegatileLayerGridXY::_nCellsY
std::vector< int > _nCellsY
Definition: MegatileLayerGridXY.h:148
MegatileLayerGridXY.h
dd4hep::DDSegmentation::MegatileLayerGridXY::_identifierWafer
std::string _identifierWafer
encoding field used for the wafer
Definition: MegatileLayerGridXY.h:163
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::nCellsY
unsigned int nCellsY
Definition: MegatileLayerGridXY.h:124
dd4hep::DDSegmentation::MegatileLayerGridXY::setup
void setup()
Definition: MegatileLayerGridXY.cpp:47
dd4hep::DDSegmentation::MegatileLayerGridXY::~MegatileLayerGridXY
virtual ~MegatileLayerGridXY()
destructor
Definition: MegatileLayerGridXY.cpp:43
dd4hep::DDSegmentation::MegatileLayerGridXY::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: MegatileLayerGridXY.cpp:73
dd4hep::DDSegmentation::MegatileLayerGridXY::_identifierModule
std::string _identifierModule
Definition: MegatileLayerGridXY.h:167
dd4hep::DDSegmentation::MegatileLayerGridXY::_identifierLayer
std::string _identifierLayer
encoding field used for the layer
Definition: MegatileLayerGridXY.h:161
dd4hep::DDSegmentation::MegatileLayerGridXY::MegatileLayerGridXY
MegatileLayerGridXY(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: MegatileLayerGridXY.cpp:31
dd4hep::DDSegmentation::MegatileLayerGridXY::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: MegatileLayerGridXY.cpp:100
dd4hep::DDSegmentation::MegatileLayerGridXY::_unif_nCellsY
int _unif_nCellsY
Definition: MegatileLayerGridXY.h:151
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::megaTileSizeY
double megaTileSizeY
Definition: MegatileLayerGridXY.h:120
dd4hep::DDSegmentation::SegmentationParameter::NoUnit
@ NoUnit
Definition: SegmentationParameter.h:111
dd4hep::DDSegmentation::MegatileLayerGridXY::_unif_nCellsX
int _unif_nCellsX
Definition: MegatileLayerGridXY.h:150
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::megaTileSizeX
double megaTileSizeX
Definition: MegatileLayerGridXY.h:119
dd4hep::DDSegmentation::MegatileLayerGridXY::_megaTileSizeY
double _megaTileSizeY
Definition: MegatileLayerGridXY.h:141
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::MegatileLayerGridXY::_currentSegInfo
segInfo _currentSegInfo
Definition: MegatileLayerGridXY.h:131
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo
Helper structure.
Definition: MegatileLayerGridXY.h:118
dd4hep::DDSegmentation::MegatileLayerGridXY::_megaTileOffsetX
double _megaTileOffsetX
Definition: MegatileLayerGridXY.h:143
dd4hep::DDSegmentation::MegatileLayerGridXY::_xId
std::string _xId
the field name used for X
Definition: MegatileLayerGridXY.h:157
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::MegatileLayerGridXY::_megaTileOffsetY
double _megaTileOffsetY
Definition: MegatileLayerGridXY.h:144
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:162
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::nCellsX
unsigned int nCellsX
Definition: MegatileLayerGridXY.h:123
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:71
dd4hep::DDSegmentation::MegatileLayerGridXY::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: MegatileLayerGridXY.cpp:132
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::megaTileOffsetY
double megaTileOffsetY
Definition: MegatileLayerGridXY.h:122
dd4hep::DDSegmentation::MegatileLayerGridXY::getSegInfo
void getSegInfo(unsigned int layerIndex, unsigned int waferIndex) const
Definition: MegatileLayerGridXY.cpp:155
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::MegatileLayerGridXY::_nCellsX
std::vector< int > _nCellsX
Definition: MegatileLayerGridXY.h:147
dd4hep::DDSegmentation::MegatileLayerGridXY::_yId
std::string _yId
the field name used for Y
Definition: MegatileLayerGridXY.h:159
dd4hep::DDSegmentation::MegatileLayerGridXY::specialMegaTiles_layerWafer
std::map< std::pair< unsigned int, unsigned int >, segInfo > specialMegaTiles_layerWafer
Definition: MegatileLayerGridXY.h:153
Printout.h
dd4hep::DDSegmentation::CartesianGrid
Segmentation base class describing cartesian grid segmentation.
Definition: CartesianGrid.h:28