Go to the documentation of this file.00001 #include "CommonTools/Utils/src/ExpressionFunctionSetter.h"
00002 #include "CommonTools/Utils/src/ExpressionUnaryOperator.h"
00003 #include "CommonTools/Utils/src/ExpressionBinaryOperator.h"
00004 #include "CommonTools/Utils/src/ExpressionQuaterOperator.h"
00005 #include <cmath>
00006 #include <Math/ProbFuncMathCore.h>
00007 #include <DataFormats/Math/interface/deltaPhi.h>
00008 #include <DataFormats/Math/interface/deltaR.h>
00009
00010 namespace reco {
00011 namespace parser {
00012 struct abs_f { double operator()( double x ) const { return fabs( x ); } };
00013 struct acos_f { double operator()( double x ) const { return acos( x ); } };
00014 struct asin_f { double operator()( double x ) const { return asin( x ); } };
00015 struct atan_f { double operator()( double x ) const { return atan( x ); } };
00016 struct atan2_f { double operator()( double x, double y ) const { return atan2( x, y ); } };
00017 struct chi2prob_f { double operator()( double x, double y ) const { return ROOT::Math::chisquared_cdf_c( x, y ); } };
00018 struct cos_f { double operator()( double x ) const { return cos( x ); } };
00019 struct cosh_f { double operator()( double x ) const { return cosh( x ); } };
00020 struct deltaR_f { double operator()( double e1, double p1, double e2, double p2 ) const { return reco::deltaR(e1,p1,e2,p2); } };
00021 struct deltaPhi_f { double operator()( double p1, double p2 ) const { return reco::deltaPhi(p1,p2); } };
00022 struct exp_f { double operator()( double x ) const { return exp( x ); } };
00023 struct hypot_f { double operator()( double x, double y ) const { return hypot( x, y ); } };
00024 struct log_f { double operator()( double x ) const { return log( x ); } };
00025 struct log10_f { double operator()( double x ) const { return log10( x ); } };
00026 struct max_f { double operator()( double x, double y ) const { return std::max( x, y ); } };
00027 struct min_f { double operator()( double x, double y ) const { return std::min( x, y ); } };
00028 struct pow_f { double operator()( double x, double y ) const { return pow( x, y ); } };
00029 struct sin_f { double operator()( double x ) const { return sin( x ); } };
00030 struct sinh_f { double operator()( double x ) const { return sinh( x ); } };
00031 struct sqrt_f { double operator()( double x ) const { return sqrt( x ); } };
00032 struct tan_f { double operator()( double x ) const { return tan( x ); } };
00033 struct tanh_f { double operator()( double x ) const { return tanh( x ); } };
00034 struct test_bit_f { double operator()( double mask, double iBit ) const { return (int(mask) >> int(iBit)) & 1; } };
00035 }
00036 }
00037
00038 using namespace reco::parser;
00039
00040 void ExpressionFunctionSetter::operator()( const char *, const char * ) const {
00041 Function fun = funStack_.back(); funStack_.pop_back();
00042 ExpressionPtr funExp;
00043 switch( fun ) {
00044 case( kAbs ) : funExp.reset( new ExpressionUnaryOperator <abs_f > ( expStack_ ) ); break;
00045 case( kAcos ) : funExp.reset( new ExpressionUnaryOperator <acos_f > ( expStack_ ) ); break;
00046 case( kAsin ) : funExp.reset( new ExpressionUnaryOperator <asin_f > ( expStack_ ) ); break;
00047 case( kAtan ) : funExp.reset( new ExpressionUnaryOperator <atan_f > ( expStack_ ) ); break;
00048 case( kAtan2 ) : funExp.reset( new ExpressionBinaryOperator<atan2_f> ( expStack_ ) ); break;
00049 case( kChi2Prob ) : funExp.reset( new ExpressionBinaryOperator<chi2prob_f>( expStack_ ) ); break;
00050 case( kCos ) : funExp.reset( new ExpressionUnaryOperator <cos_f > ( expStack_ ) ); break;
00051 case( kCosh ) : funExp.reset( new ExpressionUnaryOperator <cosh_f > ( expStack_ ) ); break;
00052 case( kDeltaR ) : funExp.reset( new ExpressionQuaterOperator<deltaR_f> ( expStack_ ) ); break;
00053 case( kDeltaPhi ) : funExp.reset( new ExpressionBinaryOperator<deltaPhi_f>( expStack_ ) ); break;
00054 case( kExp ) : funExp.reset( new ExpressionUnaryOperator <exp_f > ( expStack_ ) ); break;
00055 case( kHypot ) : funExp.reset( new ExpressionBinaryOperator<hypot_f> ( expStack_ ) ); break;
00056 case( kLog ) : funExp.reset( new ExpressionUnaryOperator <log_f > ( expStack_ ) ); break;
00057 case( kLog10 ) : funExp.reset( new ExpressionUnaryOperator <log10_f> ( expStack_ ) ); break;
00058 case( kMax ) : funExp.reset( new ExpressionBinaryOperator<max_f> ( expStack_ ) ); break;
00059 case( kMin ) : funExp.reset( new ExpressionBinaryOperator<min_f> ( expStack_ ) ); break;
00060 case( kPow ) : funExp.reset( new ExpressionBinaryOperator<pow_f > ( expStack_ ) ); break;
00061 case( kSin ) : funExp.reset( new ExpressionUnaryOperator <sin_f > ( expStack_ ) ); break;
00062 case( kSinh ) : funExp.reset( new ExpressionUnaryOperator <sinh_f > ( expStack_ ) ); break;
00063 case( kSqrt ) : funExp.reset( new ExpressionUnaryOperator <sqrt_f > ( expStack_ ) ); break;
00064 case( kTan ) : funExp.reset( new ExpressionUnaryOperator <tan_f > ( expStack_ ) ); break;
00065 case( kTanh ) : funExp.reset( new ExpressionUnaryOperator <tanh_f > ( expStack_ ) ); break;
00066 case( kTestBit ) : funExp.reset( new ExpressionBinaryOperator<test_bit_f>( expStack_ ) ); break;
00067 };
00068 expStack_.push_back( funExp );
00069 }