Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27637 from ianna/cms-units-v1
Define and use cms units
- Loading branch information
Showing
8 changed files
with
79 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef DataFormats_Math_CMS_Units_h | ||
#define DataFormats_Math_CMS_Units_h | ||
|
||
// This file provides units represented with user-defined literals to more easily attach units to numerical values. | ||
// The CMS convention is that centimeter = 1 and GeV = 1 | ||
|
||
#include "DataFormats/Math/interface/angle_units.h" | ||
|
||
namespace cms_units { | ||
|
||
using angle_units::piRadians; // Needed by files the include this file | ||
|
||
namespace operators { | ||
|
||
// The following are needed by files that include this header | ||
// Since "using namespace" is prohibited in header files, each | ||
// name is individually imported with a "using" statement. | ||
using angle_units::operators::operator""_deg; | ||
using angle_units::operators::operator""_pi; | ||
using angle_units::operators::operator""_rad; | ||
using angle_units::operators::convertDegToRad; | ||
using angle_units::operators::convertRadToDeg; | ||
|
||
// Length | ||
constexpr double operator"" _mm(long double length) { return length * 0.1; } | ||
constexpr double operator"" _cm(long double length) { return length * 1.; } | ||
constexpr double operator"" _m(long double length) { return length * 100.; } | ||
constexpr double operator"" _cm3(long double length) { return length * 1._cm * 1._cm * 1._cm; } | ||
constexpr double operator"" _m3(long double length) { return length * 1._m * 1._m * 1._m; } | ||
constexpr double operator"" _mm(unsigned long long int length) { return length * 0.1; } | ||
constexpr double operator"" _cm(unsigned long long int length) { return length * 1; } | ||
|
||
} // namespace operators | ||
} // namespace cms_units | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef DataFormats_Math_Angle_Units_h | ||
#define DataFormats_Math_Angle_Units_h | ||
|
||
#include <cmath> | ||
|
||
namespace angle_units { | ||
|
||
constexpr long double piRadians(M_PIl); // M_PIl is long double version of pi | ||
constexpr long double degPerRad = 180. / piRadians; // Degrees per radian | ||
|
||
namespace operators { | ||
|
||
// Angle | ||
constexpr long double operator"" _pi(long double x) { return x * piRadians; } | ||
constexpr long double operator"" _pi(unsigned long long int x) { return x * piRadians; } | ||
constexpr long double operator"" _deg(long double deg) { return deg / degPerRad; } | ||
constexpr long double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; } | ||
constexpr long double operator"" _rad(long double rad) { return rad * 1.; } | ||
|
||
template <class NumType> | ||
inline constexpr NumType convertRadToDeg(NumType radians) // Radians -> degrees | ||
{ | ||
return (radians * degPerRad); | ||
} | ||
|
||
template <class NumType> | ||
inline constexpr long double convertDegToRad(NumType degrees) // Degrees -> radians | ||
{ | ||
return (degrees / degPerRad); | ||
} | ||
} // namespace operators | ||
} // namespace angle_units | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters