00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "RooFit.h"
00031
00032 #include "Riostream.h"
00033 #include "Riostream.h"
00034 #include <math.h>
00035 #include "TMath.h"
00036
00037 #include "RooPolyVar.h"
00038 #include "RooAbsReal.h"
00039 #include "RooRealVar.h"
00040 #include "RooArgList.h"
00041 #include "RooMsgService.h"
00042 #include "TMath.h"
00043
00044 ClassImp(RooPolyVar)
00045 ;
00046
00047
00048
00049 RooPolyVar::RooPolyVar()
00050 {
00051
00052 _coefIter = _coefList.createIterator() ;
00053 }
00054
00055
00056
00057 RooPolyVar::RooPolyVar(const char* name, const char* title,
00058 RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
00059 RooAbsReal(name, title),
00060 _x("x", "Dependent", this, x),
00061 _coefList("coefList","List of coefficients",this),
00062 _lowestOrder(lowestOrder)
00063 {
00064
00065
00066
00067
00068
00069
00070 _coefIter = _coefList.createIterator() ;
00071
00072
00073 if (_lowestOrder<0) {
00074 coutE(InputArguments) << "RooPolyVar::ctor(" << GetName()
00075 << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
00076 _lowestOrder=0 ;
00077 }
00078
00079 TIterator* coefIter = coefList.createIterator() ;
00080 RooAbsArg* coef ;
00081 while((coef = (RooAbsArg*)coefIter->Next())) {
00082 if (!dynamic_cast<RooAbsReal*>(coef)) {
00083 coutE(InputArguments) << "RooPolyVar::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
00084 << " is not of type RooAbsReal" << endl ;
00085 assert(0) ;
00086 }
00087 _coefList.add(*coef) ;
00088 }
00089 delete coefIter ;
00090 }
00091
00092
00093
00094
00095 RooPolyVar::RooPolyVar(const char* name, const char* title,
00096 RooAbsReal& x) :
00097 RooAbsReal(name, title),
00098 _x("x", "Dependent", this, x),
00099 _coefList("coefList","List of coefficients",this),
00100 _lowestOrder(1)
00101 {
00102
00103
00104 _coefIter = _coefList.createIterator() ;
00105 }
00106
00107
00108
00109
00110 RooPolyVar::RooPolyVar(const RooPolyVar& other, const char* name) :
00111 RooAbsReal(other, name),
00112 _x("x", this, other._x),
00113 _coefList("coefList",this,other._coefList),
00114 _lowestOrder(other._lowestOrder)
00115 {
00116
00117 _coefIter = _coefList.createIterator() ;
00118 }
00119
00120
00121
00122
00123
00124 RooPolyVar::~RooPolyVar()
00125 {
00126
00127 delete _coefIter ;
00128 }
00129
00130
00131
00132
00133
00134 Double_t RooPolyVar::evaluate() const
00135 {
00136
00137
00138 Double_t sum(0) ;
00139 Int_t order(_lowestOrder) ;
00140 _coefIter->Reset() ;
00141
00142 RooAbsReal* coef ;
00143 const RooArgSet* nset = _coefList.nset() ;
00144 while((coef=(RooAbsReal*)_coefIter->Next())) {
00145 sum += coef->getVal(nset)*TMath::Power(_x,order++) ;
00146 }
00147
00148 return sum;
00149 }
00150
00151
00152
00153
00154 Int_t RooPolyVar::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
00155 {
00156
00157
00158 if (matchArgs(allVars, analVars, _x)) return 1;
00159 return 0;
00160 }
00161
00162
00163
00164
00165 Double_t RooPolyVar::analyticalIntegral(Int_t code, const char* rangeName) const
00166 {
00167
00168
00169 assert(code==1) ;
00170
00171 Double_t sum(0) ;
00172
00173 const RooArgSet* nset = _coefList.nset() ;
00174 Int_t order(_lowestOrder) ;
00175 _coefIter->Reset() ;
00176 RooAbsReal* coef ;
00177
00178
00179 while((coef=(RooAbsReal*)_coefIter->Next())) {
00180 sum += coef->getVal(nset)*(TMath::Power(_x.max(rangeName),order+1)-TMath::Power(_x.min(rangeName),order+1))/(order+1) ;
00181 order++ ;
00182 }
00183
00184 return sum;
00185
00186 }