117 _pdf(
"inputPdf",
"Function to be converted into a PDF", this, inputPdf),
118 _observable(
"observable",
"Observable to integrate over", this, observable, true, true),
121 throw std::invalid_argument(std::string(
"RooBinSamplingPDF(") +
GetName()
122 +
"): The PDF " +
_pdf->
GetName() +
" needs to depend on the observable "
134 _pdf(
"inputPdf", this, other._pdf),
135 _observable(
"observable", this, other._observable),
136 _relEpsilon(other._relEpsilon) { }
168 auto results = evalData.
makeBatch(
this, xValues.size());
174 for (
unsigned int i=0; i < xValues.size(); ++i) {
175 const double x = xValues[i];
176 const auto upperIt = std::upper_bound(boundaries.begin(), boundaries.end(),
x);
177 const unsigned int bin = std::distance(boundaries.begin(), upperIt) - 1;
178 assert(bin < boundaries.size());
180 results[i] =
integrate(normSet, boundaries[bin], boundaries[bin+1]) / (boundaries[bin+1]-boundaries[bin]);
194 const double* boundaries = binning.
array();
217 coutE(Plotting) <<
"RooBinSamplingPdf::binBoundaries(" <<
GetName() <<
"): observable '" << obs.
GetName()
218 <<
"' is not the observable of this PDF ('" <<
_observable->
GetName() <<
"')." << std::endl;
222 auto list =
new std::list<double>;
224 if (xlo <= val && val < xhi)
225 list->push_back(val);
240 coutE(Plotting) <<
"RooBinSamplingPdf::plotSamplingHint(" <<
GetName() <<
"): observable '" << obs.
GetName()
241 <<
"' is not the observable of this PDF ('" <<
_observable->
GetName() <<
"')." << std::endl;
245 auto binEdges =
new std::list<double>;
248 for (
unsigned int bin=0, numBins =
static_cast<unsigned int>(binning.numBins()); bin < numBins; ++bin) {
249 const double low = std::max(binning.binLow(bin), xlo);
250 const double high = std::min(binning.binHigh(bin), xhi);
251 const double width = high - low;
258 binEdges->push_back(low + 0.001 *
width);
259 binEdges->push_back(high - 0.001 *
width);
318 const bool oneDimAndBinned = (1 == std::count_if(funcObservables->begin(), funcObservables->end(), [](
const RooAbsArg* arg) {
319 auto var = dynamic_cast<const RooRealVar*>(arg);
320 return var && var->numBins() > 1;
323 if (!oneDimAndBinned) {
324 if (precision > 0.) {
326 <<
"Integration over bins was requested, but this is currently only implemented for 1-D fits." << std::endl;
332 auto theObs = std::find_if(funcObservables->begin(), funcObservables->end(), [](
const RooAbsArg* arg){
333 return dynamic_cast<const RooAbsRealLValue*>(arg);
335 assert(theObs != funcObservables->end());
337 std::unique_ptr<RooAbsPdf> newPdf;
339 if (precision > 0.) {
341 newPdf = std::make_unique<RooBinSamplingPdf>(
344 }
else if (
dynamic_cast<RooDataHist const *
>(&data) !=
nullptr &&
348 newPdf = std::make_unique<RooBinSamplingPdf>(
include TDocParser_001 C image html pict1_TDocParser_001 png width
User Class for performing numerical integration of a function in one dimension.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Given a set of possible observables, return the observables that this PDF depends on.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Bool_t isShapeDirty() const
Bool_t inhibitDirty() const
Delete watch flag.
void clearShapeDirty() const
RooAbsBinning is the abstract base class for RooRealVar binning definitions.
virtual Double_t binLow(Int_t bin) const =0
virtual Double_t * array() const =0
virtual Double_t binHigh(Int_t bin) const =0
virtual Int_t numBoundaries() const =0
RooAbsData is the common abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
RooArgSet const * _normSet
Normalization integral (owned by _normMgr)
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual const RooAbsBinning & getBinning(const char *name=0, Bool_t verbose=kTRUE, Bool_t createOnTheFly=kFALSE) const =0
Retrive binning configuration with given name or default binning.
virtual void setVal(Double_t value)=0
Set the current value of the object. Needs to be overridden by implementations.
virtual Int_t getBin(const char *rangeName=0) const
virtual RooSpan< const double > getValues(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet=nullptr) const
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
The RooBinSamplingPdf is supposed to be used as an adapter between a continuous PDF and a binned dist...
double integrate(const RooArgSet *normSet, double low, double high) const
Integrate the wrapped PDF using our current integrator, with given norm set and limits.
RooTemplateProxy< RooAbsPdf > _pdf
std::vector< double > _binBoundaries
Integrator used to sample bins.
std::unique_ptr< ROOT::Math::IntegratorOneDim > & integrator() const
Direct access to the unique_ptr holding the integrator that's used to sample the bins.
RooTemplateProxy< RooAbsRealLValue > _observable
RooSpan< const double > binBoundaries() const
Get the bin boundaries for the observable.
std::unique_ptr< ROOT::Math::IntegratorOneDim > _integrator
Default integrator precision.
static std::unique_ptr< RooAbsPdf > create(RooAbsPdf &pdf, RooAbsData const &data, double precision)
Creates a wrapping RooBinSamplingPdf if appropriate.
double operator()(double x) const
Binding used by the integrator to evaluate the PDF.
double evaluate() const override
Integrate the PDF over the current bin of the observable.
const RooAbsPdf & pdf() const
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Return a list of all bin edges, so the PDF is plotted as a step function.
RooSpan< double > evaluateSpan(RooBatchCompute::RunContext &evalData, const RooArgSet *normSet) const override
Integrate the PDF over all its bins, and return a batch with those values.
The RooDataHist is a container class to hold N-dimensional binned data.
A simple container to hold a batch of data values.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
@ kADAPTIVE
to be used for general functions without singularities
This struct enables passing computation data around between elements of a computation graph.
RooSpan< double > makeBatch(const RooAbsArg *owner, std::size_t size)
Create a writable batch.
Disable all caches for sub-branches in an expression tree.