00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "RooFit.h"
00025
00026 #include "Riostream.h"
00027 #include "Riostream.h"
00028 #include <math.h>
00029 #include "TMath.h"
00030 #include "RooBernstein.h"
00031 #include "RooAbsReal.h"
00032 #include "RooRealVar.h"
00033 #include "RooArgList.h"
00034
00035 ClassImp(RooBernstein)
00036 ;
00037
00038
00039
00040 RooBernstein::RooBernstein()
00041 {
00042 }
00043
00044
00045
00046 RooBernstein::RooBernstein(const char* name, const char* title,
00047 RooAbsReal& x, const RooArgList& coefList):
00048 RooAbsPdf(name, title),
00049 _x("x", "Dependent", this, x),
00050 _coefList("coefficients","List of coefficients",this)
00051 {
00052
00053 TIterator* coefIter = coefList.createIterator() ;
00054 RooAbsArg* coef ;
00055 while((coef = (RooAbsArg*)coefIter->Next())) {
00056 if (!dynamic_cast<RooAbsReal*>(coef)) {
00057 cout << "RooBernstein::ctor(" << GetName() << ") ERROR: coefficient " << coef->GetName()
00058 << " is not of type RooAbsReal" << endl ;
00059 assert(0) ;
00060 }
00061 _coefList.add(*coef) ;
00062 }
00063 delete coefIter ;
00064 }
00065
00066
00067
00068
00069 RooBernstein::RooBernstein(const RooBernstein& other, const char* name) :
00070 RooAbsPdf(other, name),
00071 _x("x", this, other._x),
00072 _coefList("coefList",this,other._coefList)
00073 {
00074 }
00075
00076
00077
00078 Double_t RooBernstein::evaluate() const
00079 {
00080
00081 Double_t xmin = _x.min(); Double_t xmax = _x.max();
00082 Int_t degree= _coefList.getSize()-1;
00083
00084 Double_t temp=0, tempx=0;
00085 for (int i=0; i<=degree; ++i){
00086 tempx = (_x-xmin)/(xmax-xmin);
00087 temp += ((RooAbsReal&) _coefList[i]).getVal() *
00088 TMath::Binomial(degree, i) * pow(tempx,i) * pow(1-tempx,degree-i);
00089 }
00090 return temp;
00091
00092 }
00093
00094
00095
00096 Int_t RooBernstein::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName) const
00097 {
00098
00099 if (rangeName && strlen(rangeName)) {
00100 return 0 ;
00101 }
00102
00103 if (matchArgs(allVars, analVars, _x)) return 1;
00104 return 0;
00105 }
00106
00107
00108
00109 Double_t RooBernstein::analyticalIntegral(Int_t code, const char* rangeName) const
00110 {
00111 assert(code==1) ;
00112 Double_t xmin = _x.min(rangeName); Double_t xmax = _x.max(rangeName);
00113 Int_t degree= _coefList.getSize()-1;
00114 Double_t norm(0) ;
00115
00116 Double_t temp=0;
00117 for (int i=0; i<=degree; ++i){
00118
00119
00120
00121 temp = 0;
00122 for (int j=i; j<=degree; ++j){
00123 temp += pow(-1.,j-i) * TMath::Binomial(degree, j) * TMath::Binomial(j,i) / (j+1);
00124 }
00125 temp *= ((RooAbsReal&) _coefList[i]).getVal();
00126 norm += temp;
00127 }
00128
00129 norm *= xmax-xmin;
00130 return norm;
00131 }