CMS 3D CMS Logo

CMSUnits.h
Go to the documentation of this file.
1 #ifndef DataFormats_Math_CMS_Units_h
2 #define DataFormats_Math_CMS_Units_h
3 
4 // This file provides units represented with user-defined literals to more easily attach units to numerical values.
5 // The CMS convention is that centimeter = 1 and GeV = 1
6 
8 
9 namespace cms_units {
10 
11  using angle_units::piRadians; // Needed by files the include this file
12 
13  namespace operators {
14 
15  // The following are needed by files that include this header
16  // Since "using namespace" is prohibited in header files, each
17  // name is individually imported with a "using" statement.
24 
25  // Length
26  constexpr double operator"" _mm(long double length) { return length * 0.1; }
27  constexpr double operator"" _cm(long double length) { return length * 1.; }
28  constexpr double operator"" _m(long double length) { return length * 100.; }
29  constexpr double operator"" _cm3(long double length) { return length * 1._cm * 1._cm * 1._cm; }
30  constexpr double operator"" _m3(long double length) { return length * 1._m * 1._m * 1._m; }
31  constexpr double operator"" _mm(unsigned long long int length) { return length * 0.1; }
32  constexpr double operator"" _cm(unsigned long long int length) { return length * 1; }
33 
34  // Energy
35  constexpr double operator"" _GeV(long double energy) { return energy * 1.; }
36  constexpr double operator"" _eV(long double energy) { return energy * 1.e-9_GeV; }
37  constexpr double operator"" _MeV(long double energy) { return energy * 1.e-3_GeV; }
38  constexpr double operator"" _TeV(long double energy) { return energy * 1.e3_GeV; }
39 
40  // Add these conversion functions to this namespace for convenience
48 
49  } // namespace operators
50 } // namespace cms_units
51 
52 #endif
constexpr NumType convertCm2ToMm2(NumType centimeters)
Definition: angle_units.h:56
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
constexpr NumType convertCmToMm(NumType centimeters)
Definition: angle_units.h:50
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
std::enable_if<!std::numeric_limits< NumType >::is_integer, bool >::type almostEqual(NumType x, NumType y, int ulp)
Definition: angle_units.h:33
constexpr NumType convertMeVToGeV(NumType mev)
Definition: angle_units.h:68
constexpr NumType convertGeVToMeV(NumType gev)
Definition: angle_units.h:74
constexpr NumType convertMm3ToM3(NumType mm3)
Definition: angle_units.h:62
constexpr NumType convertGeVToKeV(NumType gev)
Definition: angle_units.h:80
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
constexpr double piRadians(M_PI)