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 "TMath.h"
00035
00036 #include "RooPolynomial.h"
00037 #include "RooAbsReal.h"
00038 #include "RooRealVar.h"
00039 #include "RooArgList.h"
00040
00041 ClassImp(RooPolynomial)
00042 ;
00043
00044
00045
00046 RooPolynomial::RooPolynomial()
00047 {
00048
00049 _coefIter = _coefList.createIterator() ;
00050 }
00051
00052
00053
00054 RooPolynomial::RooPolynomial(const char* name, const char* title,
00055 RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
00056 RooAbsPdf(name, title),
00057 _x("x", "Dependent", this, x),
00058 _coefList("coefList","List of coefficients",this),
00059 _lowestOrder(lowestOrder)
00060 {
00061
00062 _coefIter = _coefList.createIterator() ;
00063
00064
00065 if (_lowestOrder<0) {
00066 cout << "RooPolynomial::ctor(" << GetName()
00067 << ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
00068 _lowestOrder=0 ;
00069 }
00070
00071 TIterator* coefIter = coefList.createIterator() ;
00072 RooAbsArg* coef ;
00073 while((coef = (RooAbsArg*)coefIter->Next())) {
00074 if (!dynamic_cast<RooAbsReal*>(coef)) {
00075 cout << "RooPolynomial::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
00076 << " is not of type RooAbsReal" << endl ;
00077 assert(0) ;
00078 }
00079 _coefList.add(*coef) ;
00080 }
00081 delete coefIter ;
00082 }
00083
00084
00085
00086
00087 RooPolynomial::RooPolynomial(const char* name, const char* title,
00088 RooAbsReal& x) :
00089 RooAbsPdf(name, title),
00090 _x("x", "Dependent", this, x),
00091 _coefList("coefList","List of coefficients",this),
00092 _lowestOrder(1)
00093 {
00094 _coefIter = _coefList.createIterator() ;
00095 }
00096
00097
00098
00099
00100 RooPolynomial::RooPolynomial(const RooPolynomial& other, const char* name) :
00101 RooAbsPdf(other, name),
00102 _x("x", this, other._x),
00103 _coefList("coefList",this,other._coefList),
00104 _lowestOrder(other._lowestOrder)
00105 {
00106
00107 _coefIter = _coefList.createIterator() ;
00108 }
00109
00110
00111
00112
00113
00114 RooPolynomial::~RooPolynomial()
00115 {
00116
00117 delete _coefIter ;
00118 }
00119
00120
00121
00122
00123
00124 Double_t RooPolynomial::evaluate() const
00125 {
00126 Int_t order(_lowestOrder) ;
00127 Double_t sum(order<1 ? 0 : 1) ;
00128
00129 _coefIter->Reset() ;
00130
00131 RooAbsReal* coef ;
00132 const RooArgSet* nset = _coefList.nset() ;
00133 while((coef=(RooAbsReal*)_coefIter->Next())) {
00134 sum += coef->getVal(nset)*TMath::Power(_x,order++) ;
00135 }
00136
00137
00138
00139
00140 return sum;
00141 }
00142
00143
00144
00145
00146 Int_t RooPolynomial::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
00147 {
00148 if (matchArgs(allVars, analVars, _x)) return 1;
00149 return 0;
00150 }
00151
00152
00153
00154
00155 Double_t RooPolynomial::analyticalIntegral(Int_t code, const char* rangeName) const
00156 {
00157 assert(code==1) ;
00158
00159 Int_t order(_lowestOrder) ;
00160
00161 Double_t sum(order>0 ? _x.max(rangeName)-_x.min(rangeName) : 0) ;
00162
00163
00164 const RooArgSet* nset = _coefList.nset() ;
00165 _coefIter->Reset() ;
00166 RooAbsReal* coef ;
00167
00168
00169 while((coef=(RooAbsReal*)_coefIter->Next())) {
00170 sum += coef->getVal(nset)*(TMath::Power(_x.max(rangeName),order+1)-TMath::Power(_x.min(rangeName),order+1))/(order+1) ;
00171 order++ ;
00172 }
00173
00174 return sum;
00175
00176 }