diff --git a/DDCore/include/DD4hep/TGeoUnits.h b/DDCore/include/DD4hep/TGeoUnits.h index ac70b8c4fcb76e2f80304880bbc09aa1c882c688..89468713655cc5e60107327c146706cfc888eb2c 100644 --- a/DDCore/include/DD4hep/TGeoUnits.h +++ b/DDCore/include/DD4hep/TGeoUnits.h @@ -73,9 +73,15 @@ namespace tgeo { // // Angle // - static const double radian = 180. / 3.14159265358979323846; // => degree=1 + // static const double radian = 180. / 3.14159265358979323846; // => degree=1 + // static const double milliradian = 1.e-3 * radian; + // static const double degree = 1.; //= (3.14159265358979323846/180.0)*radian; + + //fg: use radians as default unit as this is needed for all math functions + // and everywhere else, except in TGeo shapes -> this is taken care of in shape Handles .... + static const double radian = 1. ; static const double milliradian = 1.e-3 * radian; - static const double degree = 1.; //= (3.14159265358979323846/180.0)*radian; + static const double degree = (3.14159265358979323846/180.0)*radian; static const double steradian = 1.; diff --git a/DDCore/include/XML/Evaluator.h b/DDCore/include/XML/Evaluator.h index 4a6632c2b916f8d2e418566c040844b2eb0c9e73..80cbe589aed420e04d184ec0cd1a84c4bccd2d47 100644 --- a/DDCore/include/XML/Evaluator.h +++ b/DDCore/include/XML/Evaluator.h @@ -241,7 +241,7 @@ namespace XmlTools { * @endcode */ void setSystemOfUnits(double meter = 1.0, double kilogram = 1.0, double second = 1.0, double ampere = 1.0, double kelvin = - 1.0, double mole = 1.0, double candela = 1.0); + 1.0, double mole = 1.0, double candela = 1.0, double radians = 1.0 ); private: void * p; // private data diff --git a/DDCore/src/Evaluator/setStdMath.cpp b/DDCore/src/Evaluator/setStdMath.cpp index e621d60a53f1e583c8eb66e4ced2627d5e80d047..60791c7beab5a9af025992feb9457c3fcc9135f8 100644 --- a/DDCore/src/Evaluator/setStdMath.cpp +++ b/DDCore/src/Evaluator/setStdMath.cpp @@ -3,6 +3,7 @@ // ---------------------------------------------------------------------- #include "XML/Evaluator.h" +#include "DD4hep/TGeoUnits.h" #include <cmath> // for sqrt and pow @@ -39,10 +40,16 @@ void Evaluator::setStdMath() { setVariable("pi", 3.14159265358979323846); setVariable("e", 2.7182818284590452354); setVariable("gamma", 0.577215664901532861); - setVariable("radian", 1.0); - setVariable("rad", 1.0); - setVariable("degree", 3.14159265358979323846/180.); - setVariable("deg", 3.14159265358979323846/180.); + + + // setVariable("radian", 1.0); + // setVariable("rad", 1.0); + // setVariable("degree", 3.14159265358979323846/180.); + // setVariable("deg", 3.14159265358979323846/180.); + setVariable("radian", tgeo::rad ); + setVariable("rad", tgeo::rad ); + setVariable("degree", tgeo::deg ); + setVariable("deg", tgeo::deg ); // S E T S T A N D A R D F U N C T I O N S diff --git a/DDCore/src/Evaluator/setSystemOfUnits.cpp b/DDCore/src/Evaluator/setSystemOfUnits.cpp index 937de35aadb630a002b76732caa7e76c7a57c181..e028f470f33aa15425f7be23bd4e45febc0ec5d4 100644 --- a/DDCore/src/Evaluator/setSystemOfUnits.cpp +++ b/DDCore/src/Evaluator/setSystemOfUnits.cpp @@ -12,7 +12,8 @@ void Evaluator::setSystemOfUnits(double meter, double ampere, double kelvin, double mole, - double candela) + double candela, + double radians) { const double kilo_ = 1.e+03; // chilioi (Greek) "thousand" const double mega_ = 1.e+06; // megas (Greek) "large" @@ -83,14 +84,18 @@ void Evaluator::setSystemOfUnits(double meter, const double pi = 3.14159265358979323846; // Plane angle - const double rad = 1.; // Geant4 (rad units) + // const double rad = 1.; // Geant4 (rad units) //const double rad = pi; // Degree units + + const double rad = radians ; + setVariable("radian", rad); setVariable("rad", rad); setVariable("milliradian", milli_ * rad); setVariable("mrad", milli_ * rad); const double deg = rad*pi/180.; + setVariable("degree", deg); setVariable("deg", deg); diff --git a/DDCore/src/ExpressionEvaluator.cpp b/DDCore/src/ExpressionEvaluator.cpp index 92fc67f134055ef53edc67b9789cac5b4387ef3b..39a327c70d17fac1e90a90af94b834c407048bda 100644 --- a/DDCore/src/ExpressionEvaluator.cpp +++ b/DDCore/src/ExpressionEvaluator.cpp @@ -1,4 +1,6 @@ #include "XML/Evaluator.h" +#include "DD4hep/TGeoUnits.h" + namespace { void _init(XmlTools::Evaluator& e) { @@ -17,7 +19,10 @@ namespace { // 1 Coulomb = 1/e As // Ampere = C/s = 1/e * As / s = 1. / 1.60217733e-19 // kilogram = joule*s*s/(m*m) 1/e_SI * 1 *1 / 1e2 / 1e2 - e.setSystemOfUnits(1.e+2, 1./1.60217733e-6, 1.0, 1./1.60217733e-19, 1.0, 1.0, 1.0); + + // e.setSystemOfUnits(1.e+2, 1./1.60217733e-6, 1.0, 1./1.60217733e-19, 1.0, 1.0, 1.0); + // use the units as defined in TGeoUnits.h: + e.setSystemOfUnits( tgeo::meter, tgeo::kilogram , tgeo::second , tgeo::ampere , tgeo::kelvin , tgeo::mole , tgeo::candela , tgeo::rad ); } void _g4Units(XmlTools::Evaluator& e) { // =================================================================================== diff --git a/DDCore/src/Shapes.cpp b/DDCore/src/Shapes.cpp index 16967a4ae0c4aa777ff1cf310beffc9e8c58ac59..b962d7ee1c5ce3f2d2d5fed2e495201dd67786d5 100644 --- a/DDCore/src/Shapes.cpp +++ b/DDCore/src/Shapes.cpp @@ -10,6 +10,7 @@ #define _USE_MATH_DEFINES #include "DD4hep/LCDD.h" #include "DD4hep/MatrixHelpers.h" +#include "DD4hep/TGeoUnits.h" // C/C++ include files #include <stdexcept> @@ -78,7 +79,7 @@ double Box::z() const { /// Constructor to be used when creating a new object Polycone::Polycone(double start, double delta) { - _assign(new TGeoPcon(start*RAD_2_DEGREE, delta*RAD_2_DEGREE, 0), "", "polycone", false); + _assign(new TGeoPcon(start/tgeo::deg, delta/tgeo::deg, 0), "", "polycone", false); } /// Constructor to be used when creating a new polycone object. Add at the same time all Z planes @@ -88,8 +89,8 @@ Polycone::Polycone(double start, double delta, const vector<double>& rmin, const if (rmin.size() < 2) { throw runtime_error("DD4hep: PolyCone::addZPlanes> Not enough Z planes. minimum is 2!"); } - params.push_back(start*RAD_2_DEGREE); - params.push_back(delta*RAD_2_DEGREE); + params.push_back(start/tgeo::deg); + params.push_back(delta/tgeo::deg); params.push_back(rmin.size()); for (size_t i = 0; i < rmin.size(); ++i) { params.push_back(z[i] ); @@ -126,20 +127,20 @@ void Polycone::addZPlanes(const vector<double>& rmin, const vector<double>& rmax /// Constructor to be used when creating a new cone segment object ConeSegment::ConeSegment(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1, double phi2) { _assign( - new TGeoConeSeg(dz, rmin1, rmax1, rmin2, rmax2, phi1*RAD_2_DEGREE, phi2*RAD_2_DEGREE), "", "cone_segment", true); + new TGeoConeSeg(dz, rmin1, rmax1, rmin2, rmax2, phi1/tgeo::deg, phi2/tgeo::deg), "", "cone_segment", true); } /// Set the cone segment dimensions ConeSegment& ConeSegment::setDimensions(double dz, double rmin1, double rmax1, double rmin2, double rmax2, double phi1, double phi2) { - double params[] = { dz, rmin1, rmax1, rmin2, rmax2, phi1*RAD_2_DEGREE, phi2*RAD_2_DEGREE }; + double params[] = { dz, rmin1, rmax1, rmin2, rmax2, phi1/tgeo::deg, phi2/tgeo::deg }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization void Tube::make(const string& name, double rmin, double rmax, double z, double startPhi, double deltaPhi) { - //_assign(new TGeoTubeSeg(rmin,rmax,z,startPhi*RAD_2_DEGREE,deltaPhi*RAD_2_DEGREE),name,"tube",true); + //_assign(new TGeoTubeSeg(rmin,rmax,z,startPhi/tgeo::deg,deltaPhi/tgeo::deg),name,"tube",true); _assign(new MyConeSeg(), name, "tube", true); setDimensions(rmin, rmax, z, startPhi, deltaPhi); } @@ -147,7 +148,7 @@ void Tube::make(const string& name, double rmin, double rmax, double z, double s /// Set the tube dimensions Tube& Tube::setDimensions(double rmin, double rmax, double z, double startPhi, double deltaPhi) { //double params[] = {rmin,rmax,z,startPhi,deltaPhi}; - double params[] = { z, rmin, rmax, rmin, rmax, startPhi*RAD_2_DEGREE,deltaPhi*RAD_2_DEGREE }; + double params[] = { z, rmin, rmax, rmin, rmax, startPhi/tgeo::deg,deltaPhi/tgeo::deg }; _setDimensions(params); return *this; } @@ -194,25 +195,25 @@ Paraboloid& Paraboloid::setDimensions(double r_low, double r_high, double delta_ /// Constructor to be used when creating a new object with attribute initialization Sphere::Sphere(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi) { - _assign(new TGeoSphere(rmin, rmax, theta, delta_theta*RAD_2_DEGREE, phi*RAD_2_DEGREE, delta_phi*RAD_2_DEGREE), "", "sphere", true); + _assign(new TGeoSphere(rmin, rmax, theta, delta_theta/tgeo::deg, phi/tgeo::deg, delta_phi/tgeo::deg), "", "sphere", true); } /// Set the Sphere dimensions Sphere& Sphere::setDimensions(double rmin, double rmax, double theta, double delta_theta, double phi, double delta_phi) { - double params[] = { rmin, rmax, theta, delta_theta*RAD_2_DEGREE, phi*RAD_2_DEGREE, - delta_phi*RAD_2_DEGREE }; + double params[] = { rmin, rmax, theta, delta_theta/tgeo::deg, phi/tgeo::deg, + delta_phi/tgeo::deg }; _setDimensions(params); return *this; } /// Constructor to be used when creating a new object with attribute initialization void Torus::make(double r, double rmin, double rmax, double phi, double delta_phi) { - _assign(new TGeoTorus(r, rmin, rmax, phi*RAD_2_DEGREE, delta_phi*RAD_2_DEGREE), "", "torus", true); + _assign(new TGeoTorus(r, rmin, rmax, phi/tgeo::deg, delta_phi/tgeo::deg), "", "torus", true); } /// Set the Torus dimensions Torus& Torus::setDimensions(double r, double rmin, double rmax, double phi, double delta_phi) { - double params[] = { r, rmin, rmax, phi*RAD_2_DEGREE, delta_phi*RAD_2_DEGREE }; + double params[] = { r, rmin, rmax, phi/tgeo::deg, delta_phi/tgeo::deg }; _setDimensions(params); return *this; } @@ -220,7 +221,7 @@ Torus& Torus::setDimensions(double r, double rmin, double rmax, double phi, doub /// Constructor to be used when creating a new anonymous object with attribute initialization Trap::Trap(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, double x3, double x4, double alpha2) { - _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2), "", "trap", true); + _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/tgeo::deg, y2, x3, x4, alpha2/tgeo::deg), "", "trap", true); } /// Constructor to be used when creating a new anonymous object with attribute initialization @@ -232,13 +233,13 @@ void Trap::make(double pz, double py, double px, double pLTX) { double x1 = px / 2e0; double x2 = pLTX / 2e0; double alpha1 = (pLTX - px) / py; - _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1, y1, x1, x2, alpha1), "", "trap", true); + _assign(new TGeoTrap(z, theta, phi, y1, x1, x2, alpha1/tgeo::deg, y1, x1, x2, alpha1/tgeo::deg), "", "trap", true); } /// Set the trap dimensions Trap& Trap::setDimensions(double z, double theta, double phi, double y1, double x1, double x2, double alpha1, double y2, double x3, double x4, double alpha2) { - double params[] = { z, theta, phi, y1, x1, x2, alpha1, y2, x3, x4, alpha2 }; + double params[] = { z, theta, phi, y1, x1, x2, alpha1/tgeo::deg, y2, x3, x4, alpha2/tgeo::deg }; _setDimensions(params); return *this; } @@ -257,17 +258,17 @@ void PolyhedraRegular::_create(const string& name, int nsides, double rmin, doub /// Constructor to be used when creating a new object PolyhedraRegular::PolyhedraRegular(int nsides, double rmin, double rmax, double zlen) { - _create("", nsides, rmin, rmax, zlen / 2, -zlen / 2, 0, 2*M_PI*RAD_2_DEGREE); + _create("", nsides, rmin, rmax, zlen / 2, -zlen / 2, 0, 360.); } /// Constructor to be used when creating a new object PolyhedraRegular::PolyhedraRegular(int nsides, double phistart, double rmin, double rmax, double zlen) { - _create("", nsides, rmin, rmax, zlen / 2, -zlen / 2, phistart, 2*M_PI*RAD_2_DEGREE); + _create("", nsides, rmin, rmax, zlen / 2, -zlen / 2, phistart, 360.); } /// Constructor to be used when creating a new object PolyhedraRegular::PolyhedraRegular(int nsides, double rmin, double rmax, double zplanes[2]) { - _create("", nsides, rmin, rmax, zplanes[0], zplanes[1], 0, 2*M_PI*RAD_2_DEGREE); + _create("", nsides, rmin, rmax, zplanes[0], zplanes[1], 0, 360.); } /// Creator method diff --git a/DDTest/src/test_units.cc b/DDTest/src/test_units.cc index a6f1bef7aee6e356eeddd0a239436f73d2ac8f00..a9918e9ce901fadc90bebf81627f606d40f46372 100644 --- a/DDTest/src/test_units.cc +++ b/DDTest/src/test_units.cc @@ -69,6 +69,10 @@ int main(int argc, char** argv ){ double al0_deg = lcdd.constant<double>( "alpha_half_arc_deg" ) / deg ; double al1_deg = lcdd.constant<double>( "alpha_half_arc_rad" ) / deg ; + test( STR( al0_deg ) , STR( 180. ) , " alpha_half_arc_deg in deg is 180." ) ; + test( STR( al1_deg ) , STR( 180. ) , " alpha_half_arc_rad in deg is 180." ) ; + + test( STR(al0_deg), STR(al1_deg) , " alpha_half_arc in deg " ) ;