Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooHistPdf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_HIST_PDF
17#define ROO_HIST_PDF
18
19#include "RooAbsPdf.h"
20#include "RooRealProxy.h"
21#include "RooSetProxy.h"
22#include "RooDataHist.h"
23
24#include <list>
25
26class RooRealVar;
27class RooAbsReal;
28
29class RooHistPdf : public RooAbsPdf {
30public:
32 RooHistPdf(const char *name, const char *title, const RooArgSet& vars, const RooDataHist& dhist, Int_t intOrder=0);
33 RooHistPdf(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs, const RooDataHist& dhist, Int_t intOrder=0);
34 RooHistPdf(const char *name, const char *title, const RooArgSet& vars,
35 std::unique_ptr<RooDataHist> dhist, int intOrder=0);
36 RooHistPdf(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs,
37 std::unique_ptr<RooDataHist> dhist, int intOrder=0);
38 RooHistPdf(const RooHistPdf& other, const char* name=nullptr);
39 TObject* clone(const char* newname=nullptr) const override { return new RooHistPdf(*this,newname); }
40
42 // Return RooDataHist that is represented
43 return *_dataHist ;
44 }
45 const RooDataHist& dataHist() const {
46 // Return RooDataHist that is represented
47 return *_dataHist ;
48 }
49
50 /// Replaces underlying RooDataHist with a clone, which is now owned, and returns the clone.
51 /// If the underlying RooDataHist is already owned, then that is returned instead of being cloned.
53
55 // Set histogram interpolation order
56 _intOrder = order ;
57 }
59 // Return histogram interpolation order
60 return _intOrder ;
61 }
62
63 Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=nullptr) const override ;
64 double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override ;
65
66 bool forceAnalyticalInt(const RooAbsArg& dep) const override;
67
69 // Set use of special boundary conditions for c.d.f.s
71 }
72 bool getCdfBoundaries() const {
73 // If true, special boundary conditions for c.d.f.s are used
74 return _cdfBoundaries ;
75 }
76
77 void setUnitNorm(bool flag) {
78 // Declare contents to have unit normalization
79 _unitNorm = flag ;
80 }
81 bool haveUnitNorm() const {
82 // Return true if contents is declared to be unit normalized
83 return _unitNorm ;
84 }
85
86 bool selfNormalized() const override { return _unitNorm ; }
87
88 Int_t getMaxVal(const RooArgSet& vars) const override ;
89 double maxVal(Int_t code) const override ;
90
91 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
92 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
93 bool isBinnedDistribution(const RooArgSet&) const override { return _intOrder==0 ; }
94
95 void doEval(RooFit::EvalContext &) const override;
96
97 RooArgSet const &variables() const { return _pdfObsList; }
98
99protected:
100 bool areIdentical(const RooDataHist& dh1, const RooDataHist& dh2) ;
101
102 bool importWorkspaceHook(RooWorkspace& ws) override ;
103
104 double evaluate() const override;
105 double totalVolume() const ;
106 friend class RooAbsCachedPdf ;
107 double totVolume() const ;
108
109 RooArgSet _histObsList; ///< List of observables defining dimensions of histogram
110 RooSetProxy _pdfObsList; ///< List of observables mapped onto histogram observables
111 RooDataHist* _dataHist = nullptr; ///< Unowned pointer to underlying histogram
112 std::unique_ptr<RooDataHist> _ownedDataHist; ///<! Owned pointer to underlying histogram
113 Int_t _intOrder = 0; ///< Interpolation order
114 bool _cdfBoundaries = false; ///< Use boundary conditions for CDFs.
115 mutable double _totVolume = 0.0; ///<! Total volume of space (product of ranges of observables)
116 bool _unitNorm = false; ///< Assume contents is unit normalized (for use as pdf cache)
117
118private:
119
120 friend class RooHistFunc;
121
122 static bool forceAnalyticalInt(RooArgSet const& pdfObsList, RooAbsArg const& dep);
123
124 static Int_t getAnalyticalIntegral(RooArgSet& allVars,
126 const char* rangeName,
127 RooArgSet const& histObsList,
128 RooArgSet const& pdfObsList,
129 Int_t intOrder) ;
130
131 static double analyticalIntegral(Int_t code,
132 const char* rangeName,
133 RooArgSet const& histObsList,
134 RooArgSet const& pdfObsList,
136 bool histFuncMode) ;
137
138 static std::list<double>* plotSamplingHint(RooDataHist const& dataHist,
139 RooArgSet const& pdfObsList,
140 RooArgSet const& histObsList,
141 int intOrder,
142 RooAbsRealLValue& obs,
143 double xlo,
144 double xhi);
145
146 inline void initializeOwnedDataHist(std::unique_ptr<RooDataHist> &&dataHist)
147 {
148 // The constructor may already have taken ownership of a sanitized clone
149 // of the input histogram (see clampNegativeBins()). In that case, the
150 // clone stays and the original histogram can be disposed of.
151 if (!_ownedDataHist) {
152 _ownedDataHist = std::move(dataHist);
153 }
154 }
155
156 void clampNegativeBins();
157
158 ClassDefOverride(RooHistPdf,4) // Histogram based PDF
159};
160
161#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:148
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
Abstract base class for p.d.f.s that need or want to cache their evaluate() output in a RooHistPdf de...
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
A real-valued function sampled from a multidimensional histogram.
Definition RooHistFunc.h:29
A probability density function sampled from a multidimensional histogram.
Definition RooHistPdf.h:29
Int_t getInterpolationOrder() const
Definition RooHistPdf.h:58
void setUnitNorm(bool flag)
Definition RooHistPdf.h:77
RooArgSet _histObsList
List of observables defining dimensions of histogram.
Definition RooHistPdf.h:109
Int_t _intOrder
Interpolation order.
Definition RooHistPdf.h:113
bool forceAnalyticalInt(const RooAbsArg &dep) const override
bool areIdentical(const RooDataHist &dh1, const RooDataHist &dh2)
RooDataHist * _dataHist
Unowned pointer to underlying histogram.
Definition RooHistPdf.h:111
bool _cdfBoundaries
Use boundary conditions for CDFs.
Definition RooHistPdf.h:114
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Return sampling hint for making curves of (projections) of this function as the recursive division st...
double totVolume() const
Return the total volume spanned by the observables of the RooHistPdf.
void initializeOwnedDataHist(std::unique_ptr< RooDataHist > &&dataHist)
Definition RooHistPdf.h:146
bool importWorkspaceHook(RooWorkspace &ws) override
Check if our datahist is already in the workspace.
RooSetProxy _pdfObsList
List of observables mapped onto histogram observables.
Definition RooHistPdf.h:110
void clampNegativeBins()
bool isBinnedDistribution(const RooArgSet &) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
Definition RooHistPdf.h:93
double maxVal(Int_t code) const override
Return maximum value for set of observables identified by code assigned in getMaxVal.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Return integral identified by 'code'.
void setCdfBoundaries(bool flag)
Definition RooHistPdf.h:68
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Return sampling hint for making curves of (projections) of this function as the recursive division st...
RooDataHist & dataHist()
Definition RooHistPdf.h:41
bool haveUnitNorm() const
Definition RooHistPdf.h:81
Int_t getMaxVal(const RooArgSet &vars) const override
Only handle case of maximum in all variables.
double _totVolume
! Total volume of space (product of ranges of observables)
Definition RooHistPdf.h:115
TObject * clone(const char *newname=nullptr) const override
Definition RooHistPdf.h:39
RooDataHist * cloneAndOwnDataHist(const char *newname="")
Replaces underlying RooDataHist with a clone, which is now owned, and returns the clone.
std::unique_ptr< RooDataHist > _ownedDataHist
! Owned pointer to underlying histogram
Definition RooHistPdf.h:112
double totalVolume() const
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
bool getCdfBoundaries() const
Definition RooHistPdf.h:72
RooArgSet const & variables() const
Definition RooHistPdf.h:97
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
Definition RooHistPdf.h:86
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Determine integration scenario.
const RooDataHist & dataHist() const
Definition RooHistPdf.h:45
double evaluate() const override
Return the current value: The value of the bin enclosing the current coordinates of the observables,...
void setInterpolationOrder(Int_t order)
Definition RooHistPdf.h:54
bool _unitNorm
Assume contents is unit normalized (for use as pdf cache)
Definition RooHistPdf.h:116
Variable that can be changed from the outside.
Definition RooRealVar.h:37
Persistable container for RooFit projects.
Mother of all ROOT objects.
Definition TObject.h:42