Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:36:48

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  * CartesianGridXY.cpp
0013  *
0014  *  Created on: Jun 28, 2013
0015  *      Author: Christian Grefe, CERN
0016  */
0017 
0018 #include <DDSegmentation/CartesianGridXY.h>
0019 
0020 namespace dd4hep {
0021 namespace DDSegmentation {
0022 
0023 /// default constructor using an encoding string
0024 CartesianGridXY::CartesianGridXY(const std::string& cellEncoding) :
0025         CartesianGrid(cellEncoding) {
0026     // define type and description
0027     _type = "CartesianGridXY";
0028     _description = "Cartesian segmentation in the local XY-plane";
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 }
0038 
0039 /// Default constructor used by derived classes passing an existing decoder
0040 CartesianGridXY::CartesianGridXY(const BitFieldCoder* decode) :
0041         CartesianGrid(decode)
0042 {
0043     // define type and description
0044     _type = "CartesianGridXY";
0045     _description = "Cartesian segmentation in the local XY-plane";
0046 
0047     // register all necessary parameters
0048     registerParameter("grid_size_x", "Cell size in X",   _gridSizeX, 1., SegmentationParameter::LengthUnit);
0049     registerParameter("grid_size_y", "Cell size in Y",   _gridSizeY, 1., SegmentationParameter::LengthUnit);
0050     registerParameter("offset_x",    "Cell offset in X", _offsetX,   0., SegmentationParameter::LengthUnit, true);
0051     registerParameter("offset_y",    "Cell offset in Y", _offsetY,   0., SegmentationParameter::LengthUnit, true);
0052     registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
0053     registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
0054 }
0055 
0056 /// destructor
0057 CartesianGridXY::~CartesianGridXY() {
0058 
0059 }
0060 
0061 /// determine the position based on the cell ID
0062 Vector3D CartesianGridXY::position(const CellID& cID) const {
0063     Vector3D cellPosition;
0064     cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX);
0065     cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY);
0066     return cellPosition;
0067 }
0068 
0069 /// determine the cell ID based on the position
0070 CellID CartesianGridXY::cellID(const Vector3D& localPosition,
0071                                const Vector3D& /* globalPosition */,
0072                                const VolumeID& vID) const {
0073   CellID cID = vID;
0074     _decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX) );
0075     _decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY) );
0076     return cID;
0077 }
0078 
0079   std::vector<double> CartesianGridXY::cellDimensions(const CellID& /* cellID */) const {
0080 #if __cplusplus >= 201103L
0081   return {_gridSizeX, _gridSizeY};
0082 #else
0083   std::vector<double> cellDims(2,0.0);
0084   cellDims[0] = _gridSizeX;
0085   cellDims[1] = _gridSizeY;
0086   return cellDims;
0087 #endif
0088 }
0089 
0090 
0091 } /* namespace DDSegmentation */
0092 } /* namespace dd4hep */
0093 
0094 // This is done DDCore/src/plugins/ReadoutSegmentations.cpp so the plugin is not part of libDDCore
0095 // needs also #include <DD4hep/Factories.h>
0096 // DECLARE_SEGMENTATION(CartesianGridXY,dd4hep::create_segmentation<dd4hep::DDSegmentation::CartesianGridXY>)