Logo ROOT  
Reference Guide
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 
28 class RooBinSamplingPdf : public RooAbsPdf {
29 public:
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(); }
69  virtual Double_t expectedEvents(const RooArgSet* nset) const override { return _pdf->expectedEvents(nset); }
70 
71  /// Forwards to the PDF's implementation.
72  Int_t getGenerator(const RooArgSet& directVars, RooArgSet& generateVars, bool staticInitOK = true) const override {
73  return _pdf->getGenerator(directVars, generateVars, staticInitOK);
74  }
75  /// Forwards to the PDF's implementation.
76  void initGenerator(Int_t code) override { _pdf->initGenerator(code); }
77  /// Forwards to the PDF's implementation.
78  void generateEvent(Int_t code) override { _pdf->generateEvent(code); }
79  /// Forwards to the PDF's implementation.
80  Bool_t isDirectGenSafe(const RooAbsArg& arg) const override { return _pdf->isDirectGenSafe(arg); }
81 
82 
83  // Hints for optimized brute-force sampling
84  Int_t getMaxVal(const RooArgSet& vars) const override { return _pdf->getMaxVal(vars); }
85  Double_t maxVal(Int_t code) const override { return _pdf->maxVal(code); }
86  Int_t minTrialSamples(const RooArgSet& arGenObs) const override { return _pdf->minTrialSamples(arGenObs); }
87 
88  // Plotting and binning hints
89  /// Returns true, since this PDF is meant to be binned.
90  bool isBinnedDistribution(const RooArgSet& /*obs*/) const override { return true; }
91  std::list<double>* binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const override;
92  std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
93 
94  std::unique_ptr<ROOT::Math::IntegratorOneDim>& integrator() const;
95 
96 
97 protected:
98  double evaluate() const override;
99  RooSpan<double> evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override;
101 
102 private:
103  template<typename Func>
105  // Call operator for our internal integrator.
106  double operator()(double x) const;
107  double integrate(const RooArgSet* normSet, double low, double high) const;
108 
109 
112  double _relEpsilon{1.E-4}; /// Default integrator precision.
113 
114  mutable std::unique_ptr<ROOT::Math::IntegratorOneDim> _integrator{nullptr}; //! Integrator used to sample bins.
115  mutable std::vector<double> _binBoundaries; //! Workspace to store data for bin sampling
116  mutable const RooArgSet* _normSetForIntegrator{nullptr}; //! Normalisation set for operator() calls.
117 
119 };
120 
121 #endif
RooAbsReal::analyticalIntegral
virtual Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
Definition: RooAbsReal.cxx:429
RooBinSamplingPdf::RooBinSamplingPdf
RooBinSamplingPdf()
Definition: RooBinSamplingPdf.h:31
ROOT::Math::WrappedFunction
Template class to wrap any C++ callable object which takes one argument i.e.
Definition: WrappedFunction.h:56
RooAbsReal.h
RooBinSamplingPdf::forceAnalyticalInt
Bool_t forceAnalyticalInt(const RooAbsArg &dep) const override
Definition: RooBinSamplingPdf.h:43
RooAbsPdf::generateEvent
virtual void generateEvent(Int_t code)
Interface for generation of an event using the algorithm corresponding to the specified code.
Definition: RooAbsPdf.cxx:2496
RooBinSamplingPdf::extendMode
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
Definition: RooBinSamplingPdf.h:68
Integrator.h
RooAbsPdf::extendMode
virtual ExtendMode extendMode() const
Returns ability of PDF to provide extended likelihood terms.
Definition: RooAbsPdf.h:234
RooBinSamplingPdf::selfNormalized
bool selfNormalized() const override
Since contained PDF is already normalised, this always returns true.
Definition: RooBinSamplingPdf.h:66
RooBinSamplingPdf::generateEvent
void generateEvent(Int_t code) override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:78
RooBinSamplingPdf::_observable
RooTemplateProxy< RooAbsRealLValue > _observable
Definition: RooBinSamplingPdf.h:111
RooBinSamplingPdf::isBinnedDistribution
bool isBinnedDistribution(const RooArgSet &) const override
Returns true, since this PDF is meant to be binned.
Definition: RooBinSamplingPdf.h:90
x
Double_t x[n]
Definition: legend1.C:17
RooAbsPdf::getGenerator
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...
Definition: RooAbsPdf.cxx:2474
RooAbsPdf::initGenerator
virtual void initGenerator(Int_t code)
Interface for one-time initialization to setup the generator for the specified code.
Definition: RooAbsPdf.cxx:2484
RooBinSamplingPdf::analyticalIntegralWN
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:57
RooBinSamplingPdf::getAnalyticalIntegral
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &numVars, const char *rangeName=0) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:52
RooTemplateProxy.h
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
RooBinSamplingPdf::isDirectGenSafe
Bool_t isDirectGenSafe(const RooAbsArg &arg) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:80
RooAbsPdf::isDirectGenSafe
virtual Bool_t isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
Definition: RooAbsPdf.cxx:2509
RooBinSamplingPdf::_integrator
std::unique_ptr< ROOT::Math::IntegratorOneDim > _integrator
Default integrator precision.
Definition: RooBinSamplingPdf.h:114
bool
RooBinSamplingPdf::minTrialSamples
Int_t minTrialSamples(const RooArgSet &arGenObs) const override
Definition: RooBinSamplingPdf.h:86
RooAbsReal::forceAnalyticalInt
virtual Bool_t forceAnalyticalInt(const RooAbsArg &) const
Definition: RooAbsReal.h:167
RooAbsPdf::ExtendMode
ExtendMode
Definition: RooAbsPdf.h:230
RooBinSamplingPdf::getMaxVal
Int_t getMaxVal(const RooArgSet &vars) const override
Advertise capability to determine maximum value of function for given set of observables.
Definition: RooBinSamplingPdf.h:84
RooAbsReal::minTrialSamples
virtual Int_t minTrialSamples(const RooArgSet &) const
Definition: RooAbsReal.h:245
RooAbsPdf.h
epsilon
REAL epsilon
Definition: triangle.c:618
RooBinSamplingPdf::~RooBinSamplingPdf
virtual ~RooBinSamplingPdf()
Definition: RooBinSamplingPdf.h:34
RooAbsPdf::analyticalIntegralWN
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Analytical integral with normalization (see RooAbsReal::analyticalIntegralWN() for further informatio...
Definition: RooAbsPdf.cxx:413
RooBinSamplingPdf::clone
virtual TObject * clone(const char *newname) const override
Definition: RooBinSamplingPdf.h:38
RooBinSamplingPdf::expectedEvents
virtual Double_t expectedEvents(const RooArgSet *nset) const override
Return expected number of events to be used in calculation of extended likelihood.
Definition: RooBinSamplingPdf.h:69
RooBinSamplingPdf::getGenerator
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:72
RooBinSamplingPdf::_pdf
RooTemplateProxy< RooAbsPdf > _pdf
Definition: RooBinSamplingPdf.h:110
RooBinSamplingPdf::_binBoundaries
std::vector< double > _binBoundaries
Integrator used to sample bins.
Definition: RooBinSamplingPdf.h:115
RooAbsReal::getMaxVal
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
Definition: RooAbsReal.cxx:3641
RooAbsReal::getAnalyticalIntegral
virtual Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Interface function getAnalyticalIntergral advertises the analytical integrals that are supported.
Definition: RooAbsReal.cxx:403
RooBinSamplingPdf::initGenerator
void initGenerator(Int_t code) override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:76
RooBinSamplingPdf::operator()
double operator()(double x) const
Binding used by the integrator to evaluate the PDF.
Definition: RooBinSamplingPdf.cxx:292
RooBinSamplingPdf::maxVal
Double_t maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
Definition: RooBinSamplingPdf.h:85
RooAbsReal::maxVal
virtual Double_t maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
Definition: RooAbsReal.cxx:3652
RooTemplateProxy< RooAbsPdf >
RooAbsReal::getAnalyticalIntegralWN
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 ...
Definition: RooAbsReal.cxx:386
Double_t
double Double_t
Definition: RtypesCore.h:59
RooBinSamplingPdf::_relEpsilon
double _relEpsilon
Definition: RooBinSamplingPdf.h:112
RooBinSamplingPdf::evaluate
double evaluate() const override
Integrate the PDF over the current bin of the observable.
Definition: RooBinSamplingPdf.cxx:138
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
RooBinSamplingPdf::plotSamplingHint
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.
Definition: RooBinSamplingPdf.cxx:235
name
char name[80]
Definition: TGX11.cxx:110
RooBinSamplingPdf
The RooBinSamplingPdf is supposed to be used as an adapter between a continuous PDF and a binned dist...
Definition: RooBinSamplingPdf.h:28
RooBinSamplingPdf::evaluateSpan
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.
Definition: RooBinSamplingPdf.cxx:161
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooBinSamplingPdf::integrator
std::unique_ptr< ROOT::Math::IntegratorOneDim > & integrator() const
Direct access to the unique_ptr holding the integrator that's used to sample the bins.
Definition: RooBinSamplingPdf.cxx:276
RooAbsPdf
Definition: RooAbsPdf.h:41
RooBinSamplingPdf::binBoundaries
RooSpan< const double > binBoundaries() const
Get the bin boundaries for the observable.
Definition: RooBinSamplingPdf.cxx:187
RooAbsRealLValue
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Definition: RooAbsRealLValue.h:31
RooBinSamplingPdf::getAnalyticalIntegralWN
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=0) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:47
RooBatchCompute::RunContext
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
RooBinSamplingPdf::analyticalIntegral
double analyticalIntegral(Int_t code, const char *rangeName=0) const override
Forwards to the PDF's implementation.
Definition: RooBinSamplingPdf.h:61
RooSpan
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33
RooBinSamplingPdf::_normSetForIntegrator
const RooArgSet * _normSetForIntegrator
Workspace to store data for bin sampling.
Definition: RooBinSamplingPdf.h:116
int
RooAbsPdf::expectedEvents
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events to be used in calculation of extended likelihood.
Definition: RooAbsPdf.cxx:3396
RooBinSamplingPdf::integrate
double integrate(const RooArgSet *normSet, double low, double high) const
Integrate the wrapped PDF using our current integrator, with given norm set and limits.
Definition: RooBinSamplingPdf.cxx:300