Skip to content

Commit

Permalink
Merge pull request #27637 from ianna/cms-units-v1
Browse files Browse the repository at this point in the history
Define and use cms units
  • Loading branch information
cmsbuild committed Aug 2, 2019
2 parents 8ff7a66 + 7c9d2ce commit 473cbe6
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 82 deletions.
1 change: 1 addition & 0 deletions DataFormats/GeometryVector/interface/Phi.h
Expand Up @@ -3,6 +3,7 @@

#include "DataFormats/GeometryVector/interface/Pi.h"
#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/Math/interface/angle_units.h"
#include <cmath>

namespace Geom {
Expand Down
36 changes: 36 additions & 0 deletions DataFormats/Math/interface/CMSUnits.h
@@ -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
2 changes: 1 addition & 1 deletion DataFormats/Math/interface/GeantUnits.h
Expand Up @@ -6,7 +6,7 @@
// The CMS convention is that centimeter = 1 and GeV = 1, so care must be taken with code that converts between
// the two conventions.

#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/Math/interface/angle_units.h"

namespace geant_units {

Expand Down
34 changes: 34 additions & 0 deletions DataFormats/Math/interface/angle_units.h
@@ -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
29 changes: 1 addition & 28 deletions DataFormats/Math/interface/deltaPhi.h
Expand Up @@ -9,6 +9,7 @@
*/

#include <cmath>
#include "DataFormats/Math/interface/angle_units.h"

namespace reco {

Expand Down Expand Up @@ -51,34 +52,6 @@ struct DeltaPhi {
}
};

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

namespace angle0to2pi {

using angle_units::operators::operator""_pi;
Expand Down
29 changes: 2 additions & 27 deletions Geometry/EcalCommonData/plugins/dd4hep/DDEcalBarrelNewAlgo.cc
@@ -1,7 +1,6 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/Printout.h"
// FIXME: use local definition until dd4hep fixes the uniits
//#include "DataFormats/Math/interface/GeantUnits.h"
#include "DataFormats/Math/interface/CMSUnits.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/BenchmarkGrd.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand All @@ -14,31 +13,7 @@
using namespace std;
using namespace cms;
using namespace dd4hep;

// FIXME: use local definition until dd4hep fixes the uniits
// using namespace geant_units::operators;

constexpr long double piRadians(M_PIl); // M_PIl is long double version of pi
constexpr long double degPerRad = 180. / piRadians; // Degrees per radian
constexpr double operator"" _deg(long double deg) { return deg / degPerRad; }
constexpr double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; }

// Length
constexpr double operator"" _mm(long double length) { return length * 0.1; }
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; }

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);
}
using namespace cms_units::operators;

using VecDouble = vector<double>;
using VecStr = vector<string>;
Expand Down
14 changes: 2 additions & 12 deletions Geometry/EcalCommonData/plugins/dd4hep/DDEcalEndcapAlgo.cc
@@ -1,6 +1,7 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/BenchmarkGrd.h"
#include "DataFormats/Math/interface/CMSUnits.h"
// Header files for endcap supercrystal geometry
#include "Geometry/EcalCommonData/interface/DDEcalEndcapTrap.h"
#include <CLHEP/Geometry/Transform3D.h>
Expand All @@ -11,18 +12,7 @@
using namespace std;
using namespace cms;
using namespace dd4hep;
// FIXME: use local definition until dd4hep fixes the uniits
// using namespace geant_units::operators;

constexpr long double piRadians(M_PIl); // M_PIl is long double version of pi
constexpr long double degPerRad = 180. / piRadians; // Degrees per radian
constexpr double operator"" _deg(long double deg) { return deg / degPerRad; }
constexpr double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; }

// Length
constexpr double operator"" _mm(long double length) { return length * 0.1; }
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; }
using namespace cms_units::operators;

using DDTranslation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
using DDRotation = ROOT::Math::Rotation3D;
Expand Down
16 changes: 2 additions & 14 deletions Geometry/EcalCommonData/plugins/dd4hep/DDEcalPreshowerAlgo.cc
@@ -1,6 +1,7 @@
#include "DD4hep/DetFactoryHelper.h"
#include "DetectorDescription/DDCMS/interface/DDPlugins.h"
#include "DetectorDescription/DDCMS/interface/BenchmarkGrd.h"
#include "DataFormats/Math/interface/CMSUnits.h"
#include "DD4hep/Shapes.h"

#include <string>
Expand All @@ -9,20 +10,7 @@
using namespace std;
using namespace cms;
using namespace dd4hep;

// FIXME: use local definition until dd4hep fixes the uniits
// using namespace geant_units::operators;

constexpr long double piRadians(M_PIl); // M_PIl is long double version of pi
constexpr long double degPerRad = 180. / piRadians; // Degrees per radian
constexpr double operator"" _deg(long double deg) { return deg / degPerRad; }
constexpr double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; }

// Length
constexpr double operator"" _mm(long double length) { return length * 0.1; }
constexpr double operator"" _mm(unsigned long long int length) { return length * 0.1; }
constexpr double operator"" _cm(long double length) { return length * 1.; }
constexpr double operator"" _cm(unsigned long long int length) { return length * 1; }
using namespace cms_units::operators;

namespace {
struct EcalPreshower {
Expand Down

0 comments on commit 473cbe6

Please sign in to comment.