DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
SegmentationUtil.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 /*
12  * SegmentationUtil.h
13  *
14  * Created on: Oct 31, 2013
15  * Author: Christian Grefe, CERN
16  */
17 
18 #ifndef DDSEGMENTATION_SEGMENTATIONUTIL_H
19 #define DDSEGMENTATION_SEGMENTATIONUTIL_H
20 
22 
23 #include <cmath>
24 #include <vector>
25 
26 namespace dd4hep {
27 namespace DDSegmentation {
28 namespace Util {
29 
36 
37 
41 
42 
44 inline double magFromXYZ(const Vector3D& position) {
45  return std::sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z);
46 }
47 
49 inline double radiusFromXYZ(const Vector3D& position) {
50  return std::sqrt(position.X * position.X + position.Y * position.Y);
51 }
52 
54 inline double cosThetaFromXYZ(const Vector3D& position) {
55  return position.Z / magFromXYZ(position);
56 }
57 
59 inline double thetaFromXYZ(const Vector3D& position) {
60  return std::acos(cosThetaFromXYZ(position));
61 }
62 
64 inline double phiFromXYZ(const Vector3D& position) {
65  return std::atan2(position.Y, position.X);
66 }
67 
69 // implementation taken from ROOT TVector3D
70 inline double etaFromXYZ(const Vector3D& aposition) {
71  double cosTheta = cosThetaFromXYZ(aposition);
72  if (cosTheta*cosTheta < 1) return -0.5* std::log((1.0-cosTheta)/(1.0+cosTheta));
73  if (aposition.Z == 0) return 0;
74  //Warning("PseudoRapidity","transvers momentum = 0! return +/- 10e10");
75  if (aposition.Z > 0) return 10e10;
76  else return -10e10;
77 }
78 
82 
84 inline Vector3D positionFromRPhiZ(double r, double phi, double z) {
85  return Vector3D(r * std::cos(phi), r * std::sin(phi), z);
86 }
87 
89 inline double magFromRPhiZ(double r, double /* phi */, double z) {
90  return std::sqrt(r * r + z * z);
91 }
92 
94 inline double xFromRPhiZ(double r, double phi, double /* z */) {
95  return r * std::cos(phi);
96 }
97 
99 inline double yFromRPhiZ(double r, double phi, double /* z */) {
100  return r * std::sin(phi);
101 }
102 
104 inline double thetaFromRPhiZ(double r, double /* phi */, double z) {
105  return r * std::atan(z / r);
106 }
107 
111 
113 inline Vector3D positionFromRThetaPhi(double r, double theta, double phi) {
114  return Vector3D(r * std::cos(phi), r * std::sin(phi), r * std::tan(theta));
115 }
116 
118 inline Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) {
119  double r = mag * sin(theta);
120  return Vector3D(r * std::cos(phi), r * std::sin(phi), mag * std::cos(theta));
121 }
123 inline Vector3D positionFromREtaPhi(double ar, double aeta, double aphi) {
124  return Vector3D(ar * std::cos(aphi), ar * std::sin(aphi), ar * std::sinh(aeta));
125 }
126 
127 
128 } /* namespace Util */
129 } /* namespace DDSegmentation */
130 } /* namespace dd4hep */
131 
132 #endif // DDSEGMENTATION_SEGMENTATIONUTIL_H
dd4hep::DDSegmentation::Util::positionFromRThetaPhi
Vector3D positionFromRThetaPhi(double r, double theta, double phi)
Conversions from spherical to Cartesian coordinates ///.
Definition: SegmentationUtil.h:113
dd4hep::DDSegmentation::Util::positionFromRPhiZ
Vector3D positionFromRPhiZ(double r, double phi, double z)
Conversions from cylindrical to Cartesian coordinates ///.
Definition: SegmentationUtil.h:84
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
dd4hep::DDSegmentation::Util::radiusFromXYZ
double radiusFromXYZ(const Vector3D &position)
calculates the radius in the xy-plane from Cartesian coordinates
Definition: SegmentationUtil.h:49
dd4hep::DDSegmentation::Util::cosThetaFromXYZ
double cosThetaFromXYZ(const Vector3D &position)
Calculates cosine of the polar angle theat from Cartesian coodinates.
Definition: SegmentationUtil.h:54
dd4hep::DDSegmentation::Util::thetaFromXYZ
double thetaFromXYZ(const Vector3D &position)
calculates the polar angle theta from Cartesian coordinates
Definition: SegmentationUtil.h:59
dd4hep::DDSegmentation::Util::magFromXYZ
double magFromXYZ(const Vector3D &position)
Conversions from Cartesian to cylindrical/spherical coordinates ///.
Definition: SegmentationUtil.h:44
dd4hep::DDSegmentation::Util::yFromRPhiZ
double yFromRPhiZ(double r, double phi, double)
calculates y from cylindrical coordinates
Definition: SegmentationUtil.h:99
dd4hep::DDSegmentation::Util::positionFromMagThetaPhi
Vector3D positionFromMagThetaPhi(double mag, double theta, double phi)
calculates the Cartesian position from spherical coordinates
Definition: SegmentationUtil.h:118
dd4hep::DDSegmentation::Util::phiFromXYZ
double phiFromXYZ(const Vector3D &position)
calculates the azimuthal angle phi from Cartesian coordinates
Definition: SegmentationUtil.h:64
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Util::thetaFromRPhiZ
double thetaFromRPhiZ(double r, double, double z)
calculates the polar angle theta from cylindrical coordinates
Definition: SegmentationUtil.h:104
dd4hep::DDSegmentation::Util::xFromRPhiZ
double xFromRPhiZ(double r, double phi, double)
calculates x from cylindrical coordinates
Definition: SegmentationUtil.h:94
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:71
dd4hep::DDSegmentation::Util::positionFromREtaPhi
Vector3D positionFromREtaPhi(double ar, double aeta, double aphi)
calculates the Cartesian position from spherical coordinates (r, phi, eta)
Definition: SegmentationUtil.h:123
dd4hep::DDSegmentation::Util::magFromRPhiZ
double magFromRPhiZ(double r, double, double z)
calculates the radius in xyz from cylindrical coordinates
Definition: SegmentationUtil.h:89
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
Segmentation.h
dd4hep::DDSegmentation::Util::etaFromXYZ
double etaFromXYZ(const Vector3D &aposition)
calculates the pseudorapidity from Cartesian coordinates
Definition: SegmentationUtil.h:70
dd4hep::DDSegmentation::Vector3D::Z
double Z
Definition: Segmentation.h:71