91 using std::flush, std::endl;
107 pdf1(
"pdf1",
"pdf1",this,_pdf1),
108 pdf2(
"pdf2",
"pdf2",this,_pdf2),
110 alpha(
"alpha",
"alpha",this,_alpha),
149 std::unique_ptr<RooArgSet> par1{
pdf1->getParameters(
static_cast<RooArgSet*
>(
nullptr))};
151 pdf2->getParameters(
nullptr, par2);
152 par1->add(par2,
true) ;
153 par1->remove(
x.arg(),
true,
true) ;
155 par1->add(
alpha.arg()) ;
169 name.Append(
"_MORPH_") ;
191 double alphaSave =
alpha ;
193 coutP(Eval) <<
"RooIntegralMorph::fillCacheObject(" <<
GetName() <<
") filling multi-dimensional cache" ;
194 while(slIter->Next()) {
198 ccoutP(Eval) <<
"." << flush;
200 ccoutP(Eval) << std::endl;
220 ret.add(PdfCacheElem::containedArgs(action)) ;
251 _nset = std::make_unique<RooArgSet>(*
_x);
253 _c1 = std::unique_ptr<RooAbsReal>{
_pdf1->createCdf(*
_x)};
254 _c2 = std::unique_ptr<RooAbsReal>{
_pdf2->createCdf(*
_x)};
255 _cb1 = std::unique_ptr<RooAbsFunc>{
_c1->bindVars(*
_x,
_nset.get())};
256 _cb2 = std::unique_ptr<RooAbsFunc>{
_c2->bindVars(*
_x,
_nset.get())};
258 _rf1 = std::make_unique<RooBrentRootFinder>(*
_cb1);
259 _rf2 = std::make_unique<RooBrentRootFinder>(*
_cb2);
261 _rf1->setTol(1
e-12) ;
262 _rf2->setTol(1
e-12) ;
285 oocoutW(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElem::calcX() WARNING: requested root finding for unphysical CDF value " <<
y << std::endl ;
290 double xmax =
_x->getMax(
"cache") ;
291 double xmin =
_x->getMin(
"cache") ;
307 double xmax =
_x->getMax(
"cache") ;
308 double xmin =
_x->getMin(
"cache") ;
318 double xsave =
_self->x ;
325 _yatX.resize(
_x->numBins(
"cache")+1);
326 _calcX.resize(
_x->numBins(
"cache")+1);
331 Int_t nbins =
_x->numBins(
"cache") ;
334 for (
int i=0 ; i<nbins ; i++) {
343 for (
int i=0 ; i<10 ; i++) {
364 Int_t igapHigh = igapLow+1 ;
372 igapLow = igapHigh+1 ;
376 double xmax =
_x->getMax(
"cache") ;
377 double xmin =
_x->getMin(
"cache") ;
378 double binw = (
xmax-
xmin)/
_x->numBins(
"cache") ;
382 double xBinC =
xmin + (i+0.5)*binw ;
383 double xOffset = xBinC-
_calcX[i] ;
384 if (std::abs(xOffset/binw)>1
e-3) {
386 double newY =
_yatX[i] + slope*xOffset ;
395 const std::size_t binIdx =
hist()->getIndex(*
hist()->get(),
true);
396 hist()->set(binIdx, 0, -1) ;
399 double x1 =
_x->getMin(
"cache");
400 double x2 =
_x->getMin(
"cache");
402 double xMax =
_x->getMax(
"cache");
413 _rf1->findRoot(x1,x1,xMax,
y) ;
414 _rf2->findRoot(x2,x2,xMax,
y) ;
420 double fbarX = f1x1*f2x2 / (
_alpha->getVal()*f2x2 + (1-
_alpha->getVal())*f1x1 ) ;
424 const std::size_t binIdx =
hist()->getIndex(*
hist()->get(),
true);
425 hist()->set(binIdx, fbarX, -1) ;
429 for (
int i=
_yatXmax+1 ; i<nbins ; i++) {
431 const std::size_t binIdx =
hist()->getIndex(*
hist()->get(),
true);
432 hist()->set(binIdx, 0, -1) ;
435 pdf()->setUnitNorm(
true) ;
438 oocxcoutD(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElem::calculate(" <<
_self->GetName() <<
") calculation required " <<
_ccounter <<
" samplings of cdfs" << std::endl ;
453 oocoutE(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" <<
_self->GetName() <<
"): ERROR in fillgap " << ixlo <<
" = " << ixhi
454 <<
" splitPoint= " << splitPoint <<
" _yatX[ixlo] = " <<
_yatX[ixlo] << std::endl ;
457 oocoutE(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" <<
_self->GetName() <<
"): ERROR in fillgap " << ixlo <<
" = " << ixhi
458 <<
" splitPoint " << splitPoint <<
" _yatX[ixhi] = " <<
_yatX[ixhi] << std::endl ;
462 double ymid =
_yatX[ixlo]*splitPoint +
_yatX[ixhi]*(1-splitPoint) ;
464 double Xmid =
calcX(ymid,ok) ;
466 oocoutW(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElem::fillGap(" <<
_self->GetName() <<
") unable to calculate midpoint in gap ["
467 << ixlo <<
"," << ixhi <<
"], resorting to interpolation" << std::endl ;
480 if (std::abs(cq)<0.01 || std::abs(cq*(ixhi-ixlo))<0.1 || ymid<
_ycutoff ) {
494 if (splitPoint<0.95) {
496 double newSplit = splitPoint + 0.5*(1-splitPoint) ;
503 }
else if (iX==ixhi) {
506 if (splitPoint>0.05) {
507 double newSplit = splitPoint/2 ;
535 double xmax =
_x->getMax(
"cache") ;
536 double xmin =
_x->getMin(
"cache") ;
537 double binw = (
xmax-
xmin)/
_x->numBins(
"cache") ;
543 double xBinC =
xmin + (ixlo+0.5)*binw ;
544 double xOffset = xBinC-
_calcX[ixlo] ;
546 for (
int j=ixlo+1 ; j<ixhi ; j++) {
547 _yatX[j] =
_yatX[ixlo]+(xOffset+(j-ixlo))*deltaY ;
562 double xmin =
_x->getMin(
"cache") ;
563 double xmax =
_x->getMax(
"cache") ;
564 Int_t nbins =
_x->numBins(
"cache") ;
579 oocxcoutD(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" <<
_self->GetName() <<
") findMin: x1 = " << x1 <<
" x2 = " << x2 <<
" ok = " << (ok?
"T":
"F") << std::endl ;
586 if (std::abs(
X-Xlast)/(
xmax-
xmin)<0.0001) {
610 double deltaymax = 0.1;
611 double deltaymaxSave(-1);
617 oocxcoutD(
_self,Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" <<
_self->GetName() <<
") findMax: x1 = " << x1 <<
" x2 = " << x2 <<
" ok = " << (ok?
"T":
"F") << std::endl ;
624 if (std::abs(
X-Xlast)/(
xmax-
xmin)<0.0001) {
633 deltaymaxSave = deltaymax ;
637 deltaymax /=sqrt(10.) ;
672 orderedObs.
add(obs) ;
675 orderedObs.
remove(*obsX) ;
676 orderedObs.
add(*obsX) ;
int Int_t
Signed integer 4 bytes (int).
Common abstract base class for objects that represent a value and a "shape" in RooFit.
PdfCacheElem(const RooAbsCachedPdf &self, const RooArgSet *nset)
Constructor of cache object which owns RooDataHist cache histogram, RooHistPdf pdf that represents is...
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsPdf()
Default constructor.
virtual double offset() const
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
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.
const RooArgSet * get() const override
Get bin centre of current bin.
void setUnitNorm(bool flag)
std::vector< double > _yatX
~MorphCacheElem() override
Destructor.
std::unique_ptr< RooBrentRootFinder > _rf1
std::unique_ptr< RooAbsReal > _c1
void calculate(TIterator *iter)
Calculate shape of p.d.f for x,alpha values defined by dIter iterator over cache histogram.
void interpolateGap(Int_t ixlo, Int_t ixhi)
Fill empty histogram bins between ixlo and ixhi with values obtained from linear interpolation of ixl...
MorphCacheElem(RooIntegralMorph &self, const RooArgSet *nset)
Construct of cache element, copy relevant input from RooIntegralMorph, create the cdfs from the input...
std::unique_ptr< RooAbsFunc > _cb2
void fillGap(Int_t ixlo, Int_t ixhi, double splitPoint=0.5)
Fill all empty histogram bins between bins ixlo and ixhi.
std::unique_ptr< RooArgSet > _nset
void findRange()
Determine which range of y values can be mapped to x values from the numeric inversion of the input c...
std::unique_ptr< RooAbsFunc > _cb1
std::unique_ptr< RooBrentRootFinder > _rf2
std::vector< double > _calcX
RooArgList containedArgs(Action) override
Return all RooAbsArg components contained in this cache.
std::unique_ptr< RooAbsReal > _c2
double calcX(double y, bool &ok)
Calculate the x value of the output p.d.f at the given cdf value y.
Int_t binX(double x)
Return the bin number enclosing the given x value.
RooIntegralMorph()=default
RooFit::OwningPtr< RooArgSet > actualObservables(const RooArgSet &nset) const override
Observable to be cached for given choice of normalization.
friend class MorphCacheElem
PdfCacheElem * createCache(const RooArgSet *nset) const override
Create and return a derived MorphCacheElem.
const char * inputBaseName() const override
Return base name component for cache components in this case a string encoding the names of both end ...
void preferredObservableScanOrder(const RooArgSet &obs, RooArgSet &orderedObs) const override
Indicate to the RooAbsCachedPdf base class that for the filling of the cache the traversal of the x s...
void fillCacheObject(PdfCacheElem &cache) const override
Fill the cache with the interpolated shape.
double evaluate() const override
Dummy.
RooFit::OwningPtr< RooArgSet > actualParameters(const RooArgSet &nset) const override
Parameters of the cache.
Variable that can be changed from the outside.
Iterator abstract base class.
virtual TObject * Next()=0
const char * GetName() const override
Returns name of object.
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.