Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:36: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  * CartesianGridXYZ.cpp
0013  *
0014  *  Created on: Jun 28, 2013
0015  *      Author: Christian Grefe, CERN
0016  */
0017 
0018 #include <DDSegmentation/CartesianGridXYZ.h>
0019 
0020 namespace dd4hep {
0021 namespace DDSegmentation {
0022 
0023 /// default constructor using an encoding string
0024 CartesianGridXYZ::CartesianGridXYZ(const std::string& cellEncoding) :
0025         CartesianGridXY(cellEncoding) {
0026     // define type and description
0027     _type = "CartesianGridXYZ";
0028     _description = "Cartesian segmentation in the local coordinates";
0029 
0030     // register all necessary parameters
0031     registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit);
0032     registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true);
0033     registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z");
0034 }
0035 
0036 /// Default constructor used by derived classes passing an existing decoder
0037 CartesianGridXYZ::CartesianGridXYZ(const BitFieldCoder* decode) :
0038         CartesianGridXY(decode) {
0039     // define type and description
0040     _type = "CartesianGridXYZ";
0041     _description = "Cartesian segmentation in the local coordinates";
0042 
0043     // register all necessary parameters
0044     registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit);
0045     registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true);
0046     registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z");
0047 }
0048 
0049 /// destructor
0050 CartesianGridXYZ::~CartesianGridXYZ() {
0051 
0052 }
0053 
0054 /// determine the position based on the cell ID
0055 Vector3D CartesianGridXYZ::position(const CellID& cID) const {
0056     Vector3D cellPosition;
0057     cellPosition.X = binToPosition( _decoder->get(cID,_xId ), _gridSizeX, _offsetX);
0058     cellPosition.Y = binToPosition( _decoder->get(cID,_yId ), _gridSizeY, _offsetY);
0059     cellPosition.Z = binToPosition( _decoder->get(cID,_zId ), _gridSizeZ, _offsetZ);
0060     return cellPosition;
0061 }
0062 
0063 /// determine the cell ID based on the position
0064   CellID CartesianGridXYZ::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
0065         CellID cID = vID ;
0066     _decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX) );
0067     _decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY) );
0068     _decoder->set( cID,_zId, positionToBin(localPosition.Z, _gridSizeZ, _offsetZ) );
0069     return cID ;
0070 }
0071 
0072 std::vector<double> CartesianGridXYZ::cellDimensions(const CellID&) const {
0073 #if __cplusplus >= 201103L
0074   return {_gridSizeX, _gridSizeY, _gridSizeZ};
0075 #else
0076   std::vector<double> cellDims(3,0.0);
0077   cellDims[0] = _gridSizeX;
0078   cellDims[1] = _gridSizeY;
0079   cellDims[2] = _gridSizeZ;
0080   return cellDims;
0081 #endif
0082 }
0083 
0084 
0085 } /* namespace DDSegmentation */
0086 } /* namespace dd4hep */