diff --git a/DDSegmentation/include/DDSegmentation/SegmentationUtil.h b/DDSegmentation/include/DDSegmentation/SegmentationUtil.h index 1c539bbec433c6aa1477625eb4692fc707ece0c3..f147c9ce5fec087cf4a7656017e6fc0a8f857a09 100644 --- a/DDSegmentation/include/DDSegmentation/SegmentationUtil.h +++ b/DDSegmentation/include/DDSegmentation/SegmentationUtil.h @@ -11,6 +11,8 @@ #include <cmath> #include <vector> +#include "TVector3.h" + namespace DD4hep { namespace DDSegmentation { namespace Util { @@ -29,22 +31,22 @@ namespace Util { /// calculates the radius in xyz from Cartesian coordinates -double magFromXYZ(const Vector3D& position) { +inline double magFromXYZ(const Vector3D& position) { return std::sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z); } /// calculates the radius in the xy-plane from Cartesian coordinates -double radiusFromXYZ(const Vector3D& position) { +inline double radiusFromXYZ(const Vector3D& position) { return std::sqrt(position.X * position.X + position.Y * position.Y); } /// calculates the polar angle theta from Cartesian coordinates -double thetaFromXYZ(const Vector3D& position) { +inline double thetaFromXYZ(const Vector3D& position) { return std::acos(position.Z / radiusFromXYZ(position)); } /// calculates the azimuthal angle phi from Cartesian coordinates -double phiFromXYZ(const Vector3D& position) { +inline double phiFromXYZ(const Vector3D& position) { return std::atan2(position.Y, position.X); } @@ -53,27 +55,27 @@ double phiFromXYZ(const Vector3D& position) { ///////////////////////////////////////////////////////////// /// calculates the Cartesian position from cylindrical coordinates -Vector3D positionFromRPhiZ(double r, double phi, double z) { +inline Vector3D positionFromRPhiZ(double r, double phi, double z) { return Vector3D(r * std::cos(phi), r * std::sin(phi), z); } /// calculates the radius in xyz from cylindrical coordinates -double magFromRPhiZ(double r, double /* phi */, double z) { +inline double magFromRPhiZ(double r, double /* phi */, double z) { return std::sqrt(r * r + z * z); } /// calculates x from cylindrical coordinates -double xFromRPhiZ(double r, double phi, double /* z */) { +inline double xFromRPhiZ(double r, double phi, double /* z */) { return r * std::cos(phi); } /// calculates y from cylindrical coordinates -double yFromRPhiZ(double r, double phi, double /* z */) { +inline double yFromRPhiZ(double r, double phi, double /* z */) { return r * std::sin(phi); } /// calculates the polar angle theta from cylindrical coordinates -double thetaFromRPhiZ(double r, double /* phi */, double z) { +inline double thetaFromRPhiZ(double r, double /* phi */, double z) { return r * std::atan(z / r); } @@ -82,15 +84,26 @@ double thetaFromRPhiZ(double r, double /* phi */, double z) { ///////////////////////////////////////////////////////////// /// calculates the Cartesian position from spherical coordinates -Vector3D positionFromRThetaPhi(double r, double theta, double phi) { +inline Vector3D positionFromRThetaPhi(double r, double theta, double phi) { return Vector3D(r * std::cos(phi), r * std::sin(phi), r * std::tan(theta)); } /// calculates the Cartesian position from spherical coordinates -Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) { +inline Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) { double r = mag * sin(theta); return Vector3D(r * std::cos(phi), r * std::sin(phi), mag * std::cos(theta)); } +/// calculates the Cartesian position from spherical coordinates (r, phi, eta) +inline Vector3D positionFromREtaPhi(double ar, double aeta, double aphi) { + return Vector3D(ar * std::cos(aphi), ar * std::sin(aphi), ar * std::sinh(aeta)); +} + +/// calculates the pseudorapidity from Cartesian coordinates +inline double etaFromXYZ(const Vector3D& aposition) { + TVector3 vec(aposition.X, aposition.Y, aposition.Z); + return vec.Eta(); +} + } /* namespace Util */ } /* namespace DDSegmentation */