Logo ROOT  
Reference Guide
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 "RooNormSetCache.h"
24#include "RooObjCacheManager.h"
25#include "RooNameReg.h"
26#include "RooTrace.h"
27
28#include <vector>
29#include <list>
30#include <utility>
31
32class RooAddPdf : public RooAbsPdf {
33public:
34
36 RooAddPdf(const char *name, const char *title=0);
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=0) ;
43 TObject* clone(const char* newname) const override { return new RooAddPdf(*this,newname) ; }
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& numVars, const RooArgSet* normSet, const char* rangeName=0) const override;
53 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const override;
54 bool selfNormalized() const override {
55 // P.d.f is self normalized
56 return true ;
57 }
58
59 ExtendMode extendMode() const override {
60 // Return extended mode capabilities
62 }
63 /// Return expected number of events for extended likelihood calculation, which
64 /// is the sum of all coefficients.
65 double expectedEvents(const RooArgSet* nset) const override;
66
67 const RooArgList& pdfList() const {
68 // Return list of component p.d.fs
69 return _pdfList ;
70 }
71 const RooArgList& coefList() const {
72 // Return list of coefficients of component p.d.f.s
73 return _coefList ;
74 }
75
76 void fixCoefNormalization(const RooArgSet& refCoefNorm) ;
77 void fixCoefRange(const char* rangeName) ;
78
79 const RooArgSet& getCoefNormalization() const { return _refCoefNorm ; }
81
82 void resetErrorCounters(Int_t resetValue=10) override;
83
84 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
85 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override;
86 bool isBinnedDistribution(const RooArgSet& obs) const override;
87
88 void printMetaArgs(std::ostream& os) const override;
89
90 CacheMode canNodeBeCached() const override { return RooAbsArg::NotAdvised ; };
91 void setCacheAndTrackHints(RooArgSet&) override;
92
93protected:
94
95 void selectNormalization(const RooArgSet* depSet=0, bool force=false) override;
96 void selectNormalizationRange(const char* rangeName=0, bool force=false) override;
97
98 mutable RooSetProxy _refCoefNorm ; ///< Reference observable set for coefficient interpretation
99 mutable TNamed* _refCoefRangeName = nullptr ; ///< Reference range name for coefficient interpreation
100
101 bool _projectCoefs = false; ///< If true coefficients need to be projected for use in evaluate()
102 std::vector<double> _coefCache; ///<! Transient cache with transformed values of coefficients
103
104
106 public:
107 ~CacheElem() override {} ;
108
109 RooArgList _suppNormList ; ///< Supplemental normalization list
110 bool _needSupNorm ; ///< Does the above list contain any non-unit entries?
111
112 RooArgList _projList ; ///< Projection integrals to be multiplied with coefficients
113 RooArgList _suppProjList ; ///< Projection integrals to be multiplied with coefficients for supplemental normalization terms
114 RooArgList _refRangeProjList ; ///< Range integrals to be multiplied with coefficients (reference range)
115 RooArgList _rangeProjList ; ///< Range integrals to be multiplied with coefficients (target range)
116
118
119 } ;
120 mutable RooObjCacheManager _projCacheMgr ; //! Manager of cache with coefficient projections and transformations
121 CacheElem* getProjCache(const RooArgSet* nset, const RooArgSet* iset=0, const char* rangeName=0) const ;
122 void updateCoefficients(CacheElem& cache, const RooArgSet* nset) const ;
123
124
125 friend class RooAddGenContext ;
126 RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0,
127 const RooArgSet* auxProto=0, bool verbose= false) const override;
128
129
130 double evaluate() const override {
131 return getValV(nullptr);
132 }
133 double getValV(const RooArgSet* set=nullptr) const override ;
134 void computeBatch(cudaStream_t*, double* output, size_t nEvents, RooFit::Detail::DataMap const&) const override;
135 inline bool canComputeBatchWithCuda() const override { return true; }
136
137
138 mutable RooAICRegistry _codeReg; ///<! Registry of component analytical integration codes
139
140 RooListProxy _pdfList ; ///< List of component PDFs
141 RooListProxy _coefList ; ///< List of coefficients
142 mutable RooArgList* _snormList{nullptr}; ///<! List of supplemental normalization factors
143
144 bool _haveLastCoef = false; ///< Flag indicating if last PDFs coefficient was supplied in the ctor
145 bool _allExtendable = false; ///< Flag indicating if all PDF components are extendable
146 bool _recursive = false; ///< Flag indicating is fractions are treated recursively
147
148 mutable Int_t _coefErrCount ; ///<! Coefficient error counter
149
150 bool redirectServersHook(const RooAbsCollection&, bool, bool, bool) override {
151 // If a server is redirected, the cached normalization set might not point
152 // to the right observables anymore. We need to reset it.
153 _copyOfLastNormSet.reset();
154 return false;
155 }
156
157private:
158 std::pair<const RooArgSet*, CacheElem*> getNormAndCache(const RooArgSet* nset) const;
160 mutable std::unique_ptr<const RooArgSet> _copyOfLastNormSet = nullptr; ///<!
161
163
164 ClassDefOverride(RooAddPdf,4) // PDF representing a sum of PDFs
165};
166
167#endif
#define TRACE_DESTROY
Definition: RooTrace.h:24
#define TRACE_CREATE
Definition: RooTrace.h:23
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
char name[80]
Definition: TGX11.cxx:110
RooAICRegistry is a utility class for operator p.d.f classes that keeps track of analytical integrati...
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
@ NotAdvised
Definition: RooAbsArg.h:407
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
@ MustBeExtended
Definition: RooAbsPdf.h:257
@ CanNotBeExtended
Definition: RooAbsPdf.h:257
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
RooAddGenContext is an efficient implementation of the generator context specific for RooAddPdf PDFs.
RooArgList _rangeProjList
Range integrals to be multiplied with coefficients (target range)
Definition: RooAddPdf.h:115
RooArgList _refRangeProjList
Range integrals to be multiplied with coefficients (reference range)
Definition: RooAddPdf.h:114
~CacheElem() override
Definition: RooAddPdf.h:107
RooArgList _projList
Projection integrals to be multiplied with coefficients.
Definition: RooAddPdf.h:112
RooArgList _suppNormList
Supplemental normalization list.
Definition: RooAddPdf.h:109
RooArgList _suppProjList
Projection integrals to be multiplied with coefficients for supplemental normalization terms.
Definition: RooAddPdf.h:113
bool _needSupNorm
Does the above list contain any non-unit entries?
Definition: RooAddPdf.h:110
RooArgList containedArgs(Action) override
List all RooAbsArg derived contents in this cache element.
Definition: RooAddPdf.cxx:1064
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:32
RooListProxy _coefList
List of coefficients.
Definition: RooAddPdf.h:141
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, bool verbose=false) const override
Return specialized context to efficiently generate toy events from RooAddPdfs return RooAbsPdf::genCo...
Definition: RooAddPdf.cxx:1053
RooArgList * _snormList
! List of supplemental normalization factors
Definition: RooAddPdf.h:142
bool _allExtendable
Flag indicating if all PDF components are extendable.
Definition: RooAddPdf.h:145
RooAICRegistry _codeReg
! Registry of component analytical integration codes
Definition: RooAddPdf.h:138
RooFit::UniqueId< RooArgSet >::Value_t _idOfLastUsedNormSet
!
Definition: RooAddPdf.h:159
const char * getCoefRange() const
Definition: RooAddPdf.h:80
std::pair< const RooArgSet *, CacheElem * > getNormAndCache(const RooArgSet *nset) const
Look up projection cache and per-PDF norm sets.
Definition: RooAddPdf.cxx:704
std::unique_ptr< const RooArgSet > _copyOfLastNormSet
!
Definition: RooAddPdf.h:160
TObject * clone(const char *newname) const override
Definition: RooAddPdf.h:43
Int_t _coefErrCount
! Coefficient error counter
Definition: RooAddPdf.h:148
bool canComputeBatchWithCuda() const override
Definition: RooAddPdf.h:135
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the ctor.
Definition: RooAddPdf.h:144
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=0) const override
Determine which part (if any) of given integral can be performed analytically.
Definition: RooAddPdf.cxx:854
void updateCoefficients(CacheElem &cache, const RooArgSet *nset) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
Definition: RooAddPdf.cxx:580
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooAddPdf to more intuitively reflect the contents of the produ...
Definition: RooAddPdf.cxx:1199
CacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=0, const char *rangeName=0) const
Manager of cache with coefficient projections and transformations.
Definition: RooAddPdf.cxx:366
void selectNormalization(const RooArgSet *depSet=0, bool force=false) override
Interface function used by test statistics to freeze choice of observables for interpretation of frac...
Definition: RooAddPdf.cxx:1017
void finalizeConstruction()
Definition: RooAddPdf.cxx:104
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooAddPdf with cache-and-track.
Definition: RooAddPdf.cxx:1181
const RooArgList & coefList() const
Definition: RooAddPdf.h:71
bool _recursive
Flag indicating is fractions are treated recursively.
Definition: RooAddPdf.h:146
RooObjCacheManager _projCacheMgr
Definition: RooAddPdf.h:120
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
Definition: RooAddPdf.cxx:824
RooAddPdf()
Definition: RooAddPdf.h:35
void selectNormalizationRange(const char *rangeName=0, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of fraction c...
Definition: RooAddPdf.cxx:1038
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:54
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
Definition: RooAddPdf.cxx:320
RooSetProxy _refCoefNorm
Reference observable set for coefficient interpretation.
Definition: RooAddPdf.h:98
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...
Definition: RooAddPdf.cxx:811
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
Definition: RooAddPdf.h:59
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...
Definition: RooAddPdf.cxx:976
double getValV(const RooArgSet *set=nullptr) const override
Calculate and return the current value.
Definition: RooAddPdf.cxx:759
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooAddPdf.h:130
void fixCoefRange(const char *rangeName)
By default, fraction coefficients are assumed to refer to the default fit range.
Definition: RooAddPdf.cxx:347
CacheMode canNodeBeCached() const override
Definition: RooAddPdf.h:90
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.
Definition: RooAddPdf.cxx:1080
RooListProxy _pdfList
List of component PDFs.
Definition: RooAddPdf.h:140
TNamed * _refCoefRangeName
Reference range name for coefficient interpreation.
Definition: RooAddPdf.h:99
const RooArgList & pdfList() const
Definition: RooAddPdf.h:67
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Compute addition of PDFs in batches.
Definition: RooAddPdf.cxx:787
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned, so is their sum.
Definition: RooAddPdf.cxx:1165
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Function that is called at the end of redirectServers().
Definition: RooAddPdf.h:150
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const override
Return analytical integral defined by given scenario code.
Definition: RooAddPdf.cxx:919
~RooAddPdf() override
Definition: RooAddPdf.h:44
bool _projectCoefs
If true coefficients need to be projected for use in evaluate()
Definition: RooAddPdf.h:101
std::vector< double > _coefCache
! Transient cache with transformed values of coefficients
Definition: RooAddPdf.h:102
const RooArgSet & getCoefNormalization() const
Definition: RooAddPdf.h:79
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Loop over components for plot sampling hints and merge them if there are multiple.
Definition: RooAddPdf.cxx:1123
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:57
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition: RooNameReg.h:37
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
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()