109 pdf1("pdf1","pdf1",this,_pdf1),
110 pdf2("pdf2","pdf2",this,_pdf2),
112 alpha("alpha","alpha",this,_alpha),
113 _cacheAlpha(doCacheAlpha),
125 pdf1(
"pdf1",this,other.pdf1),
126 pdf2(
"pdf2",this,other.pdf2),
128 alpha(
"alpha",this,other.alpha),
129 _cacheAlpha(other._cacheAlpha),
178 static TString
name ;
181 name.Append(
"_MORPH_") ;
208 coutP(
Eval) <<
"RooIntegralMorph::fillCacheObject(" <<
GetName() <<
") filling multi-dimensional cache" ;
209 while(slIter->
Next()) {
210 alphaSet = (*cache.
hist()->
get()) ;
230 return new MorphCacheElem(const_cast<RooIntegralMorph&>(*
this),nset) ;
314 oocoutW(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElem::calcX() WARNING: requested root finding for unphysical CDF value " << y << endl ;
322 ok &= _rf1->findRoot(x1,xmin,xmax,y) ;
323 ok &= _rf2->findRoot(x2,xmin,xmax,y) ;
327 return _alpha->getVal()*x1 + (1-_alpha->getVal())*x2 ;
338 return (
Int_t)(_x->numBins(
"cache")*(X-
xmin)/(xmax-xmin)) ;
356 _yatX.resize(_x->numBins(
"cache")+1);
357 _calcX.resize(_x->numBins(
"cache")+1);
366 for (
int i=0 ; i<
nbins ; i++) {
375 for (
int i=0 ; i<10 ; i++) {
379 Double_t delta = (_yatX[_yatXmax] - _yatX[_yatXmin])/10 ;
393 Int_t igapLow = _yatXmin+1 ;
396 Int_t igapHigh = igapLow+1 ;
397 while(_yatX[igapHigh]<0 && igapHigh<(_yatXmax)) igapHigh++ ;
400 fillGap(igapLow-1,igapHigh) ;
403 if (igapHigh>=_yatXmax-1) break ;
404 igapLow = igapHigh+1 ;
411 for (
int i=_yatXmin+1 ; i<_yatXmax-1 ; i++) {
414 Double_t xBinC = xmin + (i+0.5)*binw ;
415 Double_t xOffset = xBinC-_calcX[i] ;
416 if (
fabs(xOffset/binw)>1
e-3) {
417 Double_t slope = (_yatX[i+1]-_yatX[i-1])/(_calcX[i+1]-_calcX[i-1]) ;
418 Double_t newY = _yatX[i] + slope*xOffset ;
425 for (
int i=0; i<_yatXmin ; i++) {
431 for (
int i=_yatXmin ; i<_yatXmax ; i++) {
437 Double_t xMin = _x->getMin(
"cache") ;
438 Double_t xMax = _x->getMax(
"cache") ;
439 _rf1->findRoot(x1,xMin,xMax,y) ;
440 _rf2->findRoot(x2,xMin,xMax,y) ;
442 _x->setVal(x1) ;
Double_t f1x1 = _pdf1->getVal(&nsetTmp) ;
443 _x->setVal(x2) ;
Double_t f2x2 = _pdf2->getVal(&nsetTmp) ;
444 Double_t fbarX = f1x1*f2x2 / ( _alpha->getVal()*f2x2 + (1-_alpha->getVal())*f1x1 ) ;
451 for (
int i=_yatXmax+1 ; i<
nbins ; i++) {
457 pdf()->setUnitNorm(
kTRUE) ;
460 oocxcoutD(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElem::calculate(" << _self->GetName() <<
") calculation required " << _ccounter <<
" samplings of cdfs" << endl ;
476 oocoutE(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" << _self->GetName() <<
"): ERROR in fillgap " << ixlo <<
" = " << ixhi
477 <<
" splitPoint= " << splitPoint <<
" _yatX[ixlo] = " << _yatX[ixlo] << endl ;
480 oocoutE(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" << _self->GetName() <<
"): ERROR in fillgap " << ixlo <<
" = " << ixhi
481 <<
" splitPoint " << splitPoint <<
" _yatX[ixhi] = " << _yatX[ixhi] << endl ;
485 Double_t ymid = _yatX[ixlo]*splitPoint + _yatX[ixhi]*(1-splitPoint) ;
489 oocoutW(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElem::fillGap(" << _self->GetName() <<
") unable to calculate midpoint in gap ["
490 << ixlo <<
"," << ixhi <<
"], resorting to interpolation" << endl ;
491 interpolateGap(ixlo,ixhi) ;
494 Int_t iX = binX(Xmid) ;
495 Double_t cq = (Xmid-_calcX[ixlo])/(_calcX[ixhi]-_calcX[ixlo])-0.5 ;
503 if (
fabs(cq)<0.01 ||
fabs(cq*(ixhi-ixlo))<0.1 || ymid<_ycutoff ) {
507 interpolateGap(ixlo,iX) ;
510 interpolateGap(iX,ixhi) ;
517 if (splitPoint<0.95) {
519 Double_t newSplit = splitPoint + 0.5*(1-splitPoint) ;
520 fillGap(ixlo,ixhi,newSplit) ;
523 interpolateGap(ixlo,ixhi) ;
526 }
else if (iX==ixhi) {
529 if (splitPoint>0.05) {
531 fillGap(ixlo,ixhi,newSplit) ;
534 interpolateGap(ixlo,ixhi) ;
564 Double_t deltaY = (_yatX[ixhi]-_yatX[ixlo])/((_calcX[ixhi]-_calcX[ixlo])/binw) ;
567 Double_t xBinC = xmin + (ixlo+0.5)*binw ;
568 Double_t xOffset = xBinC-_calcX[ixlo] ;
570 for (
int j=ixlo+1 ; j<ixhi ; j++) {
571 _yatX[j] = _yatX[ixlo]+(xOffset+(j-ixlo))*deltaY ;
572 _calcX[j] = xmin + (j+0.5)*binw ;
600 ok &= _rf1->findRoot(x1,xmin,xmax,ymin) ;
601 ok &= _rf2->findRoot(x2,xmin,xmax,ymin) ;
602 oocxcoutD(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" << _self->GetName() <<
") findMin: x1 = " << x1 <<
" x2 = " << x2 <<
" ok = " << (ok?
"T":
"F") << endl ;
608 Double_t X = _alpha->getVal()*x1 + (1-_alpha->getVal())*x2 ;
609 if (
fabs(X-Xlast)/(xmax-
xmin)<0.0001) {
615 _yatXmin = (
Int_t)(nbins*(X-xmin)/(xmax-
xmin)) ;
616 _yatX[_yatXmin] =
ymin ;
617 _calcX[_yatXmin] =
X ;
625 if (ymin<_ycutoff) break ;
627 _yatX[_yatXmin] = yminSave ;
628 _calcX[_yatXmin] = Xsave ;
633 Double_t deltaymax=0.1, deltaymaxSave(-1) ;
636 ok &= _rf1->findRoot(x1,xmin,xmax,1-deltaymax) ;
637 ok &= _rf2->findRoot(x2,xmin,xmax,1-deltaymax) ;
639 oocxcoutD(_self,
Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" << _self->GetName() <<
") findMax: x1 = " << x1 <<
" x2 = " << x2 <<
" ok = " << (ok?
"T":
"F") << endl ;
645 Double_t X = _alpha->getVal()*x1 + (1-_alpha->getVal())*x2 ;
646 if (
fabs(X-Xlast)/(xmax-
xmin)<0.0001) {
652 _yatXmax = (
Int_t)(nbins*(X-xmin)/(xmax-
xmin)) ;
653 _yatX[_yatXmax] = 1-deltaymax ;
654 _calcX[_yatXmax] =
X ;
655 deltaymaxSave = deltaymax ;
659 deltaymax /=
sqrt(10.) ;
662 if (deltaymax<_ycutoff) break ;
665 _yatX[_yatXmax] = 1-deltaymaxSave ;
666 _calcX[_yatXmax] = Xsave ;
670 for (
int i=0 ; i<_yatXmin ; i++) _yatX[i] = -2 ;
671 for (
int i=_yatXmax+1 ; i<
nbins; i++) _yatX[i] = -2 ;
672 oocxcoutD(_self,
Eval) <<
"RooIntegralMorph::findRange(" << _self->GetName() <<
"): ymin = " << _yatX[_yatXmin] <<
" ymax = " << _yatX[_yatXmax] << endl;
673 oocxcoutD(_self,
Eval) <<
"RooIntegralMorph::findRange(" << _self->GetName() <<
"): xmin = " << _calcX[_yatXmin] <<
" xmax = " << _calcX[_yatXmax] << endl;
698 orderedObs.
add(obs) ;
701 orderedObs.
remove(*obsX) ;
702 orderedObs.
add(*obsX) ;
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual void fillCacheObject(PdfCacheElem &cache) const
Fill the cache with the interpolated shape.
virtual RooArgList containedArgs(Action)
Returns all RooAbsArg objects contained in the cache element.
MorphCacheElem(RooIntegralMorph &self, const RooArgSet *nset)
Construct of cache element, copy relevant input from RooIntegralMorph, create the cdfs from the input...
Iterator abstract base class.
const RooAbsReal & arg() const
RooBrentRootFinder * _rf2
virtual const RooArgSet * get() const
virtual PdfCacheElem * createCache(const RooArgSet *nset) const
Create and return a derived MorphCacheElem.
RooAbsReal * createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset...
static const double x2[5]
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Int_t binX(Double_t x)
Return the bin number enclosing the given x value.
Double_t evaluate() const
Dummy.
virtual RooArgSet * actualObservables(const RooArgSet &nset) const
Observable to be cached for given choice of normalization.
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
RooRealVar represents a fundamental (non-derived) real valued object.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Double_t calcX(Double_t y, Bool_t &ok)
Calculate the x value of the output p.d.f at the given cdf value y.
RooAbsArg * find(const char *name) const
Find object with given name in list.
void findRange()
Determine which range of y values can be mapped to x values from the numeric inversion of the input c...
Implement the abstract 1-dimensional root finding interface using the Brent-Decker method...
RooAbsArg * absArg() const
virtual const char * GetName() const
Returns name of object.
void setTol(Double_t tol)
virtual void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const
Indicate to the RooAbsCachedPdf base class that for the filling of the cache the traversal of the x s...
void fillGap(Int_t ixlo, Int_t ixhi, Double_t splitPoint=0.5)
Fill all empty histogram bins between bins ixlo and ixhi.
static const double x1[5]
RooAbsCachedPdf is the abstract base class for p.d.f.s that need or want to cache their evaluate() ou...
virtual Double_t offset() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
TIterator * sliceIterator(RooAbsArg &sliceArg, const RooArgSet &otherArgs)
Create an iterator over all bins in a slice defined by the subset of observables listed in sliceArg...
virtual RooArgList containedArgs(Action)
Return all RooAbsArg components contained in this cache.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
void setUnitNorm(Bool_t flag)
void interpolateGap(Int_t ixlo, Int_t ixhi)
Fill empty histogram bins between ixlo and ixhi with values obtained from linear interpolation of ixl...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
virtual TObject * Next()=0
~MorphCacheElem()
Destructor.
virtual RooArgSet * actualParameters(const RooArgSet &nset) const
Parameters of the cache.
virtual const char * inputBaseName() const
Return base name component for cache components in this case a string encoding the names of both end ...
RooBrentRootFinder * _rf1
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
friend class MorphCacheElem
void calculate(TIterator *iter)
Calculate shape of p.d.f for x,alpha values defined by dIter iterator over cache histogram.
RooAbsFunc * bindVars(const RooArgSet &vars, const RooArgSet *nset=0, Bool_t clipInvalid=kFALSE) const
Create an interface adaptor f(vars) that binds us to the specified variables (in arbitrary order)...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.