Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsPdf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooAbsPdf.h,v 1.90 2007/07/21 21:32:52 wouter Exp $
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_ABS_PDF
17#define ROO_ABS_PDF
18
19#include <RooAbsReal.h>
20#include <RooDataHist.h>
21#include <RooDataSet.h>
22#include <RooFit/UniqueId.h>
23#include <RooGlobalFunc.h>
24#include <RooObjCacheManager.h>
25
26#include <ROOT/RConfig.hxx> // for R__DEPRECATED
27
28class RooArgSet ;
29class RooAbsGenContext ;
30class RooFitResult ;
31class RooExtendPdf ;
32class RooCategory ;
33class TPaveText;
34class TH1F;
35class TH2F;
36class TList ;
37class RooMinimizer ;
38class RooNumGenConfig ;
39class RooRealIntegral ;
40
41
42class RooAbsPdf : public RooAbsReal {
43public:
44
45 // Constructors, assignment etc
46 RooAbsPdf() ;
47 RooAbsPdf(const char *name, const char *title=nullptr) ;
48 RooAbsPdf(const char *name, const char *title, double minVal, double maxVal) ;
49 // RooAbsPdf(const RooAbsPdf& other, const char* name=nullptr);
50 ~RooAbsPdf() override;
51
52 // Toy MC generation
53
54 ////////////////////////////////////////////////////////////////////////////////
55 /// See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&)
56 /// \param[in] whatVars Set of observables to generate for each event according to this model.
57 /// \param[in] nEvents How many events to generate
58 /// \param arg1,arg2,arg3,arg4,arg5 Optional command arguments.
60 const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
61 const RooCmdArg& arg4={}, const RooCmdArg& arg5={}) {
63 }
65 const RooCmdArg& arg1={},const RooCmdArg& arg2={},
66 const RooCmdArg& arg3={},const RooCmdArg& arg4={},
67 const RooCmdArg& arg5={},const RooCmdArg& arg6={}) ;
68 RooFit::OwningPtr<RooDataSet> generate(const RooArgSet &whatVars, double nEvents = 0, bool verbose=false, bool autoBinned=true,
69 const char* binnedTag="", bool expectedData=false, bool extended = false) const;
71 bool verbose=false, bool randProtoOrder=false, bool resampleProto=false) const;
72
73
74 class GenSpec {
75 public:
76 virtual ~GenSpec() ;
77 GenSpec() = default;
78
79 private:
81 bool randProto, bool resampleProto, TString dsetName, bool init=false) ;
83
84 friend class RooAbsPdf ;
85 std::unique_ptr<RooAbsGenContext> _genContext;
89 bool _extended = false;
90 bool _randProto = false;
91 bool _resampleProto = false;
93 bool _init = false;
94
95 ClassDef(GenSpec,0) // Generation specification
96 } ;
97
98 ///Prepare GenSpec configuration object for efficient generation of multiple datasets from identical specification.
100 const RooCmdArg& arg1={},const RooCmdArg& arg2={},
101 const RooCmdArg& arg3={},const RooCmdArg& arg4={},
102 const RooCmdArg& arg5={},const RooCmdArg& arg6={}) ;
103 ///Generate according to GenSpec obtained from prepareMultiGen().
105
106
107 ////////////////////////////////////////////////////////////////////////////////
108 /// As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,const RooCmdArg&) const.
109 /// \param[in] whatVars set
110 /// \param[in] nEvents How many events to generate
111 /// \param arg1,arg2,arg3,arg4,arg5 ordered arguments
113 const RooCmdArg& arg2={}, const RooCmdArg& arg3={},
114 const RooCmdArg& arg4={}, const RooCmdArg& arg5={}) const {
116 }
118 const RooCmdArg& arg1={},const RooCmdArg& arg2={},
119 const RooCmdArg& arg3={},const RooCmdArg& arg4={},
120 const RooCmdArg& arg5={},const RooCmdArg& arg6={}) const;
121 virtual RooFit::OwningPtr<RooDataHist> generateBinned(const RooArgSet &whatVars, double nEvents, bool expectedData=false, bool extended=false) const;
122
124 R__DEPRECATED(6,38, "Use RooAbsPdf::generate() instead. The RooAbsPdf::generateSimGlobal() only contains some workarounds that are not necessary anymore");
125
126 ///Helper calling plotOn(RooPlot*, RooLinkedList&) const
127 RooPlot* plotOn(RooPlot* frame,
128 const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
129 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
130 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
131 const RooCmdArg& arg7={}, const RooCmdArg& arg8={},
132 const RooCmdArg& arg9={}, const RooCmdArg& arg10={}
133 ) const override {
135 }
136 RooPlot* plotOn(RooPlot* frame, RooLinkedList& cmdList) const override ;
137
138 /// Add a box with parameter values (and errors) to the specified frame
139 virtual RooPlot* paramOn(RooPlot* frame,
140 const RooCmdArg& arg1={}, const RooCmdArg& arg2={},
141 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
142 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
143 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
144
145 // Built-in generator support
146 virtual Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool staticInitOK=true) const;
147 virtual void initGenerator(Int_t code) ;
148 virtual void generateEvent(Int_t code);
149 virtual bool isDirectGenSafe(const RooAbsArg& arg) const ;
150
151 // Configuration of MC generators used for this pdf
152 const RooNumGenConfig* getGeneratorConfig() const ;
156 void setGeneratorConfig() ;
157 void setGeneratorConfig(const RooNumGenConfig& config) ;
158
159 template <typename... CmdArgs_t>
161 {
163 }
164
165 template <typename... CmdArgs_t>
167 {
169 }
170
171 // Constraint management
172 virtual RooArgSet* getConstraints(const RooArgSet& /*observables*/, RooArgSet const& /*constrainedParams*/, RooArgSet& /*pdfParams*/) const
173 {
174 // Interface to retrieve constraint terms on this pdf. Default implementation returns null
175 return nullptr ;
176 }
178 bool stripDisconnected=true) const ;
179
180 // Project p.d.f into lower dimensional p.d.f
181 virtual RooAbsPdf* createProjection(const RooArgSet& iset) ;
182
183 // Create cumulative density function from p.d.f
186 const RooCmdArg& arg3={}, const RooCmdArg& arg4={},
187 const RooCmdArg& arg5={}, const RooCmdArg& arg6={},
188 const RooCmdArg& arg7={}, const RooCmdArg& arg8={}) ;
190
191 // Function evaluation support
192 double getValV(const RooArgSet* set=nullptr) const override ;
193 virtual double getLogVal(const RooArgSet* set=nullptr) const ;
194
195 void getLogProbabilities(std::span<const double> pdfValues, double * output) const;
196
197 /// \copydoc getNorm(const RooArgSet*) const
198 double getNorm(const RooArgSet& nset) const {
199 return getNorm(&nset) ;
200 }
201 virtual double getNorm(const RooArgSet* set=nullptr) const ;
202
203 virtual void resetErrorCounters(Int_t resetValue=10) ;
204 void setTraceCounter(Int_t value, bool allNodes=false) ;
205
206 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
207
208 /// Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
209 /// Always returns false, unless a PDF overrides this function.
210 virtual bool selfNormalized() const {
211 return false ;
212 }
213
214 // Support for extended maximum likelihood, switched off by default
215 enum ExtendMode { CanNotBeExtended, CanBeExtended, MustBeExtended } ;
216 /// Returns ability of PDF to provide extended likelihood terms. Possible
217 /// answers are in the enumerator RooAbsPdf::ExtendMode.
218 /// This default implementation always returns CanNotBeExtended.
219 virtual ExtendMode extendMode() const { return CanNotBeExtended; }
220 /// If true, PDF can provide extended likelihood term.
221 inline bool canBeExtended() const {
222 return (extendMode() != CanNotBeExtended) ;
223 }
224 /// If true PDF must provide extended likelihood term.
225 inline bool mustBeExtended() const {
226 return (extendMode() == MustBeExtended) ;
227 }
228 /// Return expected number of events to be used in calculation of extended
229 /// likelihood.
230 virtual double expectedEvents(const RooArgSet* nset) const ;
231 /// Return expected number of events to be used in calculation of extended
232 /// likelihood. This function should not be overridden, as it just redirects
233 /// to the actual virtual function but takes a RooArgSet reference instead of
234 /// pointer. \see expectedEvents(const RooArgSet*) const
235 double expectedEvents(const RooArgSet& nset) const {
236 return expectedEvents(&nset) ;
237 }
238
239 virtual std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet* nset) const;
240
241 // Printing interface (human readable)
242 void printValue(std::ostream& os) const override ;
243 void printMultiline(std::ostream& os, Int_t contents, bool verbose=false, TString indent="") const override ;
244
245 static void verboseEval(Int_t stat) ;
246 static int verboseEval() ;
247
248 double extendedTerm(double sumEntries, double expected, double sumEntriesW2=0.0, bool doOffset=false) const;
249 double extendedTerm(double sumEntries, RooArgSet const* nset, double sumEntriesW2=0.0, bool doOffset=false) const;
250 double extendedTerm(RooAbsData const& data, bool weightSquared, bool doOffset=false) const;
251
252 void setNormRange(const char* rangeName) ;
253 const char* normRange() const {
254 return _normRange.Length()>0 ? _normRange.Data() : nullptr ;
255 }
256 void setNormRangeOverride(const char* rangeName) ;
257
258 const RooAbsReal* getNormIntegral(const RooArgSet& nset) const { return getNormObj(nullptr,&nset,nullptr) ; }
259
260 virtual const RooAbsReal* getNormObj(const RooArgSet* set, const RooArgSet* iset, const TNamed* rangeName=nullptr) const ;
261
262 virtual RooAbsGenContext* binnedGenContext(const RooArgSet &vars, bool verbose= false) const ;
263
264 virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr,
265 const RooArgSet* auxProto=nullptr, bool verbose= false) const ;
266
267 virtual RooAbsGenContext* autoGenContext(const RooArgSet &vars, const RooDataSet* prototype=nullptr, const RooArgSet* auxProto=nullptr,
268 bool verbose=false, bool autoBinned=true, const char* binnedTag="") const ;
269
270 std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
271
272private:
273
274 std::unique_ptr<RooDataSet> generate(RooAbsGenContext& context, const RooArgSet& whatVars, const RooDataSet* prototype,
275 double nEvents, bool verbose, bool randProtoOrder, bool resampleProto, bool skipInit=false,
276 bool extended=false) const ;
277
278 // Implementation version
279 virtual RooPlot* paramOn(RooPlot* frame, const RooArgSet& params, bool showConstants=false,
280 const char *label= "", double xmin=0.65,
281 double xmax= 0.99,double ymax=0.95, const RooCmdArg* formatCmd=nullptr) ;
282
283 void logBatchComputationErrors(std::span<const double>& outputs, std::size_t begin) const;
284 bool traceEvalPdf(double value) const;
285
286 /// Setter for the _normSet member, which should never be set directly.
287 inline void setActiveNormSet(RooArgSet const* normSet) const {
288 _normSet = normSet;
289 // Also store the unique ID of the _normSet. This makes it possible to
290 // detect if the pointer was invalidated.
292 }
293
294protected:
295
296 virtual std::unique_ptr<RooAbsReal> createNLLImpl(RooAbsData& data, const RooLinkedList& cmdList);
297 virtual std::unique_ptr<RooFitResult> fitToImpl(RooAbsData& data, const RooLinkedList& cmdList);
298
299 /// Checks if `normSet` is the currently active normalization set of this
300 /// PDF, meaning is exactly the same object as the one the `_normSet` member
301 /// points to (or both are `nullptr`).
302 inline bool isActiveNormSet(RooArgSet const* normSet) const {
303 return RooFit::getUniqueId(normSet).value() == _normSetId;
304 }
305
306 double normalizeWithNaNPacking(double rawVal, double normVal) const;
307
308 RooPlot *plotOn(RooPlot *frame, PlotOpt o) const override;
309
310 friend class RooMCStudy ;
311
313
314 // This also forces the definition of a copy ctor in derived classes
315 RooAbsPdf(const RooAbsPdf& other, const char* name = nullptr);
316
317 static Int_t _verboseEval ;
318
319 virtual bool syncNormalization(const RooArgSet* dset, bool adjustProxies=true) const ;
320
321 mutable double _rawValue = 0;
322 mutable RooAbsReal* _norm = nullptr; //! Normalization integral (owned by _normMgr)
323 mutable RooArgSet const* _normSet = nullptr; //! Normalization set with for above integral
324
325 class CacheElem : public RooAbsCacheElement {
326 public:
327 CacheElem(RooAbsReal& norm) : _norm(&norm) {} ;
328 ~CacheElem() override ;
329 RooArgList containedArgs(Action) override { return RooArgList(*_norm) ; }
330 std::unique_ptr<RooAbsReal> _norm;
331 } ;
332 mutable RooObjCacheManager _normMgr ; //! The cache manager
333
335 bool nameChange, bool isRecursiveStep) override;
336
337 mutable Int_t _errorCount = 0; ///< Number of errors remaining to print
338 mutable Int_t _traceCount = 0; ///< Number of traces remaining to print
339 mutable Int_t _negCount = 0; ///< Number of negative probabilities remaining to print
340
341 bool _selectComp = false; ///< Component selection flag for RooAbsPdf::plotCompOn
342
343 std::unique_ptr<RooNumGenConfig> _specGeneratorConfig ; ///<! MC generator configuration specific for this object
344
345 TString _normRange ; ///< Normalization range
347
348private:
349 mutable RooFit::UniqueId<RooArgSet>::Value_t _normSetId = RooFit::UniqueId<RooArgSet>::nullval; ///<! Unique ID of the currently-active normalization set
350
351 friend class RooAbsReal;
352 friend class RooChi2Var;
353
354 ClassDefOverride(RooAbsPdf,5) // Abstract PDF with normalization support
355};
356
357
358
359
360#endif
#define R__DEPRECATED(MAJOR, MINOR, REASON)
Definition RConfig.hxx:520
#define ClassDef(name, id)
Definition Rtypes.h:342
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
float xmin
float xmax
float ymax
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
virtual std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract base class for generator contexts of RooAbsPdf objects.
std::unique_ptr< RooAbsGenContext > _genContext
Definition RooAbsPdf.h:85
RooArgSet _whatVars
Definition RooAbsPdf.h:86
GenSpec(const GenSpec &other)
RooDataSet * _protoData
Definition RooAbsPdf.h:87
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:42
~RooAbsPdf() override
Destructor.
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={})
Prepare GenSpec configuration object for efficient generation of multiple datasets from identical spe...
RooFit::OwningPtr< RooDataSet > generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={})
See RooAbsPdf::generate(const RooArgSet&,const RooCmdArg&,const RooCmdArg&,const RooCmdArg&,...
Definition RooAbsPdf.h:59
RooAbsPdf()
Default constructor.
virtual RooFit::OwningPtr< RooDataHist > generateBinned(const RooArgSet &whatVars, double nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}) const
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition RooAbsPdf.h:112
virtual RooFit::OwningPtr< RooDataSet > generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents) R__DEPRECATED(6
Special generator interface for generation of 'global observables' – for RooStats tools.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
bool _selectComp
A buffer for reading values from trees.
Definition RooAbsReal.h:541
virtual double getValV(const RooArgSet *normalisationSet=nullptr) const
Return value of object.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Function that is called at the end of redirectServers().
void printValue(std::ostream &os) const override
Print object value.
virtual double maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
virtual double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1={}, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}, const RooCmdArg &arg9={}, const RooCmdArg &arg10={}) const
Plot (project) PDF on specified frame.
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
Object to represent discrete states.
Definition RooCategory.h:28
Simple calculation from a binned dataset and a PDF.
Definition RooChi2Var.h:19
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Container class to hold unbinned data.
Definition RooDataSet.h:34
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
Helper class to facilitate Monte Carlo studies such as 'goodness-of-fit' studies, that involve fittin...
Definition RooMCStudy.h:32
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:645
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:303
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
Basic string class.
Definition TString.h:139
RooCmdArg NumEvents(Int_t numEvents)
std::unique_ptr< RooLinkedList > createCmdList()
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35
UniqueId_t const & getUniqueId(Class const *ptr)
A helper function to replace pointer comparisons with UniqueId comparisons.
Definition UniqueId.h:89
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
Definition Config.h:40
A UniqueId can be added as a class member to enhance any class with a unique identifier for each inst...
Definition UniqueId.h:39
unsigned long Value_t
Definition UniqueId.h:41
static void output()