From e9cb05a7e17d696d32743a00eb5e09c7c451cef8 Mon Sep 17 00:00:00 2001 From: Marko Petric <marko.petric@cern.ch> Date: Tue, 17 Mar 2015 12:18:01 +0000 Subject: [PATCH] The template to add the new segmentation with vector input --- .../include/DDSegmentation/PolarGridRPhi2.h | 95 +++++++++++++++++++ DDSegmentation/src/PolarGridRPhi2.cpp | 63 ++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 DDSegmentation/include/DDSegmentation/PolarGridRPhi2.h create mode 100644 DDSegmentation/src/PolarGridRPhi2.cpp diff --git a/DDSegmentation/include/DDSegmentation/PolarGridRPhi2.h b/DDSegmentation/include/DDSegmentation/PolarGridRPhi2.h new file mode 100644 index 000000000..f339dc138 --- /dev/null +++ b/DDSegmentation/include/DDSegmentation/PolarGridRPhi2.h @@ -0,0 +1,95 @@ +/* + * PolarGridRPhi2.h + * + * Created on: Sept 13, 2014 + * Author: Marko Petric + */ + +#ifndef DDSegmentation_PolarGridRPhi2_H_ +#define DDSegmentation_PolarGridRPhi2_H_ + +#include "DDSegmentation/PolarGrid.h" +#include <math.h> +#include <vector> + +namespace DD4hep { +namespace DDSegmentation { + +class PolarGridRPhi2: public PolarGrid { +public: + /// Default constructor passing the encoding string + PolarGridRPhi2(const std::string& cellEncoding = ""); + /// destructor + virtual ~PolarGridRPhi2(); + + /// 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 + std::vector<double> gridRValues() const { + return _gridRValues; + } + /// 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 setgridRValues(double cellSize, int value) { + _gridRValues[value] = 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 + std::vector<double> _gridRValues; + /// 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_PolarGridRPhi2_H_ */ diff --git a/DDSegmentation/src/PolarGridRPhi2.cpp b/DDSegmentation/src/PolarGridRPhi2.cpp new file mode 100644 index 000000000..6cbbbf0a2 --- /dev/null +++ b/DDSegmentation/src/PolarGridRPhi2.cpp @@ -0,0 +1,63 @@ +/* + * PolarGridRPhi2.cpp + * + * Created on: Sept 16, 2014 + * Author: Marko Petric + */ + +#include "DDSegmentation/PolarGridRPhi2.h" + +namespace DD4hep { +namespace DDSegmentation { + +using std::string; + +/// default constructor using an encoding string +PolarGridRPhi2::PolarGridRPhi2(const string& cellEncoding) : + PolarGrid(cellEncoding) { + // define type and description + _type = "PolarGridRPhi2"; + _description = "Polar RPhi segmentation in the local XY-plane"; + + // register all necessary parameters + registerParameter("grid_r_values", "Vector or R values", _gridRValues, std::vector<double>(), SegmentationParameter::NoUnit, true); + 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 +PolarGridRPhi2::~PolarGridRPhi2() { + +} + +/// determine the position based on the cell ID +Vector3D PolarGridRPhi2::position(const CellID& cellID) const { + _decoder->setValue(cellID); + Vector3D position; + double R = binToPosition((*_decoder)[_rId].value(), _gridRValues[0], _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 PolarGridRPhi2::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, _gridRValues[0], _offsetR); + (*_decoder)[_phiId] = positionToBin(phi, _gridSizePhi, _offsetPhi); + return _decoder->getValue(); +} + +REGISTER_SEGMENTATION(PolarGridRPhi2) + +} /* namespace DDSegmentation */ +} /* namespace DD4hep */ -- GitLab