Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooBinSamplingPdf.h
Go to the documentation of this file.
1// Authors: Stephan Hageboeck, CERN; Andrea Sciandra, SCIPP-UCSC/Atlas; Nov 2020
2
3/*****************************************************************************
4 * Project: RooFit *
5 * Package: RooFitCore *
6 * Authors: *
7 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
8 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
9 * *
10 * Copyright (c) 2000-2018, Regents of the University of California *
11 * and Stanford University. All rights reserved. *
12 * *
13 * Redistribution and use in source and binary forms, *
14 * with or without modification, are permitted according to the terms *
15 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
16 *****************************************************************************/
17#ifndef ROO_BIN_SAMPLING__PDF
18#define ROO_BIN_SAMPLING__PDF
19
20#include "RooAbsReal.h"
21#include "RooTemplateProxy.h"
22#include "RooAbsPdf.h"
23
24#include "Math/Integrator.h"
25
26#include <memory>
27
29public:
30
32 RooBinSamplingPdf(const char *name, const char *title, RooAbsRealLValue& observable, RooAbsPdf& inputPdf,
33 double epsilon = 1.E-4);
34 virtual ~RooBinSamplingPdf() {};
35
36 RooBinSamplingPdf(const RooBinSamplingPdf& other, const char* name = 0);
37
38 virtual TObject* clone(const char* newname) const override {
39 return new RooBinSamplingPdf(*this, newname);
40 }
41
42 // Analytical Integration handling
43 Bool_t forceAnalyticalInt(const RooAbsArg& dep) const override {
44 return _pdf->forceAnalyticalInt(dep);
45 }
46 /// Forwards to the PDF's implementation.
47 Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet,
48 const char* rangeName=0) const override {
49 return _pdf->getAnalyticalIntegralWN(allVars, analVars, normSet, rangeName);
50 }
51 /// Forwards to the PDF's implementation.
53 const char* rangeName=0) const override {
54 return _pdf->getAnalyticalIntegral(allVars, numVars, rangeName);
55 }
56 /// Forwards to the PDF's implementation.
57 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const override {
58 return _pdf->analyticalIntegralWN(code, normSet, rangeName);
59 }
60 /// Forwards to the PDF's implementation.
61 double analyticalIntegral(Int_t code, const char* rangeName=0) const override {
62 return _pdf->analyticalIntegral(code, rangeName);
63 }
64
65 /// Since contained PDF is already normalised, this always returns true.
66 bool selfNormalized() const override { return true; }
67
68 ExtendMode extendMode() const override { return _pdf->extendMode(); }
70 virtual Double_t expectedEvents(const RooArgSet* nset) const override { return _pdf->expectedEvents(nset); }
71
72 /// Forwards to the PDF's implementation.
73 Int_t getGenerator(const RooArgSet& directVars, RooArgSet& generateVars, bool staticInitOK = true) const override {
74 return _pdf->getGenerator(directVars, generateVars, staticInitOK);
75 }
76 /// Forwards to the PDF's implementation.
77 void initGenerator(Int_t code) override { _pdf->initGenerator(code); }
78 /// Forwards to the PDF's implementation.
79 void generateEvent(Int_t code) override { _pdf->generateEvent(code); }
80 /// Forwards to the PDF's implementation.
81 Bool_t isDirectGenSafe(const RooAbsArg& arg) const override { return _pdf->isDirectGenSafe(arg); }
82
83
84 // Hints for optimized brute-force sampling
85 Int_t getMaxVal(const RooArgSet& vars) const override { return _pdf->getMaxVal(vars); }
86 Double_t maxVal(Int_t code) const override { return _pdf->maxVal(code); }
87 Int_t minTrialSamples(const RooArgSet& arGenObs) const override { return _pdf->minTrialSamples(arGenObs); }
88
89 // Plotting and binning hints
90 /// Returns true, since this PDF is meant to be binned.
91 bool isBinnedDistribution(const RooArgSet& /*obs*/) const override { return true; }
92 std::list<double>* binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const override;
93 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
94
95 std::unique_ptr<ROOT::Math::IntegratorOneDim>& integrator() const;
96
97
98protected:
99 double evaluate() const override;
100 RooSpan<double> evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override;
102
103private:
104 template<typename Func>
106 // Call operator for our internal integrator.
107 double operator()(double x) const;
108 double integrate(const RooArgSet* normSet, double low, double high) const;
109
110
113 double _relEpsilon{1.E-4}; /// Default integrator precision.
114
115 mutable std::unique_ptr<ROOT::Math::IntegratorOneDim> _integrator{nullptr}; //! Integrator used to sample bins.
116 mutable std::vector<double> _binBoundaries; //! Workspace to store data for bin sampling
117 mutable const RooArgSet* _normSetForIntegrator{nullptr}; //! Normalisation set for operator() calls.
118
120};
121
122#endif
double Double_t
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
char name[80]
Definition TGX11.cxx:110
Template class to wrap any C++ callable object which takes one argument i.e.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
virtual void generateEvent(Int_t code)
Interface for generation of an event using the algorithm corresponding to the specified code.
virtual Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Analytical integral with normalization (see RooAbsReal::analyticalIntegralWN() for further informatio...
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
virtual Bool_t isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
virtual void initGenerator(Int_t code)
Interface for one-time initialization to setup the generator for the specified code.
virtual ExtendMode extendMode() const
Returns ability of PDF to provide extended likelihood terms.
Definition RooAbsPdf.h:236
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=0) const
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
virtual Bool_t forceAnalyticalInt(const RooAbsArg &) const
Definition RooAbsReal.h:167
virtual Int_t minTrialSamples(const RooArgSet &) const
Definition RooAbsReal.h:245
virtual Double_t maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
virtual Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
virtual Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
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.
virtual Double_t expectedEvents(const RooArgSet *nset) const override
Return expected number of events from this p.d.f for use in extended likelihood calculations.
const RooArgSet * _normSetForIntegrator
Workspace to store data for bin sampling.
std::unique_ptr< ROOT::Math::IntegratorOneDim > & integrator() const
Direct access to the unique_ptr holding the integrator that's used to sample the bins.
double analyticalIntegral(Int_t code, const char *rangeName=0) const override
Forwards to the PDF's implementation.
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &numVars, const char *rangeName=0) const override
Forwards to the PDF's implementation.
RooTemplateProxy< RooAbsRealLValue > _observable
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Forwards to the PDF's implementation.
RooSpan< const double > binBoundaries() const
Get the bin boundaries for the observable.
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=0) const override
Forwards to the PDF's implementation.
void initGenerator(Int_t code) override
Forwards to the PDF's implementation.
virtual TObject * clone(const char *newname) const override
std::unique_ptr< ROOT::Math::IntegratorOneDim > _integrator
Default integrator precision.
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
Int_t getMaxVal(const RooArgSet &vars) const override
Advertise capability to determine maximum value of function for given set of observables.
void generateEvent(Int_t code) override
Forwards to the PDF's implementation.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName) const override
Forwards to the PDF's implementation.
Bool_t isDirectGenSafe(const RooAbsArg &arg) const override
Forwards to the PDF's implementation.
bool isBinnedDistribution(const RooArgSet &) const override
Returns true, since this PDF is meant to be binned.
double operator()(double x) const
Binding used by the integrator to evaluate the PDF.
bool selfNormalized() const override
Since contained PDF is already normalised, this always returns true.
Double_t maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
double evaluate() const override
Integrate the PDF over the current bin of the observable.
Int_t minTrialSamples(const RooArgSet &arGenObs) const override
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.
Bool_t forceAnalyticalInt(const RooAbsArg &dep) const override
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.
A simple container to hold a batch of data values.
Definition RooSpan.h:34
Mother of all ROOT objects.
Definition TObject.h:37
Double_t x[n]
Definition legend1.C:17
This struct enables passing computation data around between elements of a computation graph.
Definition RunContext.h:31
REAL epsilon
Definition triangle.c:617