Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:19

0001 #include "CommonTools/Utils/interface/parser/ExpressionFunctionSetter.h"
0002 #include "CommonTools/Utils/interface/parser/ExpressionUnaryOperator.h"
0003 #include "CommonTools/Utils/interface/parser/ExpressionBinaryOperator.h"
0004 #include "CommonTools/Utils/src/ExpressionQuaterOperator.h"
0005 #include <cmath>
0006 #include <Math/ProbFuncMathCore.h>
0007 #include <DataFormats/Math/interface/deltaPhi.h>
0008 #include <DataFormats/Math/interface/deltaR.h>
0009 
0010 namespace reco {
0011   namespace parser {
0012     struct abs_f {
0013       double operator()(double x) const { return fabs(x); }
0014     };
0015     struct acos_f {
0016       double operator()(double x) const { return acos(x); }
0017     };
0018     struct asin_f {
0019       double operator()(double x) const { return asin(x); }
0020     };
0021     struct atan_f {
0022       double operator()(double x) const { return atan(x); }
0023     };
0024     struct atan2_f {
0025       double operator()(double x, double y) const { return atan2(x, y); }
0026     };
0027     struct chi2prob_f {
0028       double operator()(double x, double y) const { return ROOT::Math::chisquared_cdf_c(x, y); }
0029     };
0030     struct cos_f {
0031       double operator()(double x) const { return cos(x); }
0032     };
0033     struct cosh_f {
0034       double operator()(double x) const { return cosh(x); }
0035     };
0036     struct deltaR_f {
0037       double operator()(double e1, double p1, double e2, double p2) const { return reco::deltaR(e1, p1, e2, p2); }
0038     };
0039     struct deltaPhi_f {
0040       double operator()(double p1, double p2) const { return reco::deltaPhi(p1, p2); }
0041     };
0042     struct exp_f {
0043       double operator()(double x) const { return exp(x); }
0044     };
0045     struct hypot_f {
0046       double operator()(double x, double y) const { return hypot(x, y); }
0047     };
0048     struct log_f {
0049       double operator()(double x) const { return log(x); }
0050     };
0051     struct log10_f {
0052       double operator()(double x) const { return log10(x); }
0053     };
0054     struct max_f {
0055       double operator()(double x, double y) const { return std::max(x, y); }
0056     };
0057     struct min_f {
0058       double operator()(double x, double y) const { return std::min(x, y); }
0059     };
0060     struct pow_f {
0061       double operator()(double x, double y) const { return pow(x, y); }
0062     };
0063     struct sin_f {
0064       double operator()(double x) const { return sin(x); }
0065     };
0066     struct sinh_f {
0067       double operator()(double x) const { return sinh(x); }
0068     };
0069     struct sqrt_f {
0070       double operator()(double x) const { return sqrt(x); }
0071     };
0072     struct tan_f {
0073       double operator()(double x) const { return tan(x); }
0074     };
0075     struct tanh_f {
0076       double operator()(double x) const { return tanh(x); }
0077     };
0078     struct test_bit_f {
0079       double operator()(double mask, double iBit) const { return (int(mask) >> int(iBit)) & 1; }
0080     };
0081   }  // namespace parser
0082 }  // namespace reco
0083 
0084 using namespace reco::parser;
0085 
0086 void ExpressionFunctionSetter::operator()(const char *, const char *) const {
0087   Function fun = funStack_.back();
0088   funStack_.pop_back();
0089   ExpressionPtr funExp;
0090   switch (fun) {
0091     case (kAbs):
0092       funExp.reset(new ExpressionUnaryOperator<abs_f>(expStack_));
0093       break;
0094     case (kAcos):
0095       funExp.reset(new ExpressionUnaryOperator<acos_f>(expStack_));
0096       break;
0097     case (kAsin):
0098       funExp.reset(new ExpressionUnaryOperator<asin_f>(expStack_));
0099       break;
0100     case (kAtan):
0101       funExp.reset(new ExpressionUnaryOperator<atan_f>(expStack_));
0102       break;
0103     case (kAtan2):
0104       funExp.reset(new ExpressionBinaryOperator<atan2_f>(expStack_));
0105       break;
0106     case (kChi2Prob):
0107       funExp.reset(new ExpressionBinaryOperator<chi2prob_f>(expStack_));
0108       break;
0109     case (kCos):
0110       funExp.reset(new ExpressionUnaryOperator<cos_f>(expStack_));
0111       break;
0112     case (kCosh):
0113       funExp.reset(new ExpressionUnaryOperator<cosh_f>(expStack_));
0114       break;
0115     case (kDeltaR):
0116       funExp.reset(new ExpressionQuaterOperator<deltaR_f>(expStack_));
0117       break;
0118     case (kDeltaPhi):
0119       funExp.reset(new ExpressionBinaryOperator<deltaPhi_f>(expStack_));
0120       break;
0121     case (kExp):
0122       funExp.reset(new ExpressionUnaryOperator<exp_f>(expStack_));
0123       break;
0124     case (kHypot):
0125       funExp.reset(new ExpressionBinaryOperator<hypot_f>(expStack_));
0126       break;
0127     case (kLog):
0128       funExp.reset(new ExpressionUnaryOperator<log_f>(expStack_));
0129       break;
0130     case (kLog10):
0131       funExp.reset(new ExpressionUnaryOperator<log10_f>(expStack_));
0132       break;
0133     case (kMax):
0134       funExp.reset(new ExpressionBinaryOperator<max_f>(expStack_));
0135       break;
0136     case (kMin):
0137       funExp.reset(new ExpressionBinaryOperator<min_f>(expStack_));
0138       break;
0139     case (kPow):
0140       funExp.reset(new ExpressionBinaryOperator<pow_f>(expStack_));
0141       break;
0142     case (kSin):
0143       funExp.reset(new ExpressionUnaryOperator<sin_f>(expStack_));
0144       break;
0145     case (kSinh):
0146       funExp.reset(new ExpressionUnaryOperator<sinh_f>(expStack_));
0147       break;
0148     case (kSqrt):
0149       funExp.reset(new ExpressionUnaryOperator<sqrt_f>(expStack_));
0150       break;
0151     case (kTan):
0152       funExp.reset(new ExpressionUnaryOperator<tan_f>(expStack_));
0153       break;
0154     case (kTanh):
0155       funExp.reset(new ExpressionUnaryOperator<tanh_f>(expStack_));
0156       break;
0157     case (kTestBit):
0158       funExp.reset(new ExpressionBinaryOperator<test_bit_f>(expStack_));
0159       break;
0160   };
0161   expStack_.push_back(funExp);
0162 }