Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-06 07:51:49

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  * CylindricalGridPhiZ.cpp
0013  *
0014  *  Created on: Jun 28, 2024
0015  *      Author: Yann Bedfer, ePIC/Saclay
0016  */
0017 
0018 #include <DDSegmentation/CylindricalGridPhiZ.h>
0019 
0020 namespace dd4hep {
0021 namespace DDSegmentation {
0022 
0023 using std::make_pair;
0024 using std::vector;
0025 
0026 /// default constructor using an encoding string
0027 CylindricalGridPhiZ::CylindricalGridPhiZ(const std::string& cellEncoding) :
0028         CylindricalSegmentation(cellEncoding) {
0029         // define type and description
0030         _type = "CylindricalGridPhiZ";
0031         _description = "Cylindrical segmentation in the local PhiZ-cylinder";
0032 
0033         // register all necessary parameters
0034         registerParameter("grid_size_phi", "Cell size in phi", _gridSizePhi, 1., SegmentationParameter::AngleUnit);
0035         registerParameter("grid_size_z",   "Cell size in Z",   _gridSizeZ,   1., SegmentationParameter::LengthUnit);
0036         registerParameter("offset_phi", "Cell offset in phi", _offsetPhi,    0., SegmentationParameter::AngleUnit, true);
0037         registerParameter("offset_z",   "Cell offset in Z",   _offsetZ,      0., SegmentationParameter::LengthUnit, true);
0038         registerParameter("radius",     "Radius of Cylinder", _radius,       0., SegmentationParameter::LengthUnit);
0039         registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiId, "phi");
0040         registerIdentifier("identifier_z",   "Cell ID identifier for Z",   _zId,   "z");
0041 }
0042 
0043 /// Default constructor used by derived classes passing an existing decoder
0044 CylindricalGridPhiZ::CylindricalGridPhiZ(const BitFieldCoder* decode) :
0045         CylindricalSegmentation(decode) {
0046         // define type and description
0047         _type = "CylindricalGridPhiZ";
0048         _description = "Cylindrical segmentation in the local PhiZ-cylinder";
0049 
0050         // register all necessary parameters
0051         registerParameter("grid_size_phi", "Cell size in phi", _gridSizePhi, 1., SegmentationParameter::AngleUnit);
0052         registerParameter("grid_size_z",   "Cell size in Z",   _gridSizeZ,   1., SegmentationParameter::LengthUnit);
0053         registerParameter("offset_phi", "Cell offset in phi", _offsetPhi,    0., SegmentationParameter::AngleUnit, true);
0054         registerParameter("offset_z",   "Cell offset in Z",   _offsetZ,      0., SegmentationParameter::LengthUnit, true);
0055         registerParameter("radius",     "Radius of Cylinder", _radius,       0., SegmentationParameter::LengthUnit);
0056         registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiId, "phi");
0057         registerIdentifier("identifier_z",   "Cell ID identifier for Z",   _zId,   "z");
0058 }
0059 
0060 /// destructor
0061 CylindricalGridPhiZ::~CylindricalGridPhiZ() {
0062 
0063 }
0064 
0065 /// Set the underlying decoder and assign isSigned attribute to phi identifier
0066 void CylindricalGridPhiZ::setDecoder(const BitFieldCoder* newDecoder) {
0067   this->Segmentation::setDecoder(newDecoder);
0068   const BitFieldElement* m_phi = &((*_decoder)[_phiId]);
0069   _phiIsSigned = m_phi->isSigned();
0070 }
0071 
0072 /// determine the position based on the cell ID
0073 Vector3D CylindricalGridPhiZ::position(const CellID& cID) const {
0074         vector<double> localPosition(3);
0075         Vector3D cellPosition;
0076         double phi =
0077           binToPosition( _decoder->get(cID,_phiId ), _gridSizePhi, _offsetPhi);
0078         cellPosition.Z =
0079           binToPosition( _decoder->get(cID,_zId ),   _gridSizeZ,   _offsetZ);
0080         const double &R = _radius;
0081         cellPosition.X = R*cos(phi); cellPosition.Y = R*sin(phi);
0082 
0083         return cellPosition;
0084 }
0085 
0086 /// determine the cell ID based on the position
0087   CellID CylindricalGridPhiZ::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
0088         double phi = atan2(localPosition.Y,localPosition.X);
0089         double Z = localPosition.Z;
0090         if (!_phiIsSigned && phi < _offsetPhi) {
0091           phi += 2*M_PI;
0092         }
0093         CellID cID = vID ;
0094         _decoder->set( cID,_phiId, positionToBin(phi, _gridSizePhi, _offsetPhi) );
0095         _decoder->set( cID,_zId,   positionToBin(Z,   _gridSizeZ,   _offsetZ) );
0096 
0097         return cID ;
0098 }
0099 
0100 std::vector<double> CylindricalGridPhiZ::cellDimensions(const CellID&) const {
0101   return {_radius*_gridSizePhi, _gridSizeZ};
0102 }
0103 
0104 
0105 } /* namespace DDSegmentation */
0106 } /* namespace dd4hep */