From 9c5fb7419140d1db7302353c62bfeb78d5dca1f5 Mon Sep 17 00:00:00 2001 From: ybedfer Date: Thu, 11 Jul 2024 13:07:23 +0200 Subject: [PATCH] Adding CylindricalGridPhiZ files and modifying Segmentation header, plugin and dictionary accordingly. --- DDCore/include/DD4hep/CartesianGridXYZ.h | 2 +- DDCore/include/DD4hep/CylindricalGridPhiZ.h | 111 +++++++++++++++ .../DDSegmentation/CylindricalGridPhiZ.h | 127 ++++++++++++++++++ .../DDSegmentation/CylindricalSegmentation.h | 6 +- DDCore/src/CylindricalGridPhiZ.cpp | 94 +++++++++++++ DDCore/src/SegmentationDictionary.h | 2 + DDCore/src/Segmentations.cpp | 3 + DDCore/src/plugins/ReadoutSegmentations.cpp | 3 + .../src/segmentations/CylindricalGridPhiZ.cpp | 106 +++++++++++++++ 9 files changed, 450 insertions(+), 4 deletions(-) create mode 100644 DDCore/include/DD4hep/CylindricalGridPhiZ.h create mode 100644 DDCore/include/DDSegmentation/CylindricalGridPhiZ.h create mode 100644 DDCore/src/CylindricalGridPhiZ.cpp create mode 100644 DDCore/src/segmentations/CylindricalGridPhiZ.cpp diff --git a/DDCore/include/DD4hep/CartesianGridXYZ.h b/DDCore/include/DD4hep/CartesianGridXYZ.h index f4cec8dd0..ad8952660 100644 --- a/DDCore/include/DD4hep/CartesianGridXYZ.h +++ b/DDCore/include/DD4hep/CartesianGridXYZ.h @@ -105,7 +105,7 @@ namespace dd4hep { Returns a vector of the cellDimensions of the given cell ID \param cellID is ignored as all cells have the same dimension - \return std::vector size 2: + \return std::vector size 3: -# size in x -# size in y -# size in z diff --git a/DDCore/include/DD4hep/CylindricalGridPhiZ.h b/DDCore/include/DD4hep/CylindricalGridPhiZ.h new file mode 100644 index 000000000..c6fb386c8 --- /dev/null +++ b/DDCore/include/DD4hep/CylindricalGridPhiZ.h @@ -0,0 +1,111 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// \author Markus Frank +// \date 2016-10-18 +// \version 1.0 +// +//========================================================================== +#ifndef DD4HEP_CYLINDRICALGRIDPHIZ_H +#define DD4HEP_CYLINDRICALGRIDPHIZ_H 1 + +// Framework include files +#include + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for base segmentations + namespace DDSegmentation { class CylindricalGridPhiZ; } + + /// We need some abbreviation to make the code more readable. + typedef Handle > CylindricalGridPhiZHandle; + + /// Implementation class for the grid PhiZ segmentation. + /** + * Concrete user handle to serve specific needs of client code + * which requires access to the base functionality not served + * by the super-class Segmentation. + * + * Note: + * We only check the validity of the underlying handle. + * If for whatever reason the implementation object is not valid + * This is not checked. + * In principle this CANNOT happen unless some brain-dead has + * fiddled with the handled object directly..... + * + * Note: + * The handle base corrsponding to this object in for + * conveniance reasons instantiated in dd4hep/src/Segmentations.cpp. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CORE + */ + class CylindricalGridPhiZ : public CylindricalGridPhiZHandle { + public: + /// Default constructor + CylindricalGridPhiZ() = default; + /// Copy constructor + CylindricalGridPhiZ(const CylindricalGridPhiZ& e) = default; + /// Copy Constructor from segmentation base object + CylindricalGridPhiZ(const Segmentation& e) : Handle(e) {} + /// Copy constructor from handle + CylindricalGridPhiZ(const Handle& e) : Handle(e) {} + /// Copy constructor from other polymorph/equivalent handle + template + CylindricalGridPhiZ(const Handle& e) : Handle(e) {} + /// Assignment operator + CylindricalGridPhiZ& operator=(const CylindricalGridPhiZ& seg) = default; + /// Equality operator + bool operator==(const CylindricalGridPhiZ& seg) const + { return m_element == seg.m_element; } + + /// determine the position based on the cell ID + Position position(const CellID& cellID) const; + /// determine the cell ID based on the position + CellID cellID(const Position& local, const Position& global, const VolumeID& volID) const; + /// access the grid size in phi + double gridSizePhi() const; + /// access the grid size in Z + double gridSizeZ() const; + /// access the radius + double radius() const; + /// access the coordinate offset in phi + double offsetPhi() const; + /// access the coordinate offset in Z + double offsetZ() const; + + /// set the grid size in phi + void setGridSizePhi(double cellSize) const; + /// set the grid size in Z + void setGridSizeZ(double cellSize) const; + /// set the coordinate offset in phi + void setOffsetPhi(double offset) const; + /// set the coordinate offset in Z + void setOffsetZ(double offset) const; + /// set the radius + void setRadius(double radius); + /// access the field name used for phi + const std::string& fieldNamePhi() const; + /// access the field name used for Z + const std::string& fieldNameZ() const; + /** \brief Returns a vector of the cellDimensions of the given cell ID + in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi + + Returns a vector of the cellDimensions of the given cell ID + \param cellID is ignored as all cells have the same dimension + \return std::vector size 2: + -# size in x + -# size in z + */ + std::vector cellDimensions(const CellID& cellID) const; + }; +} /* End namespace dd4hep */ +#endif // DD4HEP_CYLINDRICALGRIDPHIZ_H diff --git a/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h b/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h new file mode 100644 index 000000000..a02d01d47 --- /dev/null +++ b/DDCore/include/DDSegmentation/CylindricalGridPhiZ.h @@ -0,0 +1,127 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +//========================================================================== +/* + * CylindricalGridPhiZ.h + * + * Created on: Jun 28, 2024 + * Author: Yann Bedfer, ePIC/Saclay + */ + +#ifndef DDSEGMENTATION_CYLINDRICALGRIDPHIZ_H +#define DDSEGMENTATION_CYLINDRICALGRIDPHIZ_H + +#include + +namespace dd4hep { + namespace DDSegmentation { + + /// Segmentation base class describing cylindrical grid segmentation in the Phi-Z cylinder + class CylindricalGridPhiZ: public CylindricalSegmentation { + public: + /// default constructor using an arbitrary type + CylindricalGridPhiZ(const std::string& cellEncoding); + /// Default constructor used by derived classes passing an existing decoder + CylindricalGridPhiZ(const BitFieldCoder* decoder); + /// destructor + virtual ~CylindricalGridPhiZ(); + + /// determine the local based on the cell ID + virtual Vector3D position(const CellID& cellID) const; + /// determine the cell ID based on the position + virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const; + /// access the grid size in phi + double gridSizePhi() const { + return _gridSizePhi; + } + /// access the grid size in Z + double gridSizeZ() const { + return _gridSizeZ; + } + /// access the coordinate offset in phi + double offsetPhi() const { + return _offsetPhi; + } + /// access the coordinate offset in Z + double offsetZ() const { + return _offsetZ; + } + /// access the radius + double radius() const { + return _radius; + } + /// access the field name used for phi + const std::string& fieldNamePhi() const { + return _phiId; + } + /// access the field name used for Z + const std::string& fieldNameZ() const { + return _zId; + } + /// set the grid size in phi + void setGridSizePhi(double cellSize) { + _gridSizePhi = cellSize; + } + /// set the grid size in Z + void setGridSizeZ(double cellSize) { + _gridSizeZ = cellSize; + } + /// set the coordinate offset in phi + void setOffsetPhi(double offset) { + _offsetPhi = offset; + } + /// set the coordinate offset in Z + void setOffsetZ(double offset) { + _offsetZ = offset; + } + /// set the radius + void setRadius(double radius) { + _radius = radius; + } + /// set the field name used for phi + void setFieldNamePhi(const std::string& fieldName) { + _phiId = fieldName; + } + /// set the field name used for Z + void setFieldNameZ(const std::string& fieldName) { + _zId = fieldName; + } + /** \brief Returns a vector of the cellDimensions of the given cell ID + in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi + + Returns a vector of the cellDimensions of the given cell ID + \param cellID is ignored as all cells have the same dimension + \return std::vector size 2: + -# size in x + -# size in z + */ + virtual std::vector cellDimensions(const CellID& cellID) const; + + protected: + /// the grid size in phi + double _gridSizePhi; + /// the coordinate offset in phi + double _offsetPhi; + /// the grid size in Z + double _gridSizeZ; + /// the coordinate offset in Z + double _offsetZ; + /// the radius + double _radius; + /// the field name used for phi + std::string _phiId; + /// the field name used for Z + std::string _zId; + /// encoding field used for the module + }; + + } /* namespace DDSegmentation */ +} /* namespace dd4hep */ +#endif // DDSEGMENTATION_CYLINDRICALGRIDPHIZ_H diff --git a/DDCore/include/DDSegmentation/CylindricalSegmentation.h b/DDCore/include/DDSegmentation/CylindricalSegmentation.h index 84ce8e7a5..47deece42 100644 --- a/DDCore/include/DDSegmentation/CylindricalSegmentation.h +++ b/DDCore/include/DDSegmentation/CylindricalSegmentation.h @@ -26,14 +26,14 @@ namespace dd4hep { namespace DDSegmentation { - /// Segmentation base class describing a cyliondrical segmentation + /// Segmentation base class describing a cylindrical grid segmentation class CylindricalSegmentation: public Segmentation { public: - /// destructor + /// Destructor virtual ~CylindricalSegmentation(); protected: - /// default constructor using an arbitrary type + /// Default constructor using an arbitrary type CylindricalSegmentation(const std::string& cellEncoding); /// Default constructor used by derived classes passing an existing decoder CylindricalSegmentation(const BitFieldCoder* decoder); diff --git a/DDCore/src/CylindricalGridPhiZ.cpp b/DDCore/src/CylindricalGridPhiZ.cpp new file mode 100644 index 000000000..364f6e212 --- /dev/null +++ b/DDCore/src/CylindricalGridPhiZ.cpp @@ -0,0 +1,94 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include +#include + +using namespace dd4hep; + +/// determine the position based on the cell ID +Position CylindricalGridPhiZ::position(const CellID& id) const { + return Position(access()->implementation->position(id)); +} + +/// determine the cell ID based on the position +dd4hep::CellID CylindricalGridPhiZ::cellID(const Position& local, + const Position& global, + const VolumeID& volID) const +{ + return access()->implementation->cellID(local, global, volID); +} + +/// access the grid size in phi +double CylindricalGridPhiZ::gridSizePhi() const { + return access()->implementation->gridSizePhi(); +} + +/// access the grid size in Z +double CylindricalGridPhiZ::gridSizeZ() const { + return access()->implementation->gridSizeZ(); +} + +/// set the grid size in phi +void CylindricalGridPhiZ::setGridSizePhi(double cellSize) const { + access()->implementation->setGridSizePhi(cellSize); +} + +/// set the grid size in Z +void CylindricalGridPhiZ::setGridSizeZ(double cellSize) const { + access()->implementation->setGridSizeZ(cellSize); +} + +/// access the coordinate offset in phi +double CylindricalGridPhiZ::offsetPhi() const { + return access()->implementation->offsetPhi(); +} + +/// access the coordinate offset in Z +double CylindricalGridPhiZ::offsetZ() const { + return access()->implementation->offsetZ(); +} + +/// set the coordinate offset in phi +void CylindricalGridPhiZ::setOffsetPhi(double offset) const { + access()->implementation->setOffsetPhi(offset); +} + +/// set the coordinate offset in Z +void CylindricalGridPhiZ::setOffsetZ(double offset) const { + access()->implementation->setOffsetZ(offset); +} + +/// access the field name used for phi +const std::string& CylindricalGridPhiZ::fieldNamePhi() const { + return access()->implementation->fieldNamePhi(); +} + +/// access the field name used for Z +const std::string& CylindricalGridPhiZ::fieldNameZ() const { + return access()->implementation->fieldNameZ(); +} + +/** \brief Returns a vector of the cellDimensions of the given cell ID + in natural order of dimensions, e.g., dx/dy/dz, or dr/r*dPhi + + Returns a vector of the cellDimensions of the given cell ID + \param cellID is ignored as all cells have the same dimension + \return vector size 2: + -# size in x + -# size in z +*/ +std::vector CylindricalGridPhiZ::cellDimensions(const CellID& id) const { + return access()->implementation->cellDimensions(id); +} diff --git a/DDCore/src/SegmentationDictionary.h b/DDCore/src/SegmentationDictionary.h index 8a710cf09..c8c7e0aa0 100644 --- a/DDCore/src/SegmentationDictionary.h +++ b/DDCore/src/SegmentationDictionary.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -77,6 +78,7 @@ typedef dd4hep::DDSegmentation::CellID CellID; #pragma link C++ class dd4hep::DDSegmentation::CartesianStripY+; #pragma link C++ class dd4hep::DDSegmentation::CartesianStripZ+; #pragma link C++ class dd4hep::DDSegmentation::CylindricalSegmentation+; +#pragma link C++ class dd4hep::DDSegmentation::CylindricalGridPhiZ+; #pragma link C++ class dd4hep::DDSegmentation::GridPhiEta+; #pragma link C++ class dd4hep::DDSegmentation::GridRPhiEta+; #pragma link C++ class dd4hep::DDSegmentation::MegatileLayerGridXY+; diff --git a/DDCore/src/Segmentations.cpp b/DDCore/src/Segmentations.cpp index 55a4d3bac..789967aea 100644 --- a/DDCore/src/Segmentations.cpp +++ b/DDCore/src/Segmentations.cpp @@ -173,3 +173,6 @@ DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::ProjectiveCylinder); #include DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::MultiSegmentation); + +#include +DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::CylindricalGridPhiZ); diff --git a/DDCore/src/plugins/ReadoutSegmentations.cpp b/DDCore/src/plugins/ReadoutSegmentations.cpp index edfd47aea..8a1d50694 100644 --- a/DDCore/src/plugins/ReadoutSegmentations.cpp +++ b/DDCore/src/plugins/ReadoutSegmentations.cpp @@ -81,3 +81,6 @@ DECLARE_SEGMENTATION(MultiSegmentation,create_segmentation DECLARE_SEGMENTATION(HexGrid,create_segmentation) + +#include +DECLARE_SEGMENTATION(CylindricalGridPhiZ,create_segmentation) diff --git a/DDCore/src/segmentations/CylindricalGridPhiZ.cpp b/DDCore/src/segmentations/CylindricalGridPhiZ.cpp new file mode 100644 index 000000000..e0cee722c --- /dev/null +++ b/DDCore/src/segmentations/CylindricalGridPhiZ.cpp @@ -0,0 +1,106 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +//========================================================================== +/* + * CylindricalGridPhiZ.cpp + * + * Created on: Jun 28, 2024 + * Author: Yann Bedfer, ePIC/Saclay + */ + +#include + +namespace dd4hep { +namespace DDSegmentation { + +using std::make_pair; +using std::vector; + +/// default constructor using an encoding string +CylindricalGridPhiZ::CylindricalGridPhiZ(const std::string& cellEncoding) : + CylindricalSegmentation(cellEncoding) { + // define type and description + _type = "CylindricalGridPhiZ"; + _description = "Cylindrical segmentation in the local PhiZ-cylinder"; + + // register all necessary parameters + registerParameter("grid_size_phi", "Cell size in phi", _gridSizePhi, 1., SegmentationParameter::AngleUnit); + registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit); + registerParameter("offset_phi", "Cell offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true); + registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true); + registerParameter("radius", "Radius of Cylinder", _radius, 0., SegmentationParameter::LengthUnit); + registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiId, "phi"); + registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z"); +} + +/// Default constructor used by derived classes passing an existing decoder +CylindricalGridPhiZ::CylindricalGridPhiZ(const BitFieldCoder* decode) : + CylindricalSegmentation(decode) { + // define type and description + _type = "CylindricalGridPhiZ"; + _description = "Cylindrical segmentation in the local PhiZ-cylinder"; + + // register all necessary parameters + registerParameter("grid_size_phi", "Cell size in phi", _gridSizePhi, 1., SegmentationParameter::AngleUnit); + registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit); + registerParameter("offset_phi", "Cell offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true); + registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true); + registerParameter("radius", "Radius of Cylinder", _radius, 0., SegmentationParameter::LengthUnit); + registerIdentifier("identifier_phi", "Cell ID identifier for phi", _phiId, "phi"); + registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z"); +} + +/// destructor +CylindricalGridPhiZ::~CylindricalGridPhiZ() { + +} + +/// determine the position based on the cell ID +Vector3D CylindricalGridPhiZ::position(const CellID& cID) const { + vector localPosition(3); + Vector3D cellPosition; + double phi = + binToPosition( _decoder->get(cID,_phiId ), _gridSizePhi, _offsetPhi); + cellPosition.Z = + binToPosition( _decoder->get(cID,_zId ), _gridSizeZ, _offsetZ); + const double &R = _radius; + cellPosition.X = R*cos(phi); cellPosition.Y = R*sin(phi); + + return cellPosition; +} + +/// determine the cell ID based on the position + CellID CylindricalGridPhiZ::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const { + double phi = atan2(localPosition.Y,localPosition.X); + double Z = localPosition.Z; + if ( phi < _offsetPhi) { + phi += 2*M_PI; + } + CellID cID = vID ; + _decoder->set( cID,_phiId, positionToBin(phi, _gridSizePhi, _offsetPhi) ); + _decoder->set( cID,_zId, positionToBin(Z, _gridSizeZ, _offsetZ) ); + + return cID ; +} + +std::vector CylindricalGridPhiZ::cellDimensions(const CellID&) const { +#if __cplusplus >= 201103L + return {_gridSizePhi, _gridSizeZ}; +#else + std::vector cellDims(2,0.0); + cellDims[0] = _radius*_gridSizePhi; + cellDims[1] = _gridSizeZ; + return cellDims; +#endif +} + + +} /* namespace DDSegmentation */ +} /* namespace dd4hep */