From 44083600eb5d0a6294d16f03bd66f3aff4a280bf Mon Sep 17 00:00:00 2001 From: Marko Petric <marko.petric@cern.ch> Date: Wed, 17 Sep 2014 12:31:26 +0000 Subject: [PATCH] Implementation of a Polar R-phi segmentation --- .../include/DDSegmentation/PolarGrid.h | 27 ++++++ .../include/DDSegmentation/PolarGridRPhi.h | 94 +++++++++++++++++++ DDSegmentation/src/PolarGrid.cpp | 25 +++++ DDSegmentation/src/PolarGridRPhi.cpp | 63 +++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 DDSegmentation/include/DDSegmentation/PolarGrid.h create mode 100644 DDSegmentation/include/DDSegmentation/PolarGridRPhi.h create mode 100644 DDSegmentation/src/PolarGrid.cpp create mode 100644 DDSegmentation/src/PolarGridRPhi.cpp diff --git a/DDSegmentation/include/DDSegmentation/PolarGrid.h b/DDSegmentation/include/DDSegmentation/PolarGrid.h new file mode 100644 index 000000000..e147c8ff0 --- /dev/null +++ b/DDSegmentation/include/DDSegmentation/PolarGrid.h @@ -0,0 +1,27 @@ +/* + * PolarGrid.h + * + * Created on: Sept 16, 2014 + * Author: Marko Petric + */ + +#ifndef DDSegmentation_POLARGRID_H_ +#define DDSegmentation_POLARGRID_H_ + +#include "DDSegmentation/Segmentation.h" + +namespace DD4hep { +namespace DDSegmentation { + +class PolarGrid: public Segmentation { +public: + /// Destructor + virtual ~PolarGrid(); +protected: + /// Default constructor used by derived classes passing the encoding string + PolarGrid(const std::string& cellEncoding = ""); +}; + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ +#endif /* DDSegmentation_POLARGRID_H_ */ diff --git a/DDSegmentation/include/DDSegmentation/PolarGridRPhi.h b/DDSegmentation/include/DDSegmentation/PolarGridRPhi.h new file mode 100644 index 000000000..b6ef80573 --- /dev/null +++ b/DDSegmentation/include/DDSegmentation/PolarGridRPhi.h @@ -0,0 +1,94 @@ +/* + * PolarGridRPhi.h + * + * Created on: Sept 13, 2014 + * Author: Marko Petric + */ + +#ifndef DDSegmentation_POLARGRIDRPHI_H_ +#define DDSegmentation_POLARGRIDRPHI_H_ + +#include "DDSegmentation/PolarGrid.h" +#include <math.h> + +namespace DD4hep { +namespace DDSegmentation { + +class PolarGridRPhi: public PolarGrid { +public: + /// Default constructor passing the encoding string + PolarGridRPhi(const std::string& cellEncoding = ""); + /// destructor + virtual ~PolarGridRPhi(); + + /// 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 R + double gridSizeR() const { + return _gridSizeR; + } + /// access the grid size in Phi + double gridSizePhi() const { + return _gridSizePhi; + } + /// access the coordinate offset in R + double offsetR() const { + return _offsetR; + } + /// access the coordinate offset in Phi + double offsetPhi() const { + return _offsetPhi; + } + /// access the field name used for R + const std::string& fieldNameR() const { + return _rId; + } + /// access the field name used for Phi + const std::string& fieldNamePhi() const { + return _phiId; + } + /// set the grid size in R + void setGridSizeR(double cellSize) { + _gridSizeR = cellSize; + } + /// set the grid size in Phi + void setGridSizePhi(double cellSize) { + _gridSizePhi = cellSize; + } + /// set the coordinate offset in R + void setOffsetR(double offset) { + _offsetR = offset; + } + /// set the coordinate offset in Phi + void setOffsetPhi(double offset) { + _offsetPhi = offset; + } + /// set the field name used for X + void setFieldNameR(const std::string& name) { + _rId = name; + } + /// set the field name used for Y + void setFieldNamePhi(const std::string& name) { + _phiId = name; + } + +protected: + /// the grid size in X + double _gridSizeR; + /// the coordinate offset in X + double _offsetR; + /// the grid size in Y + double _gridSizePhi; + /// the coordinate offset in Y + double _offsetPhi; + /// the field name used for X + std::string _rId; + /// the field name used for Y + std::string _phiId; +}; + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ +#endif /* DDSegmentation_POLARGRIDRPHI_H_ */ diff --git a/DDSegmentation/src/PolarGrid.cpp b/DDSegmentation/src/PolarGrid.cpp new file mode 100644 index 000000000..286e94e4e --- /dev/null +++ b/DDSegmentation/src/PolarGrid.cpp @@ -0,0 +1,25 @@ +/* + * PolarGrid.cpp + * + * Created on: Sep 16, 2014 + * Author: Marko Petric + */ + +#include "DDSegmentation/PolarGrid.h" + +namespace DD4hep { +namespace DDSegmentation { + +using std::string; + +/// Default constructor used by derived classes passing the encoding string +PolarGrid::PolarGrid(const string& cellEncoding) : + Segmentation(cellEncoding) { +} + +/// Destructor +PolarGrid::~PolarGrid() { +} + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ diff --git a/DDSegmentation/src/PolarGridRPhi.cpp b/DDSegmentation/src/PolarGridRPhi.cpp new file mode 100644 index 000000000..8a29584e5 --- /dev/null +++ b/DDSegmentation/src/PolarGridRPhi.cpp @@ -0,0 +1,63 @@ +/* + * PolarGridRPhi.cpp + * + * Created on: Sept 16, 2014 + * Author: Marko Petric + */ + +#include "DDSegmentation/PolarGridRPhi.h" + +namespace DD4hep { +namespace DDSegmentation { + +using std::string; + +/// default constructor using an encoding string +PolarGridRPhi::PolarGridRPhi(const string& cellEncoding) : + PolarGrid(cellEncoding) { + // define type and description + _type = "PolarGridRPhi"; + _description = "Polar RPhi segmentation in the local XY-plane"; + + // register all necessary parameters + registerParameter("grid_size_r", "Cell size in R", _gridSizeR, 1., SegmentationParameter::LengthUnit); + registerParameter("grid_size_phi", "Cell size in Phi", _gridSizePhi, 1., SegmentationParameter::AngleUnit); + registerParameter("offset_r", "Cell offset in R", _offsetR, 0., SegmentationParameter::LengthUnit, true); + registerParameter("offset_phi", "Cell offset in Phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true); + registerIdentifier("identifier_r", "Cell ID identifier for R", _rId, "r"); + registerIdentifier("identifier_phi", "Cell ID identifier for Phi", _phiId, "phi"); +} + +/// destructor +PolarGridRPhi::~PolarGridRPhi() { + +} + +/// determine the position based on the cell ID +Vector3D PolarGridRPhi::position(const CellID& cellID) const { + _decoder->setValue(cellID); + Vector3D position; + double R = binToPosition((*_decoder)[_rId].value(), _gridSizeR, _offsetR); + double phi = binToPosition((*_decoder)[_phiId].value(), _gridSizePhi, _offsetPhi); + + position.X = R * cos(phi); + position.Y = R * sin(phi); + + return position; +} + +/// determine the cell ID based on the position +CellID PolarGridRPhi::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const { + _decoder->setValue(volumeID); + double phi = atan2(localPosition.Y,localPosition.X); + double R = sqrt( localPosition.X * localPosition.X + localPosition.Y * localPosition.Y ); + + (*_decoder)[_rId] = positionToBin(R, _gridSizeR, _offsetR); + (*_decoder)[_phiId] = positionToBin(phi, _gridSizePhi, _offsetPhi); + return _decoder->getValue(); +} + +REGISTER_SEGMENTATION(PolarGridRPhi) + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ -- GitLab