// Class RooPolyVar is a RooAbsReal implementing a polynomial in terms
// of a list of RooAbsReal coefficients
// <pre>
// f(x) = sum_i a_i * x
// </pre>
// Class RooPolyvar implements analytical integrals of all polynomials
// it can define.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <math.h>
#include "TMath.h"
#include "RooPolyVar.h"
#include "RooAbsReal.h"
#include "RooRealVar.h"
#include "RooArgList.h"
#include "RooMsgService.h"
#include "TMath.h"
#include "TError.h"
using namespace std;
ClassImp(RooPolyVar)
;
RooPolyVar::RooPolyVar() : _lowestOrder(0)
{
_coefIter = _coefList.createIterator() ;
}
RooPolyVar::RooPolyVar(const char* name, const char* title,
RooAbsReal& x, const RooArgList& coefList, Int_t lowestOrder) :
RooAbsReal(name, title),
_x("x", "Dependent", this, x),
_coefList("coefList","List of coefficients",this),
_lowestOrder(lowestOrder)
{
_coefIter = _coefList.createIterator() ;
if (_lowestOrder<0) {
coutE(InputArguments) << "RooPolyVar::ctor(" << GetName()
<< ") WARNING: lowestOrder must be >=0, setting value to 0" << endl ;
_lowestOrder=0 ;
}
TIterator* coefIter = coefList.createIterator() ;
RooAbsArg* coef ;
while((coef = (RooAbsArg*)coefIter->Next())) {
if (!dynamic_cast<RooAbsReal*>(coef)) {
coutE(InputArguments) << "RooPolyVar::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
<< " is not of type RooAbsReal" << endl ;
assert(0) ;
}
_coefList.add(*coef) ;
}
delete coefIter ;
}
RooPolyVar::RooPolyVar(const char* name, const char* title,
RooAbsReal& x) :
RooAbsReal(name, title),
_x("x", "Dependent", this, x),
_coefList("coefList","List of coefficients",this),
_lowestOrder(1)
{
_coefIter = _coefList.createIterator() ;
}
RooPolyVar::RooPolyVar(const RooPolyVar& other, const char* name) :
RooAbsReal(other, name),
_x("x", this, other._x),
_coefList("coefList",this,other._coefList),
_lowestOrder(other._lowestOrder)
{
_coefIter = _coefList.createIterator() ;
}
RooPolyVar::~RooPolyVar()
{
delete _coefIter ;
}
Double_t RooPolyVar::evaluate() const
{
Double_t sum(0) ;
Int_t order(_lowestOrder) ;
_coefIter->Reset() ;
RooAbsReal* coef ;
const RooArgSet* nset = _coefList.nset() ;
while((coef=(RooAbsReal*)_coefIter->Next())) {
sum += coef->getVal(nset)*TMath::Power(_x,order++) ;
}
return sum;
}
Int_t RooPolyVar::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* ) const
{
if (matchArgs(allVars, analVars, _x)) return 1;
return 0;
}
Double_t RooPolyVar::analyticalIntegral(Int_t code, const char* rangeName) const
{
R__ASSERT(code==1) ;
Double_t sum(0) ;
const RooArgSet* nset = _coefList.nset() ;
Int_t order(_lowestOrder) ;
_coefIter->Reset() ;
RooAbsReal* coef ;
while((coef=(RooAbsReal*)_coefIter->Next())) {
sum += coef->getVal(nset)*(TMath::Power(_x.max(rangeName),order+1)-TMath::Power(_x.min(rangeName),order+1))/(order+1) ;
order++ ;
}
return sum;
}