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