46 ClassImp(RooStepFunction);
51 RooStepFunction::RooStepFunction()
53 _coefIter = _coefList.createIterator() ;
54 _boundIter = _boundaryList.createIterator() ;
55 _interpolate = kFALSE ;
61 RooStepFunction::RooStepFunction(
const char* name,
const char* title,
62 RooAbsReal& x,
const RooArgList& coefList,
const RooArgList& boundaryList, Bool_t interpolate) :
63 RooAbsReal(name, title),
64 _x(
"x",
"Dependent", this, x),
65 _coefList(
"coefList",
"List of coefficients",this),
66 _boundaryList(
"boundaryList",
"List of boundaries",this),
67 _interpolate(interpolate)
69 _coefIter = _coefList.createIterator() ;
70 TIterator* coefIter = coefList.createIterator() ;
72 while((coef = (RooAbsArg*)coefIter->Next())) {
73 if (!dynamic_cast<RooAbsReal*>(coef)) {
74 cout <<
"RooStepFunction::ctor(" << GetName() <<
") ERROR: coefficient " << coef->GetName()
75 <<
" is not of type RooAbsReal" << endl ;
78 _coefList.add(*coef) ;
82 _boundIter = _boundaryList.createIterator() ;
83 TIterator* boundaryIter = boundaryList.createIterator() ;
85 while((boundary = (RooAbsArg*)boundaryIter->Next())) {
86 if (!dynamic_cast<RooAbsReal*>(boundary)) {
87 cout <<
"RooStepFunction::ctor(" << GetName() <<
") ERROR: boundary " << boundary->GetName()
88 <<
" is not of type RooAbsReal" << endl ;
91 _boundaryList.add(*boundary) ;
94 if (_boundaryList.getSize()!=_coefList.getSize()+1) {
95 coutE(InputArguments) <<
"RooStepFunction::ctor(" << GetName() <<
") ERROR: Number of boundaries must be number of coefficients plus 1" << endl ;
96 throw string(
"RooStepFunction::ctor() ERROR: Number of boundaries must be number of coefficients plus 1") ;
104 RooStepFunction::RooStepFunction(
const RooStepFunction& other,
const char* name) :
105 RooAbsReal(other, name),
106 _x(
"x", this, other._x),
107 _coefList(
"coefList",this,other._coefList),
108 _boundaryList(
"boundaryList",this,other._boundaryList),
109 _interpolate(other._interpolate)
111 _coefIter = _coefList.createIterator();
112 _boundIter = _boundaryList.createIterator();
118 RooStepFunction::~RooStepFunction()
127 Double_t RooStepFunction::evaluate()
const
129 vector<double> b(_boundaryList.getSize()) ;
130 vector<double> c(_coefList.getSize()+3) ;
132 _boundIter->Reset() ;
133 RooAbsReal* boundary ;
134 while ((boundary=(RooAbsReal*)_boundIter->Next())) {
135 b[nb++] = boundary->getVal() ;
139 if ((_x<b[0]) || (_x>b[nb-1]))
return 0 ;
144 for (Int_t i=0;i<nb-1;i++){
145 if (_x>b[i]&&_x<=b[i+1]) {
146 return ((RooAbsReal*)_coefList.at(i))->getVal() ;
156 c[0] = b[0] ; c[nb] = b[nb-1] ;
157 for (Int_t i=0 ; i<nb-1 ; i++) {
158 c[i+1] = (b[i]+b[i+1])/2 ;
165 vector<double> y(_coefList.getSize()+3) ;
167 while ((coef=(RooAbsReal*)_coefIter->Next())) {
168 y[nc++] = coef->getVal() ;
172 for (Int_t i=0;i<nc-1;i++){
173 if (_x>c[i]&&_x<=c[i+1]) {
174 Double_t xx[2] ; xx[0]=c[i] ; xx[1]=c[i+1] ;
175 Double_t yy[2] ; yy[0]=y[i] ; yy[1]=y[i+1] ;
176 return RooMath::interpolate(xx,yy,2,_x) ;