![]() |
|
|||
File indexing completed on 2025-07-14 08:50:36
0001 //========================================================================== 0002 // AIDA Detector description implementation 0003 //-------------------------------------------------------------------------- 0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) 0005 // All rights reserved. 0006 // 0007 // For the licensing terms see $DD4hepINSTALL/LICENSE. 0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS. 0009 // 0010 //========================================================================== 0011 /* 0012 * SegmentationUtil.h 0013 * 0014 * Created on: Oct 31, 2013 0015 * Author: Christian Grefe, CERN 0016 */ 0017 0018 #ifndef DDSEGMENTATION_SEGMENTATIONUTIL_H 0019 #define DDSEGMENTATION_SEGMENTATIONUTIL_H 0020 0021 #include <DDSegmentation/Segmentation.h> 0022 0023 #include <cmath> 0024 0025 namespace dd4hep { 0026 namespace DDSegmentation { 0027 namespace Util { 0028 0029 /////////////////////////////////////////////////////////////////////// 0030 /// Conventions /// 0031 /// - x, y, z are the Cartesian coordinates /// 0032 /// - r is the magnitude in the xy-plane /// 0033 /// - mag is the magnitude /// 0034 /////////////////////////////////////////////////////////////////////// 0035 0036 0037 /////////////////////////////////////////////////////////////////////// 0038 /// Conversions from Cartesian to cylindrical/spherical coordinates /// 0039 /////////////////////////////////////////////////////////////////////// 0040 0041 0042 /// calculates the radius in xyz from Cartesian coordinates 0043 inline double magFromXYZ(const Vector3D& position) { 0044 return std::sqrt(position.X * position.X + position.Y * position.Y + position.Z * position.Z); 0045 } 0046 0047 /// calculates the radius in the xy-plane from Cartesian coordinates 0048 inline double radiusFromXYZ(const Vector3D& position) { 0049 return std::sqrt(position.X * position.X + position.Y * position.Y); 0050 } 0051 0052 /// Calculates cosine of the polar angle theat from Cartesian coodinates 0053 inline double cosThetaFromXYZ(const Vector3D& position) { 0054 return position.Z / magFromXYZ(position); 0055 } 0056 0057 /// calculates the polar angle theta from Cartesian coordinates 0058 inline double thetaFromXYZ(const Vector3D& position) { 0059 return std::acos(cosThetaFromXYZ(position)); 0060 } 0061 0062 /// calculates the azimuthal angle phi from Cartesian coordinates 0063 inline double phiFromXYZ(const Vector3D& position) { 0064 return std::atan2(position.Y, position.X); 0065 } 0066 0067 /// calculates the pseudorapidity from Cartesian coordinates 0068 // implementation taken from ROOT TVector3D 0069 inline double etaFromXYZ(const Vector3D& aposition) { 0070 double cosTheta = cosThetaFromXYZ(aposition); 0071 if (cosTheta*cosTheta < 1) return -0.5* std::log((1.0-cosTheta)/(1.0+cosTheta)); 0072 if (aposition.Z == 0) return 0; 0073 //Warning("PseudoRapidity","transvers momentum = 0! return +/- 10e10"); 0074 if (aposition.Z > 0) return 10e10; 0075 else return -10e10; 0076 } 0077 0078 ///////////////////////////////////////////////////////////// 0079 /// Conversions from cylindrical to Cartesian coordinates /// 0080 ///////////////////////////////////////////////////////////// 0081 0082 /// calculates the Cartesian position from cylindrical coordinates 0083 inline Vector3D positionFromRPhiZ(double r, double phi, double z) { 0084 return Vector3D(r * std::cos(phi), r * std::sin(phi), z); 0085 } 0086 0087 /// calculates the radius in xyz from cylindrical coordinates 0088 inline double magFromRPhiZ(double r, double /* phi */, double z) { 0089 return std::sqrt(r * r + z * z); 0090 } 0091 0092 /// calculates x from cylindrical coordinates 0093 inline double xFromRPhiZ(double r, double phi, double /* z */) { 0094 return r * std::cos(phi); 0095 } 0096 0097 /// calculates y from cylindrical coordinates 0098 inline double yFromRPhiZ(double r, double phi, double /* z */) { 0099 return r * std::sin(phi); 0100 } 0101 0102 /// calculates the polar angle theta from cylindrical coordinates 0103 inline double thetaFromRPhiZ(double r, double /* phi */, double z) { 0104 return r * std::atan(z / r); 0105 } 0106 0107 ///////////////////////////////////////////////////////////// 0108 /// Conversions from spherical to Cartesian coordinates /// 0109 ///////////////////////////////////////////////////////////// 0110 0111 /// calculates the Cartesian position from spherical coordinates 0112 inline Vector3D positionFromRThetaPhi(double r, double theta, double phi) { 0113 return Vector3D(r * std::cos(phi), r * std::sin(phi), r * std::tan(theta)); 0114 } 0115 0116 /// calculates the Cartesian position from spherical coordinates 0117 inline Vector3D positionFromMagThetaPhi(double mag, double theta, double phi) { 0118 double r = mag * sin(theta); 0119 return Vector3D(r * std::cos(phi), r * std::sin(phi), mag * std::cos(theta)); 0120 } 0121 /// calculates the Cartesian position from spherical coordinates (r, phi, eta) 0122 inline Vector3D positionFromREtaPhi(double ar, double aeta, double aphi) { 0123 return Vector3D(ar * std::cos(aphi), ar * std::sin(aphi), ar * std::sinh(aeta)); 0124 } 0125 0126 0127 } /* namespace Util */ 0128 } /* namespace DDSegmentation */ 0129 } /* namespace dd4hep */ 0130 0131 #endif // DDSEGMENTATION_SEGMENTATIONUTIL_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |