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