From 8bca3ce1b1bfde23314994f3d59c7291006dbd9c Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Tue, 31 Mar 2015 09:48:47 +0000
Subject: [PATCH] ProjectiveCylinder: fixes

Fix: phi/theta Coordinate calculation was not updating the cellID
     Create protected functions no taking cellIDs, make public functions update the cellID for the decoder
     Make position update the cellID for the decoder and use the private phi/theta functions

Fix: Change type for thetaBins and phiBins members, they should be integer (at least the setters only allowed int)

Tweaks: Use CellID instead of long64 (same typedef)
---
 .../DDSegmentation/ProjectiveCylinder.h       | 14 +++++---
 DDSegmentation/src/ProjectiveCylinder.cpp     | 32 +++++++++++++------
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/DDSegmentation/include/DDSegmentation/ProjectiveCylinder.h b/DDSegmentation/include/DDSegmentation/ProjectiveCylinder.h
index 260dde658..6ab7c68fc 100644
--- a/DDSegmentation/include/DDSegmentation/ProjectiveCylinder.h
+++ b/DDSegmentation/include/DDSegmentation/ProjectiveCylinder.h
@@ -25,9 +25,9 @@ public:
 	/// determine the cell ID based on the position
 	virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& volumeID) const;
 	/// determine the polar angle theta based on the cell ID
-	double theta(const long64& cellID) const;
+	double theta(const CellID& cellID) const;
 	/// determine the azimuthal angle phi based on the cell ID
-	double phi(const long64& cellID) const;
+	double phi(const CellID& cellID) const;
 	/// access the number of bins in theta
 	int thetaBins() const {
 		return _thetaBins;
@@ -79,9 +79,9 @@ public:
 
 protected:
 	/// the number of bins in theta
-	double _thetaBins;
+	int _thetaBins;
 	/// the number of bins in phi
-	double _phiBins;
+	int _phiBins;
 	/// the coordinate offset in theta
 	double _offsetTheta;
 	/// the coordinate offset in phi
@@ -90,6 +90,12 @@ protected:
 	std::string _thetaID;
 	/// the field name used for phi
 	std::string _phiID;
+
+	/// determine the polar angle theta based on the current cell ID
+	double theta() const;
+	/// determine the azimuthal angle phi based on the current cell ID
+	double phi() const;
+
 };
 
 } /* namespace DDSegmentation */
diff --git a/DDSegmentation/src/ProjectiveCylinder.cpp b/DDSegmentation/src/ProjectiveCylinder.cpp
index 41878e1f1..84fcfd2e4 100644
--- a/DDSegmentation/src/ProjectiveCylinder.cpp
+++ b/DDSegmentation/src/ProjectiveCylinder.cpp
@@ -26,8 +26,8 @@ ProjectiveCylinder::ProjectiveCylinder(const string& cellEncoding) :
 	_description = "Projective segmentation in the global coordinates";
 
 	// register all necessary parameters
-	registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1.);
-	registerParameter("phi_bins", "Number of bins phi", _phiBins, 1.);
+	registerParameter("theta_bins", "Number of bins theta", _thetaBins, 1);
+	registerParameter("phi_bins", "Number of bins phi", _phiBins, 1);
 	registerParameter("offset_theta", "Angular offset in theta", _offsetTheta, 0., SegmentationParameter::AngleUnit, true);
 	registerParameter("offset_phi", "Angular offset in phi", _offsetPhi, 0., SegmentationParameter::AngleUnit, true);
 	registerIdentifier("identifier_theta", "Cell ID identifier for theta", _thetaID, "theta");
@@ -40,12 +40,13 @@ ProjectiveCylinder::~ProjectiveCylinder() {
 }
 
 /// determine the local based on the cell ID
-Vector3D ProjectiveCylinder::position(const long64& cID) const {
-	return Util::positionFromRThetaPhi(1.0, theta(cID), phi(cID));
+Vector3D ProjectiveCylinder::position(const CellID& cID) const {
+	_decoder->setValue(cID);
+	return Util::positionFromRThetaPhi(1.0, theta(), phi());
 }
 
 /// determine the cell ID based on the position
-  CellID ProjectiveCylinder::cellID(const Vector3D& /* localPosition */, const Vector3D& globalPosition, const VolumeID& vID) const {
+CellID ProjectiveCylinder::cellID(const Vector3D& /* localPosition */, const Vector3D& globalPosition, const VolumeID& vID) const {
 	_decoder->setValue(vID);
 	double lTheta = thetaFromXYZ(globalPosition);
 	double lPhi = phiFromXYZ(globalPosition);
@@ -54,14 +55,27 @@ Vector3D ProjectiveCylinder::position(const long64& cID) const {
 	return _decoder->getValue();
 }
 
+/// determine the polar angle theta based on the current cell ID
+double ProjectiveCylinder::theta() const {
+	CellID thetaIndex = (*_decoder)[_thetaID].value();
+	return M_PI * ((double) thetaIndex + 0.5) / (double) _thetaBins;
+}
+/// determine the azimuthal angle phi based on the current cell ID
+double ProjectiveCylinder::phi() const {
+	CellID phiIndex = (*_decoder)[_phiID].value();
+	return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
+}
+
 /// determine the polar angle theta based on the cell ID
-  double ProjectiveCylinder::theta(const long64& /* cellID */) const {
-	int thetaIndex = (*_decoder)[_thetaID].value();
+double ProjectiveCylinder::theta(const CellID& cID) const {
+	_decoder->setValue(cID);
+	CellID thetaIndex = (*_decoder)[_thetaID].value();
 	return M_PI * ((double) thetaIndex + 0.5) / (double) _thetaBins;
 }
 /// determine the azimuthal angle phi based on the cell ID
-  double ProjectiveCylinder::phi(const long64& /* cellID */) const {
-	int phiIndex = (*_decoder)[_phiID].value();
+double ProjectiveCylinder::phi(const CellID& cID) const {
+	_decoder->setValue(cID);
+	CellID phiIndex = (*_decoder)[_phiID].value();
 	return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
 }
 
-- 
GitLab