DD4hep  1.31.0
Detector Description Toolkit for High Energy Physics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
26 namespace dd4hep {
27  namespace DDSegmentation {
28 
30  MegatileLayerGridXY::MegatileLayerGridXY(const std::string& cellEncoding) :
31  CartesianGrid(cellEncoding)
32  {
33  setup();
34  }
35 
37  CartesianGrid(decode) {
38  setup();
39  }
40 
43 
44  }
45 
47  // define type and description
48  _type = "MegatileLayerGridXY";
49  _description = "Cartesian segmentation in the local XY-plane: megatiles, containing integer number of tiles/strips/cells";
50 
51  registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "cellX");
52  registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "cellY");
53 
54  registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
56 
57  registerParameter("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, std::string("layer"),
59 
60  registerParameter("identifier_module", "Cell encoding identifier for module", _identifierModule, std::string("module"),
62 
63  registerParameter("common_nCellsX", "ncells in x (uniform)", _unif_nCellsX, int(0), SegmentationParameter::NoUnit, true);
64  registerParameter("common_nCellsY", "ncells in y (uniform)", _unif_nCellsY, int(0), SegmentationParameter::NoUnit, true);
65 
66  _nCellsX.clear();
67  _nCellsY.clear();
68  }
69 
70 
73  // this is local position within the megatile
74 
75  unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
76  unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
77  int cellIndexX = _decoder->get(cID,_xId);
78  int cellIndexY = _decoder->get(cID,_yId);
79 
80  // segmentation info for this megatile ("wafer")
81  getSegInfo(layerIndex, waferIndex);
82 
83  Vector3D cellPosition(0,0,0);
84  cellPosition.X = ( cellIndexX + 0.5 ) * (_currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) + _currentSegInfo.megaTileOffsetX;
85  cellPosition.Y = ( cellIndexY + 0.5 ) * (_currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) + _currentSegInfo.megaTileOffsetY;
86 
87  if ( fabs( cellPosition.X )>10000e0 || fabs( cellPosition.Y )>10000e0 ) {
88  printout(WARNING,"MegatileLayerGridXY", "crazy cell position: x: %f y: %f ", cellPosition.X, cellPosition.Y);
89  printout(WARNING,"MegatileLayerGridXY", "layer, wafer, cellx,y indices: %d %d %d %d",
90  layerIndex, waferIndex, cellIndexX, cellIndexY);
91  assert(0 && "crazy cell position?");
92  }
93 
94  return cellPosition;
95  }
96 
97 
100  const Vector3D& /* globalPosition */,
101  const VolumeID& vID) const
102  {
103  // this is the local position within a megatile, local coordinates
104 
105  // get the layer, wafer, module indices from the volumeID
106  unsigned int layerIndex = _decoder->get(vID,_identifierLayer);
107  unsigned int waferIndex = _decoder->get(vID,_identifierWafer);
108 
109  // segmentation info for this megatile ("wafer")
110  getSegInfo(layerIndex, waferIndex);
111 
112  double localX = localPosition.X;
113  double localY = localPosition.Y;
114 
115  // correct for offset : move origin to corner of megatile
118 
119  // the cell index (counting from the corner)
120  int _cellIndexX = int ( localX / ( _currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) );
121  int _cellIndexY = int ( localY / ( _currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) );
122 
123  CellID cID = vID ;
124  _decoder->set(cID,_xId,_cellIndexX);
125  _decoder->set(cID,_yId,_cellIndexY);
126 
127  return cID;
128  }
129 
130 
131  std::vector<double> MegatileLayerGridXY::cellDimensions(const CellID& cID) const {
132  unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
133  unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
134  return cellDimensions(layerIndex, waferIndex);
135  }
136 
137  void MegatileLayerGridXY::setSpecialMegaTile( unsigned int layer, unsigned int tile,
138  double sizex, double sizey,
139  double offsetx, double offsety,
140  unsigned int ncellsx, unsigned int ncellsy ) {
141 
142  std::pair <int, int> tileid(layer, tile);
143  segInfo sinf;
144  sinf.megaTileSizeX = sizex;
145  sinf.megaTileSizeY = sizey;
146  sinf.megaTileOffsetX = offsetx;
147  sinf.megaTileOffsetY = offsety;
148  sinf.nCellsX = ncellsx;
149  sinf.nCellsY = ncellsy;
150  specialMegaTiles_layerWafer[tileid] = sinf;
151  }
152 
153 
154  void MegatileLayerGridXY::getSegInfo( unsigned int layerIndex, unsigned int waferIndex) const {
155 
156  std::pair < unsigned int, unsigned int > tileid(layerIndex, waferIndex);
157  if ( specialMegaTiles_layerWafer.find( tileid ) == specialMegaTiles_layerWafer.end() ) { // standard megatile
162 
163  if ( _unif_nCellsX>0 && _unif_nCellsY>0 ) {
166  } else {
167  assert ( layerIndex<_nCellsX.size() && "MegatileLayerGridXY ERROR: too high layer index?" );
168  _currentSegInfo.nCellsX = _nCellsX[layerIndex];
169  _currentSegInfo.nCellsY = _nCellsY[layerIndex];
170  }
171 
172  } else { // special megatile
173  _currentSegInfo = specialMegaTiles_layerWafer.find( tileid )->second;
174  }
175  }
176 
177  std::vector<double> MegatileLayerGridXY::cellDimensions(const unsigned int layerIndex, const unsigned int waferIndex) const {
178  // calculate the cell size for a given wafer in a given layer
179 
180  getSegInfo(layerIndex, waferIndex);
181 
184 
185  return {xsize, ysize};
186  }
187 
188 
189  } /* namespace DDSegmentation */
190 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:26
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:137
dd4hep::DDSegmentation::Segmentation::_decoder
const BitFieldCoder * _decoder
The cell ID encoder and decoder.
Definition: Segmentation.h:175
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:47
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:113
dd4hep::DDSegmentation::BitFieldCoder::get
FieldID get(CellID bitfield, size_t idx) const
Definition: BitFieldCoder.h:164
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:46
dd4hep::DDSegmentation::MegatileLayerGridXY::~MegatileLayerGridXY
virtual ~MegatileLayerGridXY()
destructor
Definition: MegatileLayerGridXY.cpp:42
dd4hep::DDSegmentation::MegatileLayerGridXY::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: MegatileLayerGridXY.cpp:72
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:30
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:99
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:145
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:70
dd4hep::DDSegmentation::BitFieldCoder::set
void set(CellID &bitfield, size_t idx, FieldID value) const
Definition: BitFieldCoder.h:176
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:25
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:169
dd4hep::DDSegmentation::MegatileLayerGridXY::segInfo::nCellsX
unsigned int nCellsX
Definition: MegatileLayerGridXY.h:123
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:70
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:131
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:154
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:167
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