DD4hep  1.31.0
Detector Description Toolkit for High Energy Physics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
25 namespace dd4hep {
26 namespace DDSegmentation {
27 namespace Util {
28 
35 
36 
40 
41 
43 inline double magFromXYZ(const Vector3D& position) {
44  return std::sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z);
45 }
46 
48 inline double radiusFromXYZ(const Vector3D& position) {
49  return std::sqrt(position.X * position.X + position.Y * position.Y);
50 }
51 
53 inline double cosThetaFromXYZ(const Vector3D& position) {
54  return position.Z / magFromXYZ(position);
55 }
56 
58 inline double thetaFromXYZ(const Vector3D& position) {
59  return std::acos(cosThetaFromXYZ(position));
60 }
61 
63 inline double phiFromXYZ(const Vector3D& position) {
64  return std::atan2(position.Y, position.X);
65 }
66 
68 // implementation taken from ROOT TVector3D
69 inline double etaFromXYZ(const Vector3D& aposition) {
70  double cosTheta = cosThetaFromXYZ(aposition);
71  if (cosTheta*cosTheta < 1) return -0.5* std::log((1.0-cosTheta)/(1.0+cosTheta));
72  if (aposition.Z == 0) return 0;
73  //Warning("PseudoRapidity","transvers momentum = 0! return +/- 10e10");
74  if (aposition.Z > 0) return 10e10;
75  else return -10e10;
76 }
77 
81 
83 inline Vector3D positionFromRPhiZ(double r, double phi, double z) {
84  return Vector3D(r * std::cos(phi), r * std::sin(phi), z);
85 }
86 
88 inline double magFromRPhiZ(double r, double /* phi */, double z) {
89  return std::sqrt(r * r + z * z);
90 }
91 
93 inline double xFromRPhiZ(double r, double phi, double /* z */) {
94  return r * std::cos(phi);
95 }
96 
98 inline double yFromRPhiZ(double r, double phi, double /* z */) {
99  return r * std::sin(phi);
100 }
101 
103 inline double thetaFromRPhiZ(double r, double /* phi */, double z) {
104  return r * std::atan(z / r);
105 }
106 
110 
112 inline Vector3D positionFromRThetaPhi(double r, double theta, double phi) {
113  return Vector3D(r * std::cos(phi), r * std::sin(phi), r * std::tan(theta));
114 }
115 
117 inline Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) {
118  double r = mag * sin(theta);
119  return Vector3D(r * std::cos(phi), r * std::sin(phi), mag * std::cos(theta));
120 }
122 inline Vector3D positionFromREtaPhi(double ar, double aeta, double aphi) {
123  return Vector3D(ar * std::cos(aphi), ar * std::sin(aphi), ar * std::sinh(aeta));
124 }
125 
126 
127 } /* namespace Util */
128 } /* namespace DDSegmentation */
129 } /* namespace dd4hep */
130 
131 #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:112
dd4hep::DDSegmentation::Util::positionFromRPhiZ
Vector3D positionFromRPhiZ(double r, double phi, double z)
Conversions from cylindrical to Cartesian coordinates ///.
Definition: SegmentationUtil.h:83
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:47
dd4hep::DDSegmentation::Util::radiusFromXYZ
double radiusFromXYZ(const Vector3D &position)
calculates the radius in the xy-plane from Cartesian coordinates
Definition: SegmentationUtil.h:48
dd4hep::DDSegmentation::Util::cosThetaFromXYZ
double cosThetaFromXYZ(const Vector3D &position)
Calculates cosine of the polar angle theat from Cartesian coodinates.
Definition: SegmentationUtil.h:53
dd4hep::DDSegmentation::Util::thetaFromXYZ
double thetaFromXYZ(const Vector3D &position)
calculates the polar angle theta from Cartesian coordinates
Definition: SegmentationUtil.h:58
dd4hep::DDSegmentation::Util::magFromXYZ
double magFromXYZ(const Vector3D &position)
Conversions from Cartesian to cylindrical/spherical coordinates ///.
Definition: SegmentationUtil.h:43
dd4hep::DDSegmentation::Util::yFromRPhiZ
double yFromRPhiZ(double r, double phi, double)
calculates y from cylindrical coordinates
Definition: SegmentationUtil.h:98
dd4hep::DDSegmentation::Util::positionFromMagThetaPhi
Vector3D positionFromMagThetaPhi(double mag, double theta, double phi)
calculates the Cartesian position from spherical coordinates
Definition: SegmentationUtil.h:117
dd4hep::DDSegmentation::Util::phiFromXYZ
double phiFromXYZ(const Vector3D &position)
calculates the azimuthal angle phi from Cartesian coordinates
Definition: SegmentationUtil.h:63
dd4hep::DDSegmentation::Vector3D::Y
double Y
Definition: Segmentation.h:70
dd4hep::DDSegmentation::Util::thetaFromRPhiZ
double thetaFromRPhiZ(double r, double, double z)
calculates the polar angle theta from cylindrical coordinates
Definition: SegmentationUtil.h:103
dd4hep::DDSegmentation::Util::xFromRPhiZ
double xFromRPhiZ(double r, double phi, double)
calculates x from cylindrical coordinates
Definition: SegmentationUtil.h:93
dd4hep::DDSegmentation::Vector3D::X
double X
Definition: Segmentation.h:70
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:122
dd4hep::DDSegmentation::Util::magFromRPhiZ
double magFromRPhiZ(double r, double, double z)
calculates the radius in xyz from cylindrical coordinates
Definition: SegmentationUtil.h:88
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:69
dd4hep::DDSegmentation::Vector3D::Z
double Z
Definition: Segmentation.h:70