CMS 3D CMS Logo

GeantUnits.h
Go to the documentation of this file.
1 #ifndef DataFormats_Math_GeantUnits_h
2 #define DataFormats_Math_GeantUnits_h
3 
4 // This file provides units represented with user-defined literals to more easily attach units to numerical values.
5 // Units here are based upon Geant conventions: millimeter = 1, MeV = 1.
6 // The CMS convention is that centimeter = 1 and GeV = 1, so care must be taken with code that converts between
7 // the two conventions.
8 
10 
11 namespace geant_units {
12 
13  using angle_units::piRadians; // Needed by files the include this file
14  constexpr double joule(6.24150e+12);
15  constexpr double seconds(1.e+9);
16  constexpr double nanoseconds(1.);
17 
18  namespace operators {
19 
20  // The following are needed by files that include this header
21  // Since "using namespace" is prohibited in header files, each
22  // name is individually imported with a "using" statement.
29 
30  // Length
31  constexpr double operator"" _mm(long double length) { return length * 1.; }
32  constexpr double operator"" _cm(long double length) { return length * 10.; }
33  constexpr double operator"" _m(long double length) { return length * 1000.; }
34  constexpr double operator"" _cm3(long double length) { return length * 1._cm * 1._cm * 1._cm; }
35  constexpr double operator"" _m3(long double length) { return length * 1._m * 1._m * 1._m; }
36  constexpr double operator"" _mm(unsigned long long int length) { return length * 1; }
37  constexpr double operator"" _cm(unsigned long long int length) { return length * 10; }
38 
39  // Time
40  constexpr double operator"" _s(long double x) { return x * seconds; }
41  constexpr double operator"" _ns(long double x) { return x * nanoseconds; }
42 
43  // Energy
44  constexpr double operator"" _MeV(long double energy) { return energy * 1.; }
45  constexpr double operator"" _eV(long double energy) { return energy * 1.e-6_MeV; }
46  constexpr double operator"" _TeV(long double energy) { return energy * 1.e6_MeV; }
47  constexpr double operator"" _GeV(long double energy) { return energy * 1000._MeV; }
48 
49  // Mass
50  constexpr double operator"" _kg(long double mass) {
51  return mass * (1._eV / 1.602176487e-19) * 1._s * 1._s / (1._m * 1._m);
52  }
53  constexpr double operator"" _g(long double mass) { return mass * 1.e-3_kg; }
54  constexpr double operator"" _mg(long double mass) { return mass * 1.e-3_g; }
55  constexpr double operator"" _mole(long double mass) { return mass * 1.; }
56 
57  // Material properties
58  constexpr double operator"" _mg_per_cm3(long double density) { return density * 1._mg / 1._cm3; }
59  constexpr double operator"" _g_per_cm3(long double density) { return density * 1._g / 1._cm3; }
60  constexpr double operator"" _g_per_mole(long double mass) { return mass * 1._g / 1._mole; }
61 
62  template <class NumType>
63  inline constexpr NumType convertMmToCm(NumType millimeters) // Millimeters -> centimeters
64  {
65  return (millimeters / 10.);
66  }
67 
68  template <class NumType>
69  inline constexpr NumType convertCmToMm(NumType centimeters) // Centimeters -> Milliimeters
70  {
71  return (centimeters * 10.);
72  }
73 
74  template <class NumType>
75  inline constexpr NumType convertCm2ToMm2(NumType centimeters) // Centimeters^2 -> Milliimeters^2
76  {
77  return (centimeters * 100.);
78  }
79 
80  template <class NumType>
81  inline constexpr NumType convertMm3ToM3(NumType mm3) // Cubic millimeters -> cubic meters
82  {
83  return (mm3 / 1.e9);
84  }
85 
86  template <class NumType>
87  inline constexpr NumType convertMeVToGeV(NumType mev) // MeV -> GeV
88  {
89  return (mev * 0.001);
90  }
91 
92  template <class NumType>
93  inline constexpr NumType convertGeVToMeV(NumType gev) // GeV -> MeV
94  {
95  return (gev * 1000.);
96  }
97 
98  // Convert Geant units to desired units
99  template <class NumType>
100  inline constexpr NumType convertUnitsTo(double desiredUnits, NumType val) {
101  return (val / desiredUnits);
102  }
103  } // namespace operators
104 } // namespace geant_units
105 
106 #endif
angle_units::operators::convertDegToRad
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
geant_units::operators::convertCm2ToMm2
constexpr NumType convertCm2ToMm2(NumType centimeters)
Definition: GeantUnits.h:75
geant_units::operators::convertMeVToGeV
constexpr NumType convertMeVToGeV(NumType mev)
Definition: GeantUnits.h:87
geant_units::joule
constexpr double joule(6.24150e+12)
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
angle_units::operators::almostEqual
std::enable_if<!std::numeric_limits< NumType >::is_integer, bool >::type almostEqual(NumType x, NumType y, int ulp)
Definition: angle_units.h:33
Utilities.operator
operator
Definition: Utilities.py:24
geant_units::operators::convertGeVToMeV
constexpr NumType convertGeVToMeV(NumType gev)
Definition: GeantUnits.h:93
hgcalDigitizer_cfi._m
_m
Definition: hgcalDigitizer_cfi.py:211
geant_units::operators::convertUnitsTo
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
Definition: GeantUnits.h:100
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
geant_units::operators::convertCmToMm
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:69
geant_units::seconds
constexpr double seconds(1.e+9)
heppy_batch.val
val
Definition: heppy_batch.py:351
geant_units::operators::convertMm3ToM3
constexpr NumType convertMm3ToM3(NumType mm3)
Definition: GeantUnits.h:81
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
angle_units::piRadians
constexpr double piRadians(M_PI)
geant_units::operators::convertMmToCm
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:63
geant_units
Definition: GeantUnits.h:11
angle_units.h
geant_units::nanoseconds
constexpr double nanoseconds(1.)
fastSimProducer_cff.density
density
Definition: fastSimProducer_cff.py:61
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37