File indexing completed on 2025-01-18 09:55:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef DDSEGMENTATION_SEGMENTATIONUTIL_H
0019 #define DDSEGMENTATION_SEGMENTATIONUTIL_H
0020
0021 #include <DDSegmentation/Segmentation.h>
0022
0023 #include <cmath>
0024 #include <vector>
0025
0026 namespace dd4hep {
0027 namespace DDSegmentation {
0028 namespace Util {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 inline double magFromXYZ(const Vector3D& position) {
0045 return std::sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z);
0046 }
0047
0048
0049 inline double radiusFromXYZ(const Vector3D& position) {
0050 return std::sqrt(position.X * position.X + position.Y * position.Y);
0051 }
0052
0053
0054 inline double cosThetaFromXYZ(const Vector3D& position) {
0055 return position.Z / magFromXYZ(position);
0056 }
0057
0058
0059 inline double thetaFromXYZ(const Vector3D& position) {
0060 return std::acos(cosThetaFromXYZ(position));
0061 }
0062
0063
0064 inline double phiFromXYZ(const Vector3D& position) {
0065 return std::atan2(position.Y, position.X);
0066 }
0067
0068
0069
0070 inline double etaFromXYZ(const Vector3D& aposition) {
0071 double cosTheta = cosThetaFromXYZ(aposition);
0072 if (cosTheta*cosTheta < 1) return -0.5* std::log((1.0-cosTheta)/(1.0+cosTheta));
0073 if (aposition.Z == 0) return 0;
0074
0075 if (aposition.Z > 0) return 10e10;
0076 else return -10e10;
0077 }
0078
0079
0080
0081
0082
0083
0084 inline Vector3D positionFromRPhiZ(double r, double phi, double z) {
0085 return Vector3D(r * std::cos(phi), r * std::sin(phi), z);
0086 }
0087
0088
0089 inline double magFromRPhiZ(double r, double , double z) {
0090 return std::sqrt(r * r + z * z);
0091 }
0092
0093
0094 inline double xFromRPhiZ(double r, double phi, double ) {
0095 return r * std::cos(phi);
0096 }
0097
0098
0099 inline double yFromRPhiZ(double r, double phi, double ) {
0100 return r * std::sin(phi);
0101 }
0102
0103
0104 inline double thetaFromRPhiZ(double r, double , double z) {
0105 return r * std::atan(z / r);
0106 }
0107
0108
0109
0110
0111
0112
0113 inline Vector3D positionFromRThetaPhi(double r, double theta, double phi) {
0114 return Vector3D(r * std::cos(phi), r * std::sin(phi), r * std::tan(theta));
0115 }
0116
0117
0118 inline Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) {
0119 double r = mag * sin(theta);
0120 return Vector3D(r * std::cos(phi), r * std::sin(phi), mag * std::cos(theta));
0121 }
0122
0123 inline Vector3D positionFromREtaPhi(double ar, double aeta, double aphi) {
0124 return Vector3D(ar * std::cos(aphi), ar * std::sin(aphi), ar * std::sinh(aeta));
0125 }
0126
0127
0128 }
0129 }
0130 }
0131
0132 #endif