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 long double joule(6.24150e+12);
15  constexpr long double seconds(1.e+9);
16  constexpr long 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.
28 
29  // Length
30  constexpr long double operator"" _mm(long double length) { return length * 1.; }
31  constexpr long double operator"" _cm(long double length) { return length * 10.; }
32  constexpr long double operator"" _m(long double length) { return length * 1000.; }
33  constexpr long double operator"" _cm3(long double length) { return length * 1._cm * 1._cm * 1._cm; }
34  constexpr long double operator"" _m3(long double length) { return length * 1._m * 1._m * 1._m; }
35  constexpr long double operator"" _mm(unsigned long long int length) { return length * 1; }
36  constexpr long double operator"" _cm(unsigned long long int length) { return length * 10; }
37 
38  // Time
39  constexpr long double operator"" _s(long double x) { return x * seconds; }
40  constexpr long double operator"" _ns(long double x) { return x * nanoseconds; }
41 
42  // Energy
43  constexpr long double operator"" _MeV(long double energy) { return energy * 1.; }
44  constexpr long double operator"" _eV(long double energy) { return energy * 1.e-6_MeV; }
45  constexpr long double operator"" _TeV(long double energy) { return energy * 1.e6_MeV; }
46  constexpr long double operator"" _GeV(long double energy) { return energy * 1000._MeV; }
47 
48  // Mass
49  constexpr long double operator"" _kg(long double mass) {
50  return mass * (1._eV / 1.602176487e-19) * 1._s * 1._s / (1._m * 1._m);
51  }
52  constexpr long double operator"" _g(long double mass) { return mass * 1.e-3_kg; }
53  constexpr long double operator"" _mg(long double mass) { return mass * 1.e-3_g; }
54  constexpr long double operator"" _mole(long double mass) { return mass * 1.; }
55 
56  // Material properties
57  constexpr long double operator"" _mg_per_cm3(long double density) { return density * 1._mg / 1._cm3; }
58  constexpr long double operator"" _g_per_cm3(long double density) { return density * 1._g / 1._cm3; }
59  constexpr long double operator"" _g_per_mole(long double mass) { return mass * 1._g / 1._mole; }
60 
61  template <class NumType>
62  inline constexpr NumType convertMmToCm(NumType millimeters) // Millimeters -> centimeters
63  {
64  return (millimeters / 10.);
65  }
66 
67  template <class NumType>
68  inline constexpr NumType convertCmToMm(NumType centimeters) // Centimeters -> Milliimeters
69  {
70  return (centimeters * 10.);
71  }
72 
73  template <class NumType>
74  inline constexpr NumType convertCm2ToMm2(NumType centimeters) // Centimeters^2 -> Milliimeters^2
75  {
76  return (centimeters * 100.);
77  }
78 
79  template <class NumType>
80  inline constexpr NumType convertMm3ToM3(NumType mm3) // Cubic millimeters -> cubic meters
81  {
82  return (mm3 / 1.e9);
83  }
84 
85  template <class NumType>
86  inline constexpr NumType convertMeVToGeV(NumType mev) // MeV -> GeV
87  {
88  return (mev * 0.001);
89  }
90 
91  template <class NumType>
92  inline constexpr NumType convertGeVToMeV(NumType gev) // GeV -> MeV
93  {
94  return (gev * 1000.);
95  }
96 
97  // Convert Geant units to desired units
98  template <class NumType>
99  inline constexpr NumType convertUnitsTo(long double desiredUnits, NumType val) {
100  return (val / desiredUnits);
101  }
102  } // namespace operators
103 } // namespace geant_units
104 
105 #endif
geant_units::joule
constexpr long double joule(6.24150e+12)
geant_units::operators::convertCm2ToMm2
constexpr NumType convertCm2ToMm2(NumType centimeters)
Definition: GeantUnits.h:74
geant_units::operators::convertMeVToGeV
constexpr NumType convertMeVToGeV(NumType mev)
Definition: GeantUnits.h:86
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
geant_units::operators::convertUnitsTo
constexpr NumType convertUnitsTo(long double desiredUnits, NumType val)
Definition: GeantUnits.h:99
angle_units::operators::convertDegToRad
constexpr long double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
geant_units::seconds
constexpr long double seconds(1.e+9)
Utilities.operator
operator
Definition: Utilities.py:24
geant_units::operators::convertGeVToMeV
constexpr NumType convertGeVToMeV(NumType gev)
Definition: GeantUnits.h:92
hgcalDigitizer_cfi._m
_m
Definition: hgcalDigitizer_cfi.py:209
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
geant_units::nanoseconds
constexpr long double nanoseconds(1.)
angle_units::piRadians
constexpr long double piRadians(M_PIl)
geant_units::operators::convertCmToMm
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
heppy_batch.val
val
Definition: heppy_batch.py:351
geant_units::operators::convertMm3ToM3
constexpr NumType convertMm3ToM3(NumType mm3)
Definition: GeantUnits.h:80
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
geant_units::operators::convertMmToCm
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:62
geant_units
Definition: GeantUnits.h:11
angle_units.h
fastSimProducer_cff.density
density
Definition: fastSimProducer_cff.py:61
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37