89using std::flush, std::endl;
100 pdf1(
"pdf1",
"pdf1",
this, _pdf1),
101 pdf2(
"pdf2",
"pdf2",
this, _pdf2),
102 x(
"x",
"x",
this, _x),
103 alpha(
"alpha",
"alpha",
this, _alpha),
117 _cacheAlpha(
other._cacheAlpha)
162 name.Append(
"_MORPH_");
182 std::unique_ptr<TIterator>
slIter{
187 coutP(Eval) <<
"RooIntegralMorph::fillCacheObject(" <<
GetName() <<
") filling multi-dimensional cache";
190 std::unique_ptr<TIterator>
dIter{
193 ccoutP(Eval) <<
"." << flush;
195 ccoutP(Eval) << std::endl;
215 ret.add(PdfCacheElem::containedArgs(
action));
246 _nset = std::make_unique<RooArgSet>(*
_x);
250 _cb1 = std::unique_ptr<RooAbsFunc>{
_c1->bindVars(*
_x,
_nset.get())};
251 _cb2 = std::unique_ptr<RooAbsFunc>{
_c2->bindVars(*
_x,
_nset.get())};
253 _rf1 = std::make_unique<RooBrentRootFinder>(*
_cb1);
254 _rf2 = std::make_unique<RooBrentRootFinder>(*
_cb2);
279 <<
"RooIntegralMorph::MorphCacheElem::calcX() WARNING: requested root finding for unphysical CDF value " <<
y
285 double xmax = _x->getMax(
"cache");
286 double xmin = _x->getMin(
"cache");
295 return _alpha->getVal() *
x1 + (1 - _alpha->getVal()) *
x2;
303 double xmax = _x->getMax(
"cache");
304 double xmin = _x->getMin(
"cache");
314 double xsave = _self->x;
321 _yatX.resize(_x->numBins(
"cache") + 1);
322 _calcX.resize(_x->numBins(
"cache") + 1);
329 oocoutE(_self, Eval) <<
"RooIntegralMorph::MorphCacheElem::calculate(" << _self->GetName()
330 <<
") ERROR: observable " << _x->GetName()
331 <<
" has an empty binning for the cache histogram."
332 <<
" Define one with RooRealVar::setBins(nbins, \"cache\")." << std::endl;
337 for (
int i = 0; i <
nbins; i++) {
346 for (
int i = 0; i < 10; i++) {
349 double offset = _yatX[_yatXmin];
350 double delta = (_yatX[_yatXmax] - _yatX[_yatXmin]) / 10;
355 double X = calcX(
y, ok);
381 double xmax = _x->getMax(
"cache");
382 double xmin = _x->getMin(
"cache");
384 for (
int i = _yatXmin + 1; i < _yatXmax - 1; i++) {
390 double slope = (_yatX[i + 1] - _yatX[i - 1]) / (_calcX[i + 1] - _calcX[i - 1]);
399 for (
int i = 0; i < _yatXmin; i++) {
401 const std::size_t
binIdx = hist()->getIndex(*hist()->get(),
true);
402 hist()->set(
binIdx, 0, -1);
405 double xMax = _x->getMax(
"cache");
406 const double aval = _alpha->getVal();
412 double x1lo = _x->getMin(
"cache");
413 double x2lo = _x->getMin(
"cache");
416 for (
int i = _yatXmin; i <= _yatXmax; i++) {
431 for (
int iter = 0; iter < 10; iter++) {
432 bool ok = _rf1->findRoot(
x1,
x1lo, xMax,
y);
433 ok &= _rf2->findRoot(
x2,
x2lo, xMax,
y);
435 f1x1 = _pdf1->getVal(_nset.get());
437 f2x2 = _pdf2->getVal(_nset.get());
455 const std::size_t
binIdx = hist()->getIndex(*hist()->get(),
true);
463 for (
int i = _yatXmax + 1; i <
nbins; i++) {
465 const std::size_t
binIdx = hist()->getIndex(*hist()->get(),
true);
466 hist()->set(
binIdx, 0, -1);
469 pdf()->setUnitNorm(
true);
472 oocxcoutD(_self, Eval) <<
"RooIntegralMorph::MorphCacheElem::calculate(" << _self->GetName()
473 <<
") calculation required " << _ccounter <<
" samplings of cdfs" << std::endl;
488 if (_yatX[
ixlo] < 0) {
489 oocoutE(_self, Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" << _self->GetName() <<
"): ERROR in fillgap "
493 if (_yatX[
ixhi] < 0) {
494 oocoutE(_self, Eval) <<
"RooIntegralMorph::MorphCacheElme::fillGap(" << _self->GetName() <<
"): ERROR in fillgap "
504 oocoutW(_self, Eval) <<
"RooIntegralMorph::MorphCacheElem::fillGap(" << _self->GetName()
505 <<
") unable to calculate midpoint in gap [" <<
ixlo <<
"," <<
ixhi
506 <<
"], resorting to interpolation" << std::endl;
519 if (std::abs(
cq) < 0.01 || std::abs(
cq * (
ixhi -
ixlo)) < 0.1 ||
ymid < _ycutoff) {
574 double xmax = _x->getMax(
"cache");
575 double xmin = _x->getMin(
"cache");
600 double xmin = _x->getMin(
"cache");
601 double xmax = _x->getMax(
"cache");
617 oocxcoutD(_self, Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" << _self->GetName()
618 <<
") findMin: x1 = " <<
x1 <<
" x2 = " <<
x2 <<
" ok = " << (ok ?
"T" :
"F") << std::endl;
625 double X = _alpha->getVal() *
x1 + (1 - _alpha->getVal()) *
x2;
633 _yatX[_yatXmin] =
ymin;
634 _calcX[_yatXmin] =
X;
646 _calcX[_yatXmin] =
Xsave;
658 oocxcoutD(_self, Eval) <<
"RooIntegralMorph::MorphCacheElem::findRange(" << _self->GetName()
659 <<
") findMax: x1 = " <<
x1 <<
" x2 = " <<
x2 <<
" ok = " << (ok ?
"T" :
"F") << std::endl;
666 double X = _alpha->getVal() *
x1 + (1 - _alpha->getVal()) *
x2;
675 _calcX[_yatXmax] =
X;
688 _calcX[_yatXmax] =
Xsave;
691 for (
int i = 0; i < _yatXmin; i++)
693 for (
int i = _yatXmax + 1; i <
nbins; i++)
695 oocxcoutD(_self, Eval) <<
"RooIntegralMorph::findRange(" << _self->GetName() <<
"): ymin = " << _yatX[_yatXmin]
696 <<
" ymax = " << _yatX[_yatXmax] << std::endl;
697 oocxcoutD(_self, Eval) <<
"RooIntegralMorph::findRange(" << _self->GetName() <<
"): xmin = " << _calcX[_yatXmin]
698 <<
" xmax = " << _calcX[_yatXmax] << std::endl;
int Int_t
Signed integer 4 bytes (int)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Abstract base class for p.d.f.s that need or want to cache their evaluate() output in a RooHistPdf de...
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
RooFit::OwningPtr< 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.
Abstract base class for objects that represent a real value and implements functionality common to al...
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)
~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
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.
Class RooIntegralMorph is an implementation of the histogram interpolation technique described by Ale...
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.
const T & arg() const
Return reference to object held in proxy.
Iterator abstract base class.
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.