Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:16

0001 #ifndef DataFormats_Math_GeantUnits_h
0002 #define DataFormats_Math_GeantUnits_h
0003 
0004 // This file provides units represented with user-defined literals to more easily attach units to numerical values.
0005 // Units here are based upon Geant conventions: millimeter = 1, MeV = 1.
0006 // The CMS convention is that centimeter = 1 and GeV = 1, so care must be taken with code that converts between
0007 // the two conventions.
0008 
0009 #include "DataFormats/Math/interface/angle_units.h"
0010 
0011 namespace geant_units {
0012 
0013   using angle_units::piRadians;  // Needed by files the include this file
0014   constexpr double joule(6.24150e+12);
0015   constexpr double seconds(1.e+9);
0016   constexpr double nanoseconds(1.);
0017 
0018   namespace operators {
0019 
0020     // The following are needed by files that include this header
0021     // Since "using namespace" is prohibited in header files, each
0022     // name is individually imported with a "using" statement.
0023     using angle_units::operators::operator""_deg;
0024     using angle_units::operators::operator""_pi;
0025     using angle_units::operators::operator""_rad;
0026     using angle_units::operators::almostEqual;
0027     using angle_units::operators::convertDegToRad;
0028     using angle_units::operators::convertRadToDeg;
0029 
0030     // Length
0031     constexpr double operator"" _mm(long double length) { return length * 1.; }
0032     constexpr double operator"" _cm(long double length) { return length * 10.; }
0033     constexpr double operator"" _m(long double length) { return length * 1000.; }
0034     constexpr double operator"" _cm3(long double length) { return length * 1._cm * 1._cm * 1._cm; }
0035     constexpr double operator"" _m3(long double length) { return length * 1._m * 1._m * 1._m; }
0036     constexpr double operator"" _mm(unsigned long long int length) { return length * 1; }
0037     constexpr double operator"" _cm(unsigned long long int length) { return length * 10; }
0038 
0039     // Time
0040     constexpr double operator"" _s(long double x) { return x * seconds; }
0041     constexpr double operator"" _ns(long double x) { return x * nanoseconds; }
0042 
0043     // Energy
0044     constexpr double operator"" _MeV(long double energy) { return energy * 1.; }
0045     constexpr double operator"" _eV(long double energy) { return energy * 1.e-6_MeV; }
0046     constexpr double operator"" _TeV(long double energy) { return energy * 1.e6_MeV; }
0047     constexpr double operator"" _GeV(long double energy) { return energy * 1000._MeV; }
0048 
0049     // Mass
0050     constexpr double operator"" _kg(long double mass) {
0051       return mass * (1._eV / 1.602176487e-19) * 1._s * 1._s / (1._m * 1._m);
0052     }
0053     constexpr double operator"" _g(long double mass) { return mass * 1.e-3_kg; }
0054     constexpr double operator"" _mg(long double mass) { return mass * 1.e-3_g; }
0055     constexpr double operator"" _mole(long double mass) { return mass * 1.; }
0056 
0057     // Material properties
0058     constexpr double operator"" _mg_per_cm3(long double density) { return density * 1._mg / 1._cm3; }
0059     constexpr double operator"" _g_per_cm3(long double density) { return density * 1._g / 1._cm3; }
0060     constexpr double operator"" _g_per_mole(long double mass) { return mass * 1._g / 1._mole; }
0061 
0062     // Add these conversion functions to this namespace for convenience
0063     using angle_units::operators::convertCm2ToMm2;
0064     using angle_units::operators::convertCmToMm;
0065     using angle_units::operators::convertGeVToKeV;
0066     using angle_units::operators::convertGeVToMeV;
0067     using angle_units::operators::convertMeVToGeV;
0068     using angle_units::operators::convertMm3ToM3;
0069     using angle_units::operators::convertMmToCm;
0070 
0071     // Convert Geant units to desired units
0072     template <class NumType>
0073     inline constexpr NumType convertUnitsTo(double desiredUnits, NumType val) {
0074       return (val / desiredUnits);
0075     }
0076   }  // namespace operators
0077 }  // namespace geant_units
0078 
0079 #endif