Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:26

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 #include <vector>
0025 
0026 namespace dd4hep {
0027 namespace DDSegmentation {
0028 namespace Util {
0029 
0030 ///////////////////////////////////////////////////////////////////////
0031 ///           Conventions                                           ///
0032 /// - x, y, z are the Cartesian coordinates                         ///
0033 /// - r is the magnitude in the xy-plane                            ///
0034 /// - mag is the magnitude                                          ///
0035 ///////////////////////////////////////////////////////////////////////
0036 
0037 
0038 ///////////////////////////////////////////////////////////////////////
0039 /// Conversions from Cartesian to cylindrical/spherical coordinates ///
0040 ///////////////////////////////////////////////////////////////////////
0041 
0042 
0043 /// calculates the radius in xyz from Cartesian coordinates
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 /// calculates the radius in the xy-plane from Cartesian coordinates
0049 inline double radiusFromXYZ(const Vector3D& position) {
0050     return std::sqrt(position.X * position.X + position.Y * position.Y);
0051 }
0052 
0053 /// Calculates cosine of the polar angle theat from Cartesian coodinates
0054 inline double cosThetaFromXYZ(const Vector3D& position) {
0055     return position.Z / magFromXYZ(position);
0056 }
0057 
0058 /// calculates the polar angle theta from Cartesian coordinates
0059 inline double thetaFromXYZ(const Vector3D& position) {
0060     return std::acos(cosThetaFromXYZ(position));
0061 }
0062 
0063 /// calculates the azimuthal angle phi from Cartesian coordinates
0064 inline double phiFromXYZ(const Vector3D& position) {
0065     return std::atan2(position.Y, position.X);
0066 }
0067 
0068 /// calculates the pseudorapidity from Cartesian coordinates
0069 // implementation taken from ROOT TVector3D
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     //Warning("PseudoRapidity","transvers momentum = 0! return +/- 10e10");
0075     if (aposition.Z > 0) return 10e10;
0076     else return -10e10;
0077 }
0078 
0079 /////////////////////////////////////////////////////////////
0080 /// Conversions from cylindrical to Cartesian coordinates ///
0081 /////////////////////////////////////////////////////////////
0082 
0083 /// calculates the Cartesian position from cylindrical coordinates
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 /// calculates the radius in xyz from cylindrical coordinates
0089 inline double magFromRPhiZ(double r, double /* phi */, double z) {
0090     return std::sqrt(r * r + z * z);
0091 }
0092 
0093 /// calculates x from cylindrical coordinates
0094 inline double xFromRPhiZ(double r, double phi, double /* z */) {
0095     return r * std::cos(phi);
0096 }
0097 
0098 /// calculates y from cylindrical coordinates
0099 inline double yFromRPhiZ(double r, double phi, double /* z */) {
0100     return r * std::sin(phi);
0101 }
0102 
0103 /// calculates the polar angle theta from cylindrical coordinates
0104 inline double thetaFromRPhiZ(double r, double /* phi */, double z) {
0105     return r * std::atan(z / r);
0106 }
0107 
0108 /////////////////////////////////////////////////////////////
0109 /// Conversions from spherical to Cartesian coordinates   ///
0110 /////////////////////////////////////////////////////////////
0111 
0112 /// calculates the Cartesian position from spherical coordinates
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 /// calculates the Cartesian position from spherical coordinates
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 /// calculates the Cartesian position from spherical coordinates (r, phi, eta)
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 } /* namespace Util */
0129 } /* namespace DDSegmentation */
0130 } /* namespace dd4hep */
0131 
0132 #endif // DDSEGMENTATION_SEGMENTATIONUTIL_H