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
35 RooBinSamplingPdf(const RooBinSamplingPdf& other, const char* name = 0);
36
37 virtual TObject* clone(const char* newname) const override {
38 return new RooBinSamplingPdf(*this, newname);
39 }
40
41 // Analytical Integration handling
42 Bool_t forceAnalyticalInt(const RooAbsArg& dep) const override {
43 return _pdf->forceAnalyticalInt(dep);
44 }
45 /// Forwards to the PDF's implementation.
46 Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars, const RooArgSet* normSet,
47 const char* rangeName=0) const override {
48 return _pdf->getAnalyticalIntegralWN(allVars, analVars, normSet, rangeName);
49 }
50 /// Forwards to the PDF's implementation.
52 const char* rangeName=0) const override {
53 return _pdf->getAnalyticalIntegral(allVars, numVars, rangeName);
54 }
55 /// Forwards to the PDF's implementation.
56 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const override {
57 return _pdf->analyticalIntegralWN(code, normSet, rangeName);
58 }
59 /// Forwards to the PDF's implementation.
60 double analyticalIntegral(Int_t code, const char* rangeName=0) const override {
61 return _pdf->analyticalIntegral(code, rangeName);
62 }
63
64 /// Forwards to the PDF's implementation.
65 bool selfNormalized() const override { return true; }
66
67 /// Forwards to the PDF's implementation.
69 const RooArgSet* nset=nullptr,
70 const RooNumIntConfig* cfg=nullptr,
71 const char* rangeName=nullptr) const override {
72 return _pdf->createIntegral(iset, nset, cfg, rangeName);
73 }
74
75 ExtendMode extendMode() const override { return _pdf->extendMode(); }
76 virtual Double_t expectedEvents(const RooArgSet* nset) const override { return _pdf->expectedEvents(nset); }
77
78 /// Forwards to the PDF's implementation.
79 Int_t getGenerator(const RooArgSet& directVars, RooArgSet& generateVars, bool staticInitOK = true) const override {
80 return _pdf->getGenerator(directVars, generateVars, staticInitOK);
81 }
82 /// Forwards to the PDF's implementation.
83 void initGenerator(Int_t code) override { _pdf->initGenerator(code); }
84 /// Forwards to the PDF's implementation.
85 void generateEvent(Int_t code) override { _pdf->generateEvent(code); }
86 /// Forwards to the PDF's implementation.
87 Bool_t isDirectGenSafe(const RooAbsArg& arg) const override { return _pdf->isDirectGenSafe(arg); }
88
89
90 // Hints for optimized brute-force sampling
91 Int_t getMaxVal(const RooArgSet& vars) const override { return _pdf->getMaxVal(vars); }
92 Double_t maxVal(Int_t code) const override { return _pdf->maxVal(code); }
93 Int_t minTrialSamples(const RooArgSet& arGenObs) const override { return _pdf->minTrialSamples(arGenObs); }
94
95 // Plotting and binning hints
96 /// Returns true, since this PDF is meant to be binned.
97 bool isBinnedDistribution(const RooArgSet& /*obs*/) const override { return true; }
98 std::list<double>* binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const override;
99 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
100
101 std::unique_ptr<ROOT::Math::IntegratorOneDim>& integrator() const;
102
103 static std::unique_ptr<RooAbsPdf> create(RooAbsPdf& pdf, RooAbsData const &data, double precision);
104
105 double epsilon() const { return _relEpsilon; }
106 const RooAbsPdf& pdf() const { return _pdf.arg(); }
107 const RooAbsReal& observable() const { return _observable.arg(); }
108
109 std::unique_ptr<RooArgSet> fillNormSetForServer(RooArgSet const& /*normSet*/,
110 RooAbsArg const& /*server*/) const override {
111 // servers are evaluated unnormalized
112 return std::make_unique<RooArgSet>();
113 }
114
115protected:
116 double evaluate() const override;
117 RooSpan<double> evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override;
119
120private:
121 template<typename Func>
123 // Call operator for our internal integrator.
124 double operator()(double x) const;
125 double integrate(const RooArgSet* normSet, double low, double high) const;
126
127
130 double _relEpsilon{1.E-4}; /// Default integrator precision.
131
132 mutable std::unique_ptr<ROOT::Math::IntegratorOneDim> _integrator{nullptr}; //! Integrator used to sample bins.
133 mutable std::vector<double> _binBoundaries; //! Workspace to store data for bin sampling
134
136};
137
138#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:69
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:82
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 to be used in calculation of extended likelihood.
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:260
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:64
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 ...
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
virtual Bool_t forceAnalyticalInt(const RooAbsArg &) const
Definition RooAbsReal.h:171
virtual Int_t minTrialSamples(const RooArgSet &) const
Definition RooAbsReal.h:249
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:35
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 to be used in calculation of extended likelihood.
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.
double epsilon() const
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.
RooAbsReal * createIntegral(const RooArgSet &iset, const RooArgSet *nset=nullptr, const RooNumIntConfig *cfg=nullptr, const char *rangeName=nullptr) const override
Forwards to the PDF's implementation.
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.
std::unique_ptr< RooArgSet > fillNormSetForServer(RooArgSet const &, RooAbsArg const &) const override
Fills a RooArgSet to be used as the normalization set for a server, given a normalization set for thi...
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.
static std::unique_ptr< RooAbsPdf > create(RooAbsPdf &pdf, RooAbsData const &data, double precision)
Creates a wrapping RooBinSamplingPdf if appropriate.
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
Forwards to the PDF's implementation.
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
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.
Bool_t forceAnalyticalInt(const RooAbsArg &dep) const override
const RooAbsReal & observable() const
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.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
A simple container to hold a batch of data values.
Definition RooSpan.h:34
const T & arg() const
Return reference to object held in proxy.
Mother of all ROOT objects.
Definition TObject.h:41
Double_t x[n]
Definition legend1.C:17
This struct enables passing computation data around between elements of a computation graph.
Definition RunContext.h:32