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