00001 #include "PhysicsTools/Utilities/src/ExpressionFunctionSetter.h" 00002 #include "PhysicsTools/Utilities/src/ExpressionUnaryOperator.h" 00003 #include "PhysicsTools/Utilities/src/ExpressionBinaryOperator.h" 00004 #include <cmath> 00005 #include "RVersion.h" 00006 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,0) 00007 #include <Math/ProbFuncMathCore.h> 00008 #else 00009 #include <Math/DistFunc.h> 00010 #endif 00011 00012 namespace reco { 00013 namespace parser { 00014 struct abs_f { double operator()( double x ) const { return fabs( x ); } }; 00015 struct acos_f { double operator()( double x ) const { return acos( x ); } }; 00016 struct asin_f { double operator()( double x ) const { return asin( x ); } }; 00017 struct atan_f { double operator()( double x ) const { return atan( x ); } }; 00018 struct atan2_f { double operator()( double x, double y ) const { return atan2( x, y ); } }; 00019 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,18,0) 00020 struct chi2prob_f { double operator()( double x, double y ) const { return ROOT::Math::chisquared_cdf_c( x, y ); } }; 00021 #else 00022 struct chi2prob_f { double operator()( double x, double y ) const { return ROOT::Math::chisquared_prob( x, y ); } }; 00023 #endif 00024 struct cos_f { double operator()( double x ) const { return cos( x ); } }; 00025 struct cosh_f { double operator()( double x ) const { return cosh( x ); } }; 00026 struct exp_f { double operator()( double x ) const { return exp( x ); } }; 00027 struct log_f { double operator()( double x ) const { return log( x ); } }; 00028 struct log10_f { double operator()( double x ) const { return log10( x ); } }; 00029 struct max_f { double operator()( double x, double y ) const { return std::max( x, y ); } }; 00030 struct min_f { double operator()( double x, double y ) const { return std::min( x, y ); } }; 00031 struct pow_f { double operator()( double x, double y ) const { return pow( x, y ); } }; 00032 struct sin_f { double operator()( double x ) const { return sin( x ); } }; 00033 struct sinh_f { double operator()( double x ) const { return sinh( x ); } }; 00034 struct sqrt_f { double operator()( double x ) const { return sqrt( x ); } }; 00035 struct tan_f { double operator()( double x ) const { return tan( x ); } }; 00036 struct tanh_f { double operator()( double x ) const { return tanh( x ); } }; 00037 } 00038 } 00039 00040 using namespace reco::parser; 00041 00042 void ExpressionFunctionSetter::operator()( const char *, const char * ) const { 00043 Function fun = funStack_.back(); funStack_.pop_back(); 00044 ExpressionPtr funExp; 00045 switch( fun ) { 00046 case( kAbs ) : funExp.reset( new ExpressionUnaryOperator <abs_f > ( expStack_ ) ); break; 00047 case( kAcos ) : funExp.reset( new ExpressionUnaryOperator <acos_f > ( expStack_ ) ); break; 00048 case( kAsin ) : funExp.reset( new ExpressionUnaryOperator <asin_f > ( expStack_ ) ); break; 00049 case( kAtan ) : funExp.reset( new ExpressionUnaryOperator <atan_f > ( expStack_ ) ); break; 00050 case( kAtan2 ) : funExp.reset( new ExpressionBinaryOperator<atan2_f> ( expStack_ ) ); break; 00051 case( kChi2Prob ) : funExp.reset( new ExpressionBinaryOperator<chi2prob_f>( expStack_ ) ); break; 00052 case( kCos ) : funExp.reset( new ExpressionUnaryOperator <cos_f > ( expStack_ ) ); break; 00053 case( kCosh ) : funExp.reset( new ExpressionUnaryOperator <cosh_f > ( expStack_ ) ); break; 00054 case( kExp ) : funExp.reset( new ExpressionUnaryOperator <exp_f > ( expStack_ ) ); break; 00055 case( kLog ) : funExp.reset( new ExpressionUnaryOperator <log_f > ( expStack_ ) ); break; 00056 case( kLog10 ) : funExp.reset( new ExpressionUnaryOperator <log10_f> ( expStack_ ) ); break; 00057 case( kMax ) : funExp.reset( new ExpressionBinaryOperator<max_f> ( expStack_ ) ); break; 00058 case( kMin ) : funExp.reset( new ExpressionBinaryOperator<min_f> ( expStack_ ) ); break; 00059 case( kPow ) : funExp.reset( new ExpressionBinaryOperator<pow_f > ( expStack_ ) ); break; 00060 case( kSin ) : funExp.reset( new ExpressionUnaryOperator <sin_f > ( expStack_ ) ); break; 00061 case( kSinh ) : funExp.reset( new ExpressionUnaryOperator <sinh_f > ( expStack_ ) ); break; 00062 case( kSqrt ) : funExp.reset( new ExpressionUnaryOperator <sqrt_f > ( expStack_ ) ); break; 00063 case( kTan ) : funExp.reset( new ExpressionUnaryOperator <tan_f > ( expStack_ ) ); break; 00064 case( kTanh ) : funExp.reset( new ExpressionUnaryOperator <tanh_f > ( expStack_ ) ); break; 00065 }; 00066 expStack_.push_back( funExp ); 00067 }