From 8fb6840dbbbd46547e1316a7e0e8e9fdf575249c Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Wed, 3 Sep 2014 13:04:40 +0000 Subject: [PATCH] - added CartesianGridYZ --- DDCore/include/DD4hep/Dictionary.h | 2 + .../include/DDSegmentation/CartesianGridYZ.h | 95 +++++++++++++++++++ DDSegmentation/src/CartesianGridYZ.cpp | 57 +++++++++++ 3 files changed, 154 insertions(+) create mode 100644 DDSegmentation/include/DDSegmentation/CartesianGridYZ.h create mode 100644 DDSegmentation/src/CartesianGridYZ.cpp diff --git a/DDCore/include/DD4hep/Dictionary.h b/DDCore/include/DD4hep/Dictionary.h index 3f5941e24..17d7e64ad 100644 --- a/DDCore/include/DD4hep/Dictionary.h +++ b/DDCore/include/DD4hep/Dictionary.h @@ -262,6 +262,7 @@ template vector<pair<string, int> >::iterator; #include "DDSegmentation/CartesianGridXY.h" #include "DDSegmentation/CartesianGridXYZ.h" #include "DDSegmentation/CartesianGridXZ.h" +#include "DDSegmentation/CartesianGridYZ.h" #include "DDSegmentation/CylindricalSegmentation.h" #include "DDSegmentation/ProjectiveCylinder.h" #include "DDSegmentation/SegmentationParameter.h" @@ -289,6 +290,7 @@ typedef DD4hep::DDSegmentation::CellID CellID; #pragma link C++ class DD4hep::DDSegmentation::CartesianGridXY+; #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::CylindricalSegmentation+; #pragma link C++ class DD4hep::DDSegmentation::ProjectiveCylinder+; #pragma link C++ class DD4hep::DDSegmentation::TiledLayerSegmentation+; diff --git a/DDSegmentation/include/DDSegmentation/CartesianGridYZ.h b/DDSegmentation/include/DDSegmentation/CartesianGridYZ.h new file mode 100644 index 000000000..aeba7572e --- /dev/null +++ b/DDSegmentation/include/DDSegmentation/CartesianGridYZ.h @@ -0,0 +1,95 @@ +#ifndef DDSegmentation_CARTESIANGRIDXY_H_ +#define DDSegmentation_CARTESIANGRIDXY_H_ + +#include "DDSegmentation/CartesianGrid.h" + +namespace DD4hep { +namespace DDSegmentation { + +/** + * CartesianGridYZ.h + * + * @date: Sep 03, 2014 + * @author: F.Gaede CERN/Desy + * @version: $Id$ + * direkt copy of CartesianGridXY + * by Christian Grefe, CERN + */ +class CartesianGridYZ: public CartesianGrid { +public: + /// Default constructor passing the encoding string + CartesianGridYZ(const std::string& cellEncoding = ""); + /// destructor + virtual ~CartesianGridYZ(); + + /// 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 Y + double gridSizeY() const { + return _gridSizeY; + } + /// access the grid size in Z + double gridSizeZ() const { + return _gridSizeZ; + } + /// access the coordinate offset in Y + double offsetY() const { + return _offsetY; + } + /// access the coordinate offset in Z + double offsetZ() const { + return _offsetZ; + } + /// access the field name used for Y + const std::string& fieldNameY() const { + return _yId; + } + /// access the field name used for Z + const std::string& fieldNameZ() const { + return _zId; + } + /// set the grid size in Y + void setGridSizeY(double cellSize) { + _gridSizeY = cellSize; + } + /// set the grid size in Z + void setGridSizeZ(double cellSize) { + _gridSizeZ = cellSize; + } + /// set the coordinate offset in Y + void setOffsetY(double offset) { + _offsetY = offset; + } + /// set the coordinate offset in Z + void setOffsetZ(double offset) { + _offsetZ = offset; + } + /// set the field name used for Y + void setFieldNameY(const std::string& name) { + _yId = name; + } + /// set the field name used for Z + void setFieldNameZ(const std::string& name) { + _zId = name; + } + +protected: + /// the grid size in Y + double _gridSizeY; + /// the coordinate offset in Y + double _offsetY; + /// the grid size in Z + double _gridSizeZ; + /// the coordinate offset in Z + double _offsetZ; + /// the field name used for Y + std::string _yId; + /// the field name used for Z + std::string _zId; +}; + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ +#endif /* DDSegmentation_CARTESIANGRIDXY_H_ */ diff --git a/DDSegmentation/src/CartesianGridYZ.cpp b/DDSegmentation/src/CartesianGridYZ.cpp new file mode 100644 index 000000000..6a913998b --- /dev/null +++ b/DDSegmentation/src/CartesianGridYZ.cpp @@ -0,0 +1,57 @@ +/* CartesianGridYZ.cpp + * + * @date: Sep 03, 2014 + * @author: F.Gaede CERN/Desy + * @version: $Id$ + * direkt copy of CartesianGridXY + * by Christian Grefe, CERN + */ +#include "DDSegmentation/CartesianGridYZ.h" + +namespace DD4hep { +namespace DDSegmentation { + +using std::string; + +/// default constructor using an encoding string +CartesianGridYZ::CartesianGridYZ(const string& cellEncoding) : + CartesianGrid(cellEncoding) { + // define type and description + _type = "CartesianGridYZ"; + _description = "Cartesian segmentation in the local YZ-plane"; + + // register all necessary parameters + registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit); + registerParameter("grid_size_z", "Cell size in Z", _gridSizeZ, 1., SegmentationParameter::LengthUnit); + registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true); + registerParameter("offset_z", "Cell offset in Z", _offsetZ, 0., SegmentationParameter::LengthUnit, true); + registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y"); + registerIdentifier("identifier_z", "Cell ID identifier for Z", _zId, "z"); +} + +/// destructor +CartesianGridYZ::~CartesianGridYZ() { + +} + +/// determine the position based on the cell ID +Vector3D CartesianGridYZ::position(const CellID& cellID) const { + _decoder->setValue(cellID); + Vector3D position; + position.Y = binToPosition((*_decoder)[_yId].value(), _gridSizeY, _offsetY); + position.Z = binToPosition((*_decoder)[_zId].value(), _gridSizeZ, _offsetZ); + return position; +} + +/// determine the cell ID based on the position +CellID CartesianGridYZ::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const { + _decoder->setValue(volumeID); + (*_decoder)[_yId] = positionToBin(localPosition.Y, _gridSizeY, _offsetY); + (*_decoder)[_zId] = positionToBin(localPosition.Z, _gridSizeZ, _offsetZ); + return _decoder->getValue(); +} + +REGISTER_SEGMENTATION(CartesianGridYZ) + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ -- GitLab