Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 08:23:43

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //==========================================================================
0011 /*
0012  * WaferGridXY.cpp
0013  *
0014  *  Created on: April 19, 2016
0015  *      Author: S. Lu, DESY
0016  */
0017 
0018 #include <DDSegmentation/WaferGridXY.h>
0019 
0020 namespace dd4hep {
0021 namespace DDSegmentation {
0022 
0023 /// default constructor using an encoding string
0024 WaferGridXY::WaferGridXY(const std::string& cellEncoding) :
0025                 CartesianGrid(cellEncoding) {
0026         // define type and description
0027         _type = "WaferGridXY";
0028         _description = "Cartesian segmentation in the local XY-plane for both Normal wafer and Magic wafer(depending on the layer dimensions)";
0029 
0030         // register all necessary parameters
0031         registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
0032         registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
0033         registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
0034         registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
0035         registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
0036         registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
0037         registerParameter("identifier_groupMGWafer", "Cell encoding identifier for Magic Wafer group", _identifierMGWaferGroup, std::string("layer"),
0038                         SegmentationParameter::NoUnit, true);
0039         registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
0040                         SegmentationParameter::NoUnit, true);
0041 }
0042 
0043 /// Default constructor used by derived classes passing an existing decoder
0044 WaferGridXY::WaferGridXY(const BitFieldCoder* decode) :        CartesianGrid(decode) {
0045         // define type and description
0046         _type = "WaferGridXY";
0047         _description = "Cartesian segmentation in the local XY-plane for both Normal wafer and Magic wafer(depending on the layer dimensions)";
0048 
0049         // register all necessary parameters
0050         registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
0051         registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
0052         registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
0053         registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
0054         registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
0055         registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
0056         registerParameter("identifier_groupMGWafer", "Cell encoding identifier for Magic Wafer group", _identifierMGWaferGroup, std::string("layer"),
0057                         SegmentationParameter::NoUnit, true);
0058         registerParameter("identifier_wafer", "Cell encoding identifier for wafer", _identifierWafer, std::string("wafer"),
0059                         SegmentationParameter::NoUnit, true);
0060 }
0061 
0062 /// destructor
0063 WaferGridXY::~WaferGridXY() {
0064 
0065 }
0066 
0067 /// determine the position based on the cell ID
0068 Vector3D WaferGridXY::position(const CellID& cID) const {
0069         unsigned int _groupMGWaferIndex;
0070         unsigned int _waferIndex;
0071         Vector3D cellPosition;
0072 
0073         _groupMGWaferIndex = _decoder->get(cID,_identifierMGWaferGroup);
0074         _waferIndex = _decoder->get(cID,_identifierWafer);
0075 
0076         if ( _waferOffsetX[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetX[_groupMGWaferIndex][_waferIndex] < 0 )
0077           {
0078             cellPosition.X = binToPosition(_decoder->get(cID,_xId), _gridSizeX, _offsetX+_waferOffsetX[_groupMGWaferIndex][_waferIndex]);
0079           }
0080         else
0081           {
0082             cellPosition.X = binToPosition(_decoder->get(cID,_xId), _gridSizeX, _offsetX);
0083           }
0084 
0085         if ( _waferOffsetY[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetY[_groupMGWaferIndex][_waferIndex] < 0 )
0086           {
0087             cellPosition.Y = binToPosition(_decoder->get(cID,_yId), _gridSizeY, _offsetY+_waferOffsetY[_groupMGWaferIndex][_waferIndex]);
0088           }
0089         else
0090           {
0091             cellPosition.Y = binToPosition(_decoder->get(cID,_yId), _gridSizeY, _offsetY);
0092           }
0093 
0094         return cellPosition;
0095 }
0096 
0097 /// determine the cell ID based on the position
0098   CellID WaferGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
0099         unsigned int _groupMGWaferIndex;
0100         unsigned int _waferIndex;
0101 
0102         CellID cID = vID ;
0103 
0104         _groupMGWaferIndex = _decoder->get(cID,_identifierMGWaferGroup);
0105         _waferIndex = _decoder->get(cID,_identifierWafer);
0106 
0107         if ( _waferOffsetX[_groupMGWaferIndex][_waferIndex] > 0 || _waferOffsetX[_groupMGWaferIndex][_waferIndex] < 0 )
0108           {
0109             _decoder->set(cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX+_waferOffsetX[_groupMGWaferIndex][_waferIndex]));
0110           }
0111         else
0112           {
0113             _decoder->set(cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX));
0114           }
0115 
0116         if ( _waferOffsetY[_groupMGWaferIndex][_waferIndex] > 0 ||  _waferOffsetY[_groupMGWaferIndex][_waferIndex] < 0)
0117           {
0118             _decoder->set(cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY+_waferOffsetY[_groupMGWaferIndex][_waferIndex]));
0119           }
0120         else
0121           {
0122             _decoder->set(cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY));
0123           }
0124 
0125         return cID;
0126 }
0127 
0128 std::vector<double> WaferGridXY::cellDimensions(const CellID&) const {
0129   return {_gridSizeX, _gridSizeY};
0130 }
0131 
0132 } /* namespace DDSegmentation */
0133 } /* namespace dd4hep */