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 #include "Riostream.h"
00030
00031 #include "RooAbsPdf.h"
00032 #include "RooNumRunningInt.h"
00033 #include "RooAbsReal.h"
00034 #include "RooMsgService.h"
00035 #include "RooDataHist.h"
00036 #include "RooHistPdf.h"
00037 #include "RooRealVar.h"
00038
00039 ClassImp(RooNumRunningInt)
00040 ;
00041
00042
00043
00044
00045 RooNumRunningInt::RooNumRunningInt(const char *name, const char *title, RooAbsReal& _func, RooRealVar& _x, const char* bname) :
00046 RooAbsCachedReal(name,title),
00047 func("func","func",this,_func),
00048 x("x","x",this,_x),
00049 _binningName(bname?bname:"cache")
00050 {
00051
00052
00053
00054
00055
00056
00057 setInterpolationOrder(2) ;
00058 }
00059
00060
00061
00062
00063
00064 RooNumRunningInt::RooNumRunningInt(const RooNumRunningInt& other, const char* name) :
00065 RooAbsCachedReal(other,name),
00066 func("func",this,other.func),
00067 x("x",this,other.x),
00068 _binningName(other._binningName)
00069 {
00070
00071 }
00072
00073
00074
00075
00076 RooNumRunningInt::~RooNumRunningInt()
00077 {
00078
00079 }
00080
00081
00082
00083 const char* RooNumRunningInt::inputBaseName() const
00084 {
00085
00086
00087
00088 static string ret ;
00089 ret = func.arg().GetName() ;
00090 ret += "_NUMRUNINT" ;
00091 return ret.c_str() ;
00092 } ;
00093
00094
00095
00096
00097 RooNumRunningInt::RICacheElem::RICacheElem(const RooNumRunningInt& self, const RooArgSet* nset) :
00098 FuncCacheElem(self,nset), _self(&const_cast<RooNumRunningInt&>(self))
00099 {
00100
00101
00102
00103 _ax = new Double_t[hist()->numEntries()] ;
00104 _ay = new Double_t[hist()->numEntries()] ;
00105
00106
00107 _xx = (RooRealVar*) hist()->get()->find(self.x.arg().GetName()) ;
00108 for (int i=0 ; i<hist()->numEntries() ; i++) {
00109 hist()->get(i) ;
00110 _ax[i] = _xx->getVal() ;
00111 _ay[i] = -1 ;
00112 }
00113
00114 }
00115
00116
00117
00118 RooNumRunningInt::RICacheElem::~RICacheElem()
00119 {
00120
00121
00122
00123 delete[] _ax ;
00124 delete[] _ay ;
00125 }
00126
00127
00128
00129 RooArgList RooNumRunningInt::RICacheElem::containedArgs(Action action)
00130 {
00131
00132
00133 RooArgList ret ;
00134 ret.add(FuncCacheElem::containedArgs(action)) ;
00135 ret.add(*_self) ;
00136 ret.add(*_xx) ;
00137 return ret ;
00138 }
00139
00140
00141
00142
00143 void RooNumRunningInt::RICacheElem::calculate(Bool_t cdfmode)
00144 {
00145
00146
00147
00148
00149
00150 Int_t nbins = hist()->numEntries() ;
00151
00152 Double_t xsave = _self->x ;
00153
00154 Int_t lastHi=0 ;
00155 Int_t nInitRange=32 ;
00156 for (int i=1 ; i<=nInitRange ; i++) {
00157 Int_t hi = (i*nbins)/nInitRange -1 ;
00158 Int_t lo = lastHi ;
00159 addRange(lo,hi,nbins) ;
00160 lastHi=hi ;
00161 }
00162
00163
00164 for (int i=1 ; i<nbins ; i++) {
00165 _ay[i] += _ay[i-1] ;
00166 }
00167
00168
00169 Double_t binv = (_self->x.max()-_self->x.min())/nbins ;
00170 for (int i=0 ; i<nbins ; i++) {
00171 hist()->get(i) ;
00172 if (cdfmode) {
00173 hist()->set(_ay[i]/_ay[nbins-1]) ;
00174 } else {
00175 hist()->set(_ay[i]*binv) ;
00176 }
00177 }
00178
00179 if (cdfmode) {
00180 func()->setCdfBoundaries(kTRUE) ;
00181 }
00182 _self->x = xsave ;
00183 }
00184
00185
00186
00187
00188 void RooNumRunningInt::RICacheElem::addRange(Int_t ixlo, Int_t ixhi, Int_t nbins)
00189 {
00190
00191
00192
00193
00194
00195
00196
00197
00198 if (_ay[ixlo]<0) {
00199 addPoint(ixlo) ;
00200 }
00201 if (_ay[ixhi]<0) {
00202 addPoint(ixhi) ;
00203 }
00204
00205
00206 if (ixhi-ixlo==1) {
00207 return ;
00208 }
00209
00210
00211 if (ixhi-ixlo==2) {
00212 addPoint(ixlo+1) ;
00213 return ;
00214 }
00215
00216
00217 Int_t ixmid = (ixlo+ixhi)/2 ;
00218 addPoint(ixmid) ;
00219
00220
00221 Double_t yInt = _ay[ixlo] + (_ay[ixhi]-_ay[ixlo])*(ixmid-ixlo)/(ixhi-ixlo) ;
00222
00223
00224 if (fabs(yInt-_ay[ixmid])*(_ax[nbins-1]-_ax[0])>1e-6) {
00225 addRange(ixlo,ixmid,nbins) ;
00226 addRange(ixmid,ixhi,nbins) ;
00227 } else {
00228 for (Int_t j=ixlo+1 ; j<ixmid ; j++) {
00229 _ay[j] = _ay[ixlo] + (_ay[ixmid]-_ay[ixlo])*(j-ixlo)/(ixmid-ixlo) ;
00230 }
00231 for (Int_t j=ixmid+1 ; j<ixhi ; j++) {
00232 _ay[j] = _ay[ixmid] + (_ay[ixhi]-_ay[ixmid])*(j-ixmid)/(ixhi-ixmid) ;
00233 }
00234 }
00235
00236 }
00237
00238
00239
00240 void RooNumRunningInt::RICacheElem::addPoint(Int_t ix)
00241 {
00242
00243
00244 hist()->get(ix) ;
00245 _self->x = _xx->getVal() ;
00246 _ay[ix] = _self->func.arg().getVal(*_xx) ;
00247
00248 }
00249
00250
00251
00252
00253 void RooNumRunningInt::fillCacheObject(RooAbsCachedReal::FuncCacheElem& cache) const
00254 {
00255
00256 RICacheElem& riCache = static_cast<RICacheElem&>(cache) ;
00257 riCache.calculate(kFALSE) ;
00258 }
00259
00260
00261
00262
00263 RooArgSet* RooNumRunningInt::actualObservables(const RooArgSet& ) const
00264 {
00265
00266
00267
00268 RooArgSet* ret = new RooArgSet ;
00269 ret->add(x.arg()) ;
00270 return ret ;
00271 }
00272
00273
00274
00275
00276 RooArgSet* RooNumRunningInt::actualParameters(const RooArgSet& ) const
00277 {
00278
00279
00280
00281
00282 RooArgSet* ret = func.arg().getParameters(RooArgSet()) ;
00283 ret->remove(x.arg(),kTRUE,kTRUE) ;
00284 return ret ;
00285 }
00286
00287
00288
00289 RooAbsCachedReal::FuncCacheElem* RooNumRunningInt::createCache(const RooArgSet* nset) const
00290 {
00291
00292
00293 return new RICacheElem(*const_cast<RooNumRunningInt*>(this),nset) ;
00294 }
00295
00296
00297
00298 Double_t RooNumRunningInt::evaluate() const
00299 {
00300
00301
00302 cout << "RooNumRunningInt::evaluate(" << GetName() << ")" << endl ;
00303 return 0 ;
00304 }
00305
00306