File indexing completed on 2025-02-22 09:36:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <DDSegmentation/MegatileLayerGridXY.h>
0020 #include <DD4hep/Printout.h>
0021
0022 #undef NDEBUG
0023 #include <cmath>
0024 #include <cassert>
0025 #include <algorithm>
0026
0027 namespace dd4hep {
0028 namespace DDSegmentation {
0029
0030
0031 MegatileLayerGridXY::MegatileLayerGridXY(const std::string& cellEncoding) :
0032 CartesianGrid(cellEncoding)
0033 {
0034 setup();
0035 }
0036
0037 MegatileLayerGridXY::MegatileLayerGridXY(const BitFieldCoder* decode) :
0038 CartesianGrid(decode) {
0039 setup();
0040 }
0041
0042
0043 MegatileLayerGridXY::~MegatileLayerGridXY() {
0044
0045 }
0046
0047 void MegatileLayerGridXY::setup() {
0048
0049 _type = "MegatileLayerGridXY";
0050 _description = "Cartesian segmentation in the local XY-plane: megatiles, containing integer number of tiles/strips/cells";
0051
0052 registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "cellX");
0053 registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "cellY");
0054
0055 registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
0056 SegmentationParameter::NoUnit, true);
0057
0058 registerParameter("identifier_layer", "Cell encoding identifier for layer", _identifierLayer, std::string("layer"),
0059 SegmentationParameter::NoUnit, true);
0060
0061 registerParameter("identifier_module", "Cell encoding identifier for module", _identifierModule, std::string("module"),
0062 SegmentationParameter::NoUnit, true);
0063
0064 registerParameter("common_nCellsX", "ncells in x (uniform)", _unif_nCellsX, int(0), SegmentationParameter::NoUnit, true);
0065 registerParameter("common_nCellsY", "ncells in y (uniform)", _unif_nCellsY, int(0), SegmentationParameter::NoUnit, true);
0066
0067 _nCellsX.clear();
0068 _nCellsY.clear();
0069 }
0070
0071
0072
0073 Vector3D MegatileLayerGridXY::position(const CellID& cID) const {
0074
0075
0076 unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
0077 unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
0078 int cellIndexX = _decoder->get(cID,_xId);
0079 int cellIndexY = _decoder->get(cID,_yId);
0080
0081
0082 getSegInfo(layerIndex, waferIndex);
0083
0084 Vector3D cellPosition(0,0,0);
0085 cellPosition.X = ( cellIndexX + 0.5 ) * (_currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) + _currentSegInfo.megaTileOffsetX;
0086 cellPosition.Y = ( cellIndexY + 0.5 ) * (_currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) + _currentSegInfo.megaTileOffsetY;
0087
0088 if ( fabs( cellPosition.X )>10000e0 || fabs( cellPosition.Y )>10000e0 ) {
0089 printout(WARNING,"MegatileLayerGridXY", "crazy cell position: x: %f y: %f ", cellPosition.X, cellPosition.Y);
0090 printout(WARNING,"MegatileLayerGridXY", "layer, wafer, cellx,y indices: %d %d %d %d",
0091 layerIndex, waferIndex, cellIndexX, cellIndexY);
0092 assert(0 && "crazy cell position?");
0093 }
0094
0095 return cellPosition;
0096 }
0097
0098
0099
0100 CellID MegatileLayerGridXY::cellID(const Vector3D& localPosition,
0101 const Vector3D& ,
0102 const VolumeID& vID) const
0103 {
0104
0105
0106
0107 unsigned int layerIndex = _decoder->get(vID,_identifierLayer);
0108 unsigned int waferIndex = _decoder->get(vID,_identifierWafer);
0109
0110
0111 getSegInfo(layerIndex, waferIndex);
0112
0113 double localX = localPosition.X;
0114 double localY = localPosition.Y;
0115
0116
0117 localX -= _currentSegInfo.megaTileOffsetX;
0118 localY -= _currentSegInfo.megaTileOffsetY;
0119
0120
0121 int _cellIndexX = int ( localX / ( _currentSegInfo.megaTileSizeX / _currentSegInfo.nCellsX ) );
0122 int _cellIndexY = int ( localY / ( _currentSegInfo.megaTileSizeY / _currentSegInfo.nCellsY ) );
0123
0124 CellID cID = vID ;
0125 _decoder->set(cID,_xId,_cellIndexX);
0126 _decoder->set(cID,_yId,_cellIndexY);
0127
0128 return cID;
0129 }
0130
0131
0132 std::vector<double> MegatileLayerGridXY::cellDimensions(const CellID& cID) const {
0133 unsigned int layerIndex = _decoder->get(cID,_identifierLayer);
0134 unsigned int waferIndex = _decoder->get(cID,_identifierWafer);
0135 return cellDimensions(layerIndex, waferIndex);
0136 }
0137
0138 void MegatileLayerGridXY::setSpecialMegaTile( unsigned int layer, unsigned int tile,
0139 double sizex, double sizey,
0140 double offsetx, double offsety,
0141 unsigned int ncellsx, unsigned int ncellsy ) {
0142
0143 std::pair <int, int> tileid(layer, tile);
0144 segInfo sinf;
0145 sinf.megaTileSizeX = sizex;
0146 sinf.megaTileSizeY = sizey;
0147 sinf.megaTileOffsetX = offsetx;
0148 sinf.megaTileOffsetY = offsety;
0149 sinf.nCellsX = ncellsx;
0150 sinf.nCellsY = ncellsy;
0151 specialMegaTiles_layerWafer[tileid] = sinf;
0152 }
0153
0154
0155 void MegatileLayerGridXY::getSegInfo( unsigned int layerIndex, unsigned int waferIndex) const {
0156
0157 std::pair < unsigned int, unsigned int > tileid(layerIndex, waferIndex);
0158 if ( specialMegaTiles_layerWafer.find( tileid ) == specialMegaTiles_layerWafer.end() ) {
0159 _currentSegInfo.megaTileSizeX = _megaTileSizeX;
0160 _currentSegInfo.megaTileSizeY = _megaTileSizeY;
0161 _currentSegInfo.megaTileOffsetX = _megaTileOffsetX;
0162 _currentSegInfo.megaTileOffsetY = _megaTileOffsetY;
0163
0164 if ( _unif_nCellsX>0 && _unif_nCellsY>0 ) {
0165 _currentSegInfo.nCellsX = _unif_nCellsX;
0166 _currentSegInfo.nCellsY = _unif_nCellsY;
0167 } else {
0168 assert ( layerIndex<_nCellsX.size() && "MegatileLayerGridXY ERROR: too high layer index?" );
0169 _currentSegInfo.nCellsX = _nCellsX[layerIndex];
0170 _currentSegInfo.nCellsY = _nCellsY[layerIndex];
0171 }
0172
0173 } else {
0174 _currentSegInfo = specialMegaTiles_layerWafer.find( tileid )->second;
0175 }
0176 }
0177
0178 std::vector<double> MegatileLayerGridXY::cellDimensions(const unsigned int layerIndex, const unsigned int waferIndex) const {
0179
0180
0181 getSegInfo(layerIndex, waferIndex);
0182
0183 double xsize = _currentSegInfo.megaTileSizeX/_currentSegInfo.nCellsX;
0184 double ysize = _currentSegInfo.megaTileSizeY/_currentSegInfo.nCellsY;
0185
0186 #if __cplusplus >= 201103L
0187 return {xsize, ysize};
0188 #else
0189 std::vector<double> cellDims(2,0.0);
0190 cellDims[0] = xsize;
0191 cellDims[1] = ysize;
0192 return cellDims;
0193 #endif
0194 }
0195
0196
0197 }
0198 }