Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAddPdf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooAddPdf.h,v 1.46 2007/07/12 20:30:28 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_ADD_PDF
17#define ROO_ADD_PDF
18
19#include "RooAbsPdf.h"
20#include "RooListProxy.h"
21#include "RooSetProxy.h"
22#include "RooAICRegistry.h"
23#include "RooObjCacheManager.h"
24#include "RooNameReg.h"
25
26#include <vector>
27#include <list>
28#include <utility>
29
30class AddCacheElem;
31
32class RooAddPdf : public RooAbsPdf {
33public:
34
35 RooAddPdf() : _projCacheMgr(this,10) {}
36 RooAddPdf(const char *name, const char *title=nullptr);
37 RooAddPdf(const char *name, const char *title,
38 RooAbsPdf& pdf1, RooAbsPdf& pdf2, RooAbsReal& coef1) ;
39 RooAddPdf(const char *name, const char *title, const RooArgList& pdfList) ;
40 RooAddPdf(const char *name, const char *title, const RooArgList& pdfList, const RooArgList& coefList, bool recursiveFraction=false) ;
41
42 RooAddPdf(const RooAddPdf& other, const char* name=nullptr) ;
43 TObject* clone(const char* newname=nullptr) const override { return new RooAddPdf(*this,newname) ; }
44 ~RooAddPdf() override {}
45
46 bool checkObservables(const RooArgSet* nset) const override;
47
48 /// Force RooRealIntegral to offer all observables for internal integration.
49 bool forceAnalyticalInt(const RooAbsArg& /*dep*/) const override {
50 return true ;
51 }
52 Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet,
53 const char *rangeName = nullptr) const override;
54 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override;
55 bool selfNormalized() const override {
56 // P.d.f is self normalized
57 return true ;
58 }
59
60 ExtendMode extendMode() const override {
61 // Return extended mode capabilities
63 }
64 /// Return expected number of events for extended likelihood calculation, which
65 /// is the sum of all coefficients.
66 double expectedEvents(const RooArgSet* nset) const override;
67
68 std::unique_ptr<RooAbsReal> createExpectedEventsFunc(const RooArgSet* nset) const override;
69
70 const RooArgList& pdfList() const {
71 // Return list of component p.d.fs
72 return _pdfList ;
73 }
74 const RooArgList& coefList() const {
75 // Return list of coefficients of component p.d.f.s
76 return _coefList ;
77 }
78
79 void fixCoefNormalization(const RooArgSet& refCoefNorm) ;
80 void fixCoefRange(const char* rangeName) ;
81
82 const RooArgSet& getCoefNormalization() const;
84
85 void resetErrorCounters(Int_t resetValue=10) override;
86
87 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
88 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override;
89 bool isBinnedDistribution(const RooArgSet& obs) const override;
90
91 void printMetaArgs(std::ostream& os) const override;
92
93
94 std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
95
96 protected:
97 void selectNormalization(const RooArgSet* depSet=nullptr, bool force=false) override;
98 void selectNormalizationRange(const char* rangeName=nullptr, bool force=false) override;
99
100 mutable RooSetProxy _refCoefNorm ; ///< Reference observable set for coefficient interpretation
101 mutable TNamed* _refCoefRangeName = nullptr ; ///< Reference range name for coefficient interpretation
102
103 mutable std::vector<double> _coefCache; ///<! Transient cache with transformed values of coefficients
104
105
106 mutable RooObjCacheManager _projCacheMgr ; ///<! Manager of cache with coefficient projections and transformations
107 AddCacheElem* getProjCache(const RooArgSet* nset, const RooArgSet* iset=nullptr) const ;
108 void updateCoefficients(AddCacheElem& cache, const RooArgSet* nset, bool syncCoefValues=true) const ;
109
110
111 friend class RooAddGenContext ;
112 friend class RooAddModel ;
113 RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr,
114 const RooArgSet* auxProto=nullptr, bool verbose= false) const override;
115
116
117 double evaluate() const override {
118 return getValV(nullptr);
119 }
120 double getValV(const RooArgSet* set=nullptr) const override ;
121 void doEval(RooFit::EvalContext &) const override;
122 inline bool canComputeBatchWithCuda() const override { return true; }
123
124
125 mutable RooAICRegistry _codeReg; ///<! Registry of component analytical integration codes
126
127 RooListProxy _pdfList ; ///< List of component PDFs
128 RooListProxy _coefList ; ///< List of coefficients
129 RooArgList *_snormList{nullptr}; ///<! List of supplemental normalization factors
130
131 bool _haveLastCoef = false; ///< Flag indicating if last PDFs coefficient was supplied in the constructor
132 bool _allExtendable = false; ///< Flag indicating if all PDF components are extendable
133 bool _recursive = false; ///< Flag indicating is fractions are treated recursively
134
135 mutable Int_t _coefErrCount = 0; ///<! Coefficient error counter
136
137 bool redirectServersHook(const RooAbsCollection&, bool, bool, bool) override;
138
139private:
140 std::pair<const RooArgSet*, AddCacheElem*> getNormAndCache(const RooArgSet* nset) const;
142 mutable std::unique_ptr<const RooArgSet> _copyOfLastNormSet = nullptr; ///<!
143
146
147 ClassDefOverride(RooAddPdf,5) // PDF representing a sum of PDFs
148};
149
150#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
char name[80]
Definition TGX11.cxx:142
Registry for analytical integration codes.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
Abstract container object that can hold multiple RooAbsArg objects.
Abstract base class for generator contexts of RooAbsPdf objects.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
@ MustBeExtended
Definition RooAbsPdf.h:208
@ CanNotBeExtended
Definition RooAbsPdf.h:208
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
friend class AddCacheElem
Definition RooAbsReal.h:407
Efficient implementation of the generator context specific for RooAddPdf PDFs.
RooAddModel is an efficient implementation of a sum of PDFs of the form.
Definition RooAddModel.h:26
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:32
RooListProxy _coefList
List of coefficients.
Definition RooAddPdf.h:128
RooArgList * _snormList
! List of supplemental normalization factors
Definition RooAddPdf.h:129
bool _allExtendable
Flag indicating if all PDF components are extendable.
Definition RooAddPdf.h:132
void doEval(RooFit::EvalContext &) const override
Compute addition of PDFs in batches.
RooAICRegistry _codeReg
! Registry of component analytical integration codes
Definition RooAddPdf.h:125
RooFit::UniqueId< RooArgSet >::Value_t _idOfLastUsedNormSet
!
Definition RooAddPdf.h:141
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
const char * getCoefRange() const
Definition RooAddPdf.h:83
std::unique_ptr< const RooArgSet > _copyOfLastNormSet
!
Definition RooAddPdf.h:142
void updateCoefficients(AddCacheElem &cache, const RooArgSet *nset, bool syncCoefValues=true) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
Int_t _coefErrCount
! Coefficient error counter
Definition RooAddPdf.h:135
bool canComputeBatchWithCuda() const override
Definition RooAddPdf.h:122
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the constructor.
Definition RooAddPdf.h:131
void selectNormalization(const RooArgSet *depSet=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of observables for interpretation of frac...
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooAddPdf to more intuitively reflect the contents of the produ...
void finalizeConstruction()
const RooArgList & coefList() const
Definition RooAddPdf.h:74
bool _recursive
Flag indicating is fractions are treated recursively.
Definition RooAddPdf.h:133
RooObjCacheManager _projCacheMgr
! Manager of cache with coefficient projections and transformations
Definition RooAddPdf.h:106
void materializeRefCoefNormFromAttribute() const
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Return specialized context to efficiently generate toy events from RooAddPdfs return RooAbsPdf::genCo...
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
Definition RooAddPdf.h:55
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
std::pair< const RooArgSet *, AddCacheElem * > getNormAndCache(const RooArgSet *nset) const
Look up projection cache and per-PDF norm sets.
RooSetProxy _refCoefNorm
Reference observable set for coefficient interpretation.
Definition RooAddPdf.h:100
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of fraction c...
void resetErrorCounters(Int_t resetValue=10) override
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
Definition RooAddPdf.h:60
bool forceAnalyticalInt(const RooAbsArg &) const override
Force RooRealIntegral to offer all observables for internal integration.
Definition RooAddPdf.h:49
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
double getValV(const RooArgSet *set=nullptr) const override
Calculate and return the current value.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooAddPdf.h:117
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
void fixCoefRange(const char *rangeName)
By default, fraction coefficients are assumed to refer to the default fit range.
AddCacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=nullptr) const
Retrieve cache element for the computation of the PDF normalisation.
TObject * clone(const char *newname=nullptr) const override
Definition RooAddPdf.h:43
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Loop over components for plot sampling hints and merge them if there are multiple.
RooListProxy _pdfList
List of component PDFs.
Definition RooAddPdf.h:127
TNamed * _refCoefRangeName
Reference range name for coefficient interpretation.
Definition RooAddPdf.h:101
const RooArgList & pdfList() const
Definition RooAddPdf.h:70
std::unique_ptr< RooAbsReal > createExpectedEventsFunc(const RooArgSet *nset) const override
Returns an object that represents the expected number of events for a given normalization set,...
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned, so is their sum.
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Hook function intercepting redirectServer calls.
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Determine which part (if any) of given integral can be performed analytically.
~RooAddPdf() override
Definition RooAddPdf.h:44
std::vector< double > _coefCache
! Transient cache with transformed values of coefficients
Definition RooAddPdf.h:103
const RooArgSet & getCoefNormalization() const
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Loop over components for plot sampling hints and merge them if there are multiple.
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 unbinned data.
Definition RooDataSet.h:32
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition RooNameReg.h:39
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:42
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