Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:33

0001 // -*- C++ -*-
0002 // ----------------------------------------------------------------------
0003 
0004 #include "Evaluator/Evaluator.h"
0005 #include "Evaluator/detail/Evaluator.h"
0006 #include <limits>
0007 
0008 #ifdef DD4HEP_NONE
0009 /// Utility namespace to support TGeo units.
0010 namespace dd4hep {
0011   //namespace units  {
0012   static const double radian = 1. ;
0013   static const double degree = (3.14159265358979323846/180.0)*radian;
0014   //}
0015 }
0016 #else
0017 #include "Evaluator/DD4hepUnits.h"
0018 #endif
0019 namespace units = dd4hep;
0020 
0021 #include <cmath>        // for sqrt and pow
0022 #include <math.h>
0023 
0024 using namespace std;
0025 
0026 static double eval_abs  (double a)           { return (a < 0) ? -a : a;        }
0027 static double eval_fabs (double a)           { return std::fabs(a);            }
0028 static double eval_fmod (double a, double b) { return std::fmod(a,b);          }
0029 static double eval_min  (double a, double b) { return (a < b) ?  a : b;        }
0030 static double eval_max  (double a, double b) { return (a > b) ?  a : b;        }
0031 static double eval_sqrt (double a)           { return std::sqrt(a);            }
0032 static double eval_cbrt (double a)           { return ::cbrt(a);               }
0033 static double eval_pow  (double a, double b) { return std::pow(a,b);           }
0034 static double eval_sin  (double a)           { return std::sin(a);             }
0035 static double eval_cos  (double a)           { return std::cos(a);             }
0036 static double eval_tan  (double a)           { return std::tan(a);             }
0037 static double eval_asin (double a)           { return std::asin(a);            }
0038 static double eval_acos (double a)           { return std::acos(a);            }
0039 static double eval_atan (double a)           { return std::atan(a);            }
0040 static double eval_atan2(double a, double b) { return std::atan2(a,b);         }
0041 static double eval_sinh (double a)           { return std::sinh(a);            }
0042 static double eval_cosh (double a)           { return std::cosh(a);            }
0043 static double eval_tanh (double a)           { return std::tanh(a);            }
0044 static double eval_exp  (double a)           { return std::exp(a);             }
0045 static double eval_exp2 (double a)           { return ::exp2(a);               }
0046 //static double eval_exp10(double a)           { return ::exp10(a);              }
0047 static double eval_exp10(double a)           { return ::pow(10.,a) ;           }
0048 static double eval_expm1(double a)           { return ::expm1(a);              }
0049 static double eval_log  (double a)           { return std::log(a);             }
0050 static double eval_logb (double a)           { return ::logb(a);               }
0051 static double eval_log10(double a)           { return std::log10(a);           }
0052 static double eval_log1p(double a)           { return ::log1p(a);              }
0053 static double eval_hypot(double a, double b) { return ::hypot(a,b);            }
0054 static double eval_erf  (double a)           { return ::erf(a);                }
0055 static double eval_erfc (double a)           { return ::erfc(a);               }
0056 static double eval_gamma(double a)           { return ::tgamma(a);             }
0057 static double eval_double(double a)          { return a;                       }
0058 static double eval_int  (double a)           { return (double)int(a);          }
0059 static double eval_nint (double a)           { return std::floor(a);           }
0060 static double eval_floor(double a)           { return std::floor(a);           }
0061 static double eval_round(double a)           { return ::round(a);              }
0062 static double eval_ceil (double a)           { return std::ceil(a);            }
0063 static double eval_isnan(double a)           { return std::isnan(a);           }
0064 static double eval_isinf(double a)           { return std::isinf(a);           }
0065 static double eval_nearbyint(double a)       { return ::nearbyint(a);          }
0066 
0067 /// Namespace for the AIDA detector description toolkit
0068 namespace dd4hep  {
0069 
0070   namespace tools {
0071 
0072     void Evaluator::Object::setStdMath() {
0073 
0074       //   S E T   S T A N D A R D   C O N S T A N T S
0075 
0076       setVariableNoLock("pi",     3.14159265358979323846);
0077       setVariableNoLock("e",      2.7182818284590452354);
0078       setVariableNoLock("gamma",  0.577215664901532861);
0079 
0080 
0081       // setVariableNoLock("radian", 1.0);
0082       // setVariableNoLock("rad",    1.0);
0083       // setVariableNoLock("degree", 3.14159265358979323846/180.);
0084       // setVariableNoLock("deg",    3.14159265358979323846/180.);
0085       setVariableNoLock("radian", units::radian );
0086       setVariableNoLock("rad",    units::radian );
0087       setVariableNoLock("degree", units::degree );
0088       setVariableNoLock("deg",    units::degree );
0089       setVariableNoLock("int:epsilon",    std::numeric_limits<int>::epsilon());
0090       setVariableNoLock("long:epsilon",   std::numeric_limits<long>::epsilon());
0091       setVariableNoLock("float:epsilon",  std::numeric_limits<float>::epsilon());
0092       setVariableNoLock("double:epsilon", std::numeric_limits<double>::epsilon());
0093 
0094       //   S E T   S T A N D A R D   F U N C T I O N S
0095 
0096       setFunctionNoLock("abs",        eval_abs);
0097       setFunctionNoLock("fabs",       eval_fabs);
0098       setFunctionNoLock("fmod",       eval_fmod);
0099       setFunctionNoLock("min",        eval_min);
0100       setFunctionNoLock("max",        eval_max);
0101       setFunctionNoLock("sqrt",       eval_sqrt);
0102       setFunctionNoLock("cbrt",       eval_cbrt);
0103       setFunctionNoLock("pow",        eval_pow);
0104       setFunctionNoLock("sin",        eval_sin);
0105       setFunctionNoLock("cos",        eval_cos);
0106       setFunctionNoLock("tan",        eval_tan);
0107       setFunctionNoLock("asin",       eval_asin);
0108       setFunctionNoLock("acos",       eval_acos);
0109       setFunctionNoLock("atan",       eval_atan);
0110       setFunctionNoLock("atan2",      eval_atan2);
0111       setFunctionNoLock("sinh",       eval_sinh);
0112       setFunctionNoLock("cosh",       eval_cosh);
0113       setFunctionNoLock("tanh",       eval_tanh);
0114       setFunctionNoLock("exp",        eval_exp);
0115       setFunctionNoLock("exp2",       eval_exp2);
0116       setFunctionNoLock("exp10",      eval_exp10);
0117       setFunctionNoLock("expm1",      eval_expm1);
0118       setFunctionNoLock("log",        eval_log);
0119       setFunctionNoLock("logb",       eval_logb);
0120       setFunctionNoLock("log10",      eval_log10);
0121       setFunctionNoLock("log1p",      eval_log1p);
0122       setFunctionNoLock("hypot",      eval_hypot);
0123       setFunctionNoLock("erf",        eval_erf);
0124       setFunctionNoLock("erfc",       eval_erfc);
0125       setFunctionNoLock("gamma",      eval_gamma);
0126       setFunctionNoLock("double",     eval_double);
0127       setFunctionNoLock("int",        eval_int);
0128       setFunctionNoLock("nint",       eval_nint);
0129       setFunctionNoLock("floor",      eval_floor);
0130       setFunctionNoLock("round",      eval_round);
0131       setFunctionNoLock("ceil",       eval_ceil);
0132       setFunctionNoLock("isnan",      eval_isnan);
0133       setFunctionNoLock("isinf",      eval_isinf);
0134       setFunctionNoLock("nearbyint",  eval_nearbyint);
0135     }
0136 
0137   } // namespace tools
0138 }  // namespace dd4hep