diff --git a/DDCore/include/DD4hep/CartesianGridUV.h b/DDCore/include/DD4hep/CartesianGridUV.h new file mode 100644 index 000000000..19a335dc0 --- /dev/null +++ b/DDCore/include/DD4hep/CartesianGridUV.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_CARTESIANGRIDUV_H +#define DD4HEP_CARTESIANGRIDUV_H 1 + +// Framework include files +#include + +/// Namespace for the AIDA detector description toolkit +namespace dd4hep { + + /// Namespace for base segmentations + namespace DDSegmentation { class CartesianGridUV; } + + /// We need some abbreviation to make the code more readable. + typedef Handle > CartesianGridUVHandle; + + /// Implementation class for the grid UV 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 corresponding to this object in for + * conveniance reasons instantiated in dd4hep/src/Segmentations.cpp. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CORE + */ + class CartesianGridUV : public CartesianGridUVHandle { + public: + /// Default constructor + CartesianGridUV() = default; + /// Copy constructor + CartesianGridUV(const CartesianGridUV& e) = default; + /// Copy Constructor from segmentation base object + CartesianGridUV(const Segmentation& e) : Handle(e) { } + /// Copy constructor from handle + CartesianGridUV(const Handle& e) : Handle(e) { } + /// Copy constructor from other equivalent handle + template CartesianGridUV(const Handle& e) : Handle(e) { } + /// Assignment operator + CartesianGridUV& operator=(const CartesianGridUV& seg) = default; + /// Equality operator + bool operator==(const CartesianGridUV& 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 U + double gridSizeU() const; + /// access the grid size in V + double gridSizeV() const; + /// set the grid size in U + void setGridSizeU(double cellSize) const; + /// set the grid size in V + void setGridSizeV(double cellSize) const; + /// access the coordinate offset in U + double offsetU() const; + /// access the coordinate offset in V + double offsetV() const; + /// access the rotation angle + double gridAngle() const; + /// set the coordinate offset in U + void setOffsetU(double offset) const; + /// set the coordinate offset in V + void setOffsetV(double offset) const; + /// set the rotation angle + void setGridAngle(double angle) const; + /// access the field name used for U + const std::string& fieldNameU() const; + /// access the field name used for V + const std::string& fieldNameV() 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 U + -# size in V + */ + std::vector cellDimensions(const CellID& cellID) const; + }; + +} /* End namespace dd4hep */ +#endif // DD4HEP_CARTESIANGRIDUV_H diff --git a/DDCore/include/DDSegmentation/CartesianGridUV.h b/DDCore/include/DDSegmentation/CartesianGridUV.h new file mode 100644 index 000000000..0dd7e52bc --- /dev/null +++ b/DDCore/include/DDSegmentation/CartesianGridUV.h @@ -0,0 +1,126 @@ +//========================================================================== +// 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. +// +//========================================================================== +/* + * CartesianGridUV.h + * + * Created on: December 5, 2024 + * Author: Yann Bedfer, ePIC/Saclay + */ + +#ifndef DDSEGMENTATION_CARTESIANGRIDUV_H +#define DDSEGMENTATION_CARTESIANGRIDUV_H + +#include + +namespace dd4hep { + namespace DDSegmentation { + + /// Segmentation base class describing cartesian grid segmentation in along U,V rotated some angle from local X,Y axes + class CartesianGridUV: public CartesianGrid { + public: + /// Default constructor passing the encoding string + CartesianGridUV(const std::string& cellEncoding = ""); + /// Default constructor used by derived classes passing an existing decoder + CartesianGridUV(const BitFieldCoder* decoder); + /// destructor + virtual ~CartesianGridUV(); + + /// determine the position 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 U + double gridSizeU() const { + return _gridSizeU; + } + /// access the grid size in V + double gridSizeV() const { + return _gridSizeV; + } + /// access the coordinate offset in U + double offsetU() const { + return _offsetU; + } + /// access the coordinate offset in V + double offsetV() const { + return _offsetV; + } + /// access the rotation angle + double gridAngle() const { + return _gridAngle; + } + /// access the field name used for U + const std::string& fieldNameU() const { + return _uId; + } + /// access the field name used for V + const std::string& fieldNameV() const { + return _vId; + } + /// set the grid size in U + void setGridSizeU(double cellSize) { + _gridSizeU = cellSize; + } + /// set the grid size in V + void setGridSizeV(double cellSize) { + _gridSizeV = cellSize; + } + /// set the coordinate offset in U + void setOffsetU(double offset) { + _offsetU = offset; + } + /// set the coordinate offset in V + void setOffsetV(double offset) { + _offsetV = offset; + } + /// set the rotation angle + void setGridAngle(double angle) { + _gridAngle = angle; + } + /// set the field name used for U + void setFieldNameU(const std::string& fieldName) { + _uId = fieldName; + } + /// set the field name used for V + void setFieldNameV(const std::string& fieldName) { + _vId = 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 U + -# size in V + */ + virtual std::vector cellDimensions(const CellID& cellID) const; + + protected: + /// the grid size in U + double _gridSizeU; + /// the coordinate offset in U + double _offsetU; + /// the grid size in V + double _gridSizeV; + /// the coordinate offset in V + double _offsetV; + /// the field name used for U + std::string _uId; + /// the field name used for V + std::string _vId; + /// the U grid angle + double _gridAngle; + }; + + } /* namespace DDSegmentation */ +} /* namespace dd4hep */ +#endif // DDSEGMENTATION_CARTESIANGRIDUV_H diff --git a/DDCore/include/XML/UnicodeValues.h b/DDCore/include/XML/UnicodeValues.h index 9a41be51e..8f18522bd 100644 --- a/DDCore/include/XML/UnicodeValues.h +++ b/DDCore/include/XML/UnicodeValues.h @@ -192,9 +192,11 @@ UNICODE (global); UNICODE (global_grid_xy); UNICODE (grid_size_x); UNICODE (grid_size_y); -UNICODE (grid_size_z); +UNICODE (grid_size_u); +UNICODE (grid_size_v); UNICODE (grid_size_phi); UNICODE (grid_xyz); +UNICODE (grid_angle); UNICODE (gridSizePhi); UNICODE (gridSizeX); UNICODE (gridSizeY); diff --git a/DDCore/src/CartesianGridUV.cpp b/DDCore/src/CartesianGridUV.cpp new file mode 100644 index 000000000..132813819 --- /dev/null +++ b/DDCore/src/CartesianGridUV.cpp @@ -0,0 +1,91 @@ +//========================================================================== +// 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 CartesianGridUV::position(const CellID& id) const { + return Position(access()->implementation->position(id)); +} + +/// determine the cell ID based on the position +dd4hep::CellID CartesianGridUV::cellID(const Position& local, + const Position& global, + const VolumeID& volID) const +{ + return access()->implementation->cellID(local, global, volID); +} + +/// access the grid size in U +double CartesianGridUV::gridSizeU() const { + return access()->implementation->gridSizeU(); +} + +/// access the grid size in V +double CartesianGridUV::gridSizeV() const { + return access()->implementation->gridSizeV(); +} + +/// set the grid size in U +void CartesianGridUV::setGridSizeU(double cellSize) const { + access()->implementation->setGridSizeU(cellSize); +} + +/// set the grid size in V +void CartesianGridUV::setGridSizeV(double cellSize) const { + access()->implementation->setGridSizeV(cellSize); +} + +/// access the coordinate offset in U +double CartesianGridUV::offsetU() const { + return access()->implementation->offsetU(); +} + +/// access the coordinate offset in V +double CartesianGridUV::offsetV() const { + return access()->implementation->offsetV(); +} + +/// access the rotation angle +double CartesianGridUV::gridAngle() const { + return access()->implementation->gridAngle(); +} + +/// set the coordinate offset in U +void CartesianGridUV::setOffsetU(double offset) const { + access()->implementation->setOffsetU(offset); +} + +/// set the coordinate offset in V +void CartesianGridUV::setOffsetV(double offset) const { + access()->implementation->setOffsetV(offset); +} + +/// access the field name used for U +const std::string& CartesianGridUV::fieldNameU() const { + return access()->implementation->fieldNameU(); +} + +/// access the field name used for V +const std::string& CartesianGridUV::fieldNameV() const { + return access()->implementation->fieldNameV(); +} + +// Returns a vector of the cellDimensions of the given cell ID +std::vector CartesianGridUV::cellDimensions(const CellID& id) const { + return access()->implementation->cellDimensions(id); +} diff --git a/DDCore/src/SegmentationDictionary.h b/DDCore/src/SegmentationDictionary.h index c8c7e0aa0..ef99cc620 100644 --- a/DDCore/src/SegmentationDictionary.h +++ b/DDCore/src/SegmentationDictionary.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ typedef dd4hep::DDSegmentation::CellID CellID; #pragma link C++ class dd4hep::DDSegmentation::CartesianGridXYZ+; #pragma link C++ class dd4hep::DDSegmentation::CartesianGridXZ+; #pragma link C++ class dd4hep::DDSegmentation::CartesianGridYZ+; +#pragma link C++ class dd4hep::DDSegmentation::CartesianGridUV+; #pragma link C++ class dd4hep::DDSegmentation::CartesianStripX+; #pragma link C++ class dd4hep::DDSegmentation::CartesianStripY+; #pragma link C++ class dd4hep::DDSegmentation::CartesianStripZ+; diff --git a/DDCore/src/Segmentations.cpp b/DDCore/src/Segmentations.cpp index 789967aea..4d36775de 100644 --- a/DDCore/src/Segmentations.cpp +++ b/DDCore/src/Segmentations.cpp @@ -135,6 +135,9 @@ DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridXZ); #include DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridYZ); +#include +DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridUV); + #include DD4HEP_INSTANTIATE_SEGMENTATION_HANDLE(DDSegmentation::CartesianGridXYZ); diff --git a/DDCore/src/plugins/ReadoutSegmentations.cpp b/DDCore/src/plugins/ReadoutSegmentations.cpp index 8a1d50694..69d8035fb 100644 --- a/DDCore/src/plugins/ReadoutSegmentations.cpp +++ b/DDCore/src/plugins/ReadoutSegmentations.cpp @@ -37,8 +37,8 @@ DECLARE_SEGMENTATION(CartesianGridXZ,create_segmentation DECLARE_SEGMENTATION(CartesianGridYZ,create_segmentation) -#include -DECLARE_SEGMENTATION(CartesianGridXYZ,create_segmentation) +#include +DECLARE_SEGMENTATION(CartesianGridUV,create_segmentation) #include DECLARE_SEGMENTATION(CartesianGridXYStaggered,dd4hep::create_segmentation) diff --git a/DDCore/src/segmentations/CartesianGridUV.cpp b/DDCore/src/segmentations/CartesianGridUV.cpp new file mode 100644 index 000000000..3f7375913 --- /dev/null +++ b/DDCore/src/segmentations/CartesianGridUV.cpp @@ -0,0 +1,101 @@ +//========================================================================== +// 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. +// +//========================================================================== +/* + * CartesianGridUV.cpp + * + * Created on: December 5, 2024 + * Author: Yann Bedfer, ePIC/Saclay + * + * Derived from "./CartesianGridXY.cpp". + */ +#include + +namespace dd4hep { +namespace DDSegmentation { + +/// default constructor using an encoding string +CartesianGridUV::CartesianGridUV(const std::string& cellEncoding) : + CartesianGrid(cellEncoding) { + // define type and description + _type = "CartesianGridUV"; + _description = "Cartesian segmentation along U,V rotated some angle from local X,Y axes"; + + // register all necessary parameters + registerParameter("grid_size_u", "Cell size in U", _gridSizeU, 1., SegmentationParameter::LengthUnit); + registerParameter("grid_size_v", "Cell size in V", _gridSizeV, 1., SegmentationParameter::LengthUnit); + registerParameter("offset_u", "Cell offset in U", _offsetU, 0., SegmentationParameter::LengthUnit, true); + registerParameter("offset_v", "Cell offset in V", _offsetV, 0., SegmentationParameter::LengthUnit, true); + registerIdentifier("identifier_u", "Cell ID identifier for U", _uId, "u"); + registerIdentifier("identifier_v", "Cell ID identifier for V", _vId, "v"); + registerParameter("grid_angle", "Angle of U measurement axis in X,Y frame", _gridAngle, 0., SegmentationParameter::AngleUnit); +}; + +/// Default constructor used by derived classes passing an existing decoder +CartesianGridUV::CartesianGridUV(const BitFieldCoder* decode) : + CartesianGrid(decode) +{ + // define type and description + _type = "CartesianGridUV"; + _description = "Cartesian segmentation along U,V rotated some angle from local X,Y axes"; + + // register all necessary parameters + registerParameter("grid_size_u", "Cell size in U", _gridSizeU, 1., SegmentationParameter::LengthUnit); + registerParameter("grid_size_v", "Cell size in V", _gridSizeV, 1., SegmentationParameter::LengthUnit); + registerParameter("offset_u", "Cell offset in U", _offsetU, 0., SegmentationParameter::LengthUnit, true); + registerParameter("offset_v", "Cell offset in V", _offsetV, 0., SegmentationParameter::LengthUnit, true); + registerIdentifier("identifier_u", "Cell ID identifier for U", _uId, "u"); + registerIdentifier("identifier_v", "Cell ID identifier for V", _vId, "v"); + registerParameter("grid_angle", "Angle of U measurement axis in X,Y frame", _gridAngle, 0., SegmentationParameter::AngleUnit); +}; + +/// destructor +CartesianGridUV::~CartesianGridUV() { + +} + +/// determine the position based on the cell ID +Vector3D CartesianGridUV::position(const CellID& cID) const { + Vector3D cellPosition; + cellPosition.X = binToPosition( _decoder->get(cID,_uId ), _gridSizeU, _offsetU); + cellPosition.Y = binToPosition( _decoder->get(cID,_vId ), _gridSizeV, _offsetV); + cellPosition = RotationZ(-_gridAngle)*cellPosition; + return cellPosition; +} + +/// determine the cell ID based on the position +CellID CartesianGridUV::cellID(const Vector3D& localPosition, + const Vector3D& /* globalPosition */, + const VolumeID& vID) const { + CellID cID = vID; + const Vector3D& localUV = RotationZ(_gridAngle)*localPosition; + _decoder->set( cID,_uId, positionToBin(localUV.X, _gridSizeU, _offsetU) ); + _decoder->set( cID,_vId, positionToBin(localUV.Y, _gridSizeV, _offsetV) ); + return cID; +} + + std::vector CartesianGridUV::cellDimensions(const CellID& /* cellID */) const { +#if __cplusplus >= 201103L + return {_gridSizeU, _gridSizeV}; +#else + std::vector cellDims(2,0.0); + cellDims[0] = _gridSizeU; + cellDims[1] = _gridSizeV; + return cellDims; +#endif +} + + +} /* namespace DDSegmentation */ +} /* namespace dd4hep */ + +// This is done DDCore/src/plugins/ReadoutSegmentations.cpp so the plugin is not part of libDDCore +// needs also #include +// DECLARE_SEGMENTATION(CartesianGridUV,dd4hep::create_segmentation)