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 AddCacheElem;
33
34class RooAddPdf : public RooAbsPdf {
35public:
36
38 RooAddPdf(const char *name, const char *title=nullptr);
39 RooAddPdf(const char *name, const char *title,
40 RooAbsPdf& pdf1, RooAbsPdf& pdf2, RooAbsReal& coef1) ;
41 RooAddPdf(const char *name, const char *title, const RooArgList& pdfList) ;
42 RooAddPdf(const char *name, const char *title, const RooArgList& pdfList, const RooArgList& coefList, bool recursiveFraction=false) ;
43
44 RooAddPdf(const RooAddPdf& other, const char* name=nullptr) ;
45 TObject* clone(const char* newname) const override { return new RooAddPdf(*this,newname) ; }
47
48 bool checkObservables(const RooArgSet* nset) const override;
49
50 /// Force RooRealIntegral to offer all observables for internal integration.
51 bool forceAnalyticalInt(const RooAbsArg& /*dep*/) const override {
52 return true ;
53 }
54 Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=nullptr) const override;
55 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override;
56 bool selfNormalized() const override {
57 // P.d.f is self normalized
58 return true ;
59 }
60
61 ExtendMode extendMode() const override {
62 // Return extended mode capabilities
64 }
65 /// Return expected number of events for extended likelihood calculation, which
66 /// is the sum of all coefficients.
67 double expectedEvents(const RooArgSet* nset) const override;
68
69 const RooArgList& pdfList() const {
70 // Return list of component p.d.fs
71 return _pdfList ;
72 }
73 const RooArgList& coefList() const {
74 // Return list of coefficients of component p.d.f.s
75 return _coefList ;
76 }
77
78 void fixCoefNormalization(const RooArgSet& refCoefNorm) ;
79 void fixCoefRange(const char* rangeName) ;
80
81 const RooArgSet& getCoefNormalization() const { return _refCoefNorm ; }
83
84 void resetErrorCounters(Int_t resetValue=10) override;
85
86 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override;
87 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override;
88 bool isBinnedDistribution(const RooArgSet& obs) const override;
89
90 void printMetaArgs(std::ostream& os) const override;
91
92 CacheMode canNodeBeCached() const override { return RooAbsArg::NotAdvised ; };
93 void setCacheAndTrackHints(RooArgSet&) override;
94
95protected:
96
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 interpreation
102
103 bool _projectCoefs = false; ///< If true coefficients need to be projected for use in evaluate()
104 mutable std::vector<double> _coefCache; ///<! Transient cache with transformed values of coefficients
105
106
107 mutable RooObjCacheManager _projCacheMgr ; //! Manager of cache with coefficient projections and transformations
108 AddCacheElem* getProjCache(const RooArgSet* nset, const RooArgSet* iset=nullptr) const ;
109 void updateCoefficients(AddCacheElem& cache, const RooArgSet* nset, bool syncCoefValues=true) const ;
110
111
112 friend class RooAddGenContext ;
113 friend class RooAddModel ;
114 RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr,
115 const RooArgSet* auxProto=nullptr, bool verbose= false) const override;
116
117
118 double evaluate() const override {
119 return getValV(nullptr);
120 }
121 double getValV(const RooArgSet* set=nullptr) const override ;
122 void computeBatch(cudaStream_t*, double* output, size_t nEvents, RooFit::Detail::DataMap const&) const override;
123 inline bool canComputeBatchWithCuda() const override { return true; }
124
125
126 mutable RooAICRegistry _codeReg; ///<! Registry of component analytical integration codes
127
128 RooListProxy _pdfList ; ///< List of component PDFs
129 RooListProxy _coefList ; ///< List of coefficients
130 mutable RooArgList* _snormList{nullptr}; ///<! List of supplemental normalization factors
131
132 bool _haveLastCoef = false; ///< Flag indicating if last PDFs coefficient was supplied in the ctor
133 bool _allExtendable = false; ///< Flag indicating if all PDF components are extendable
134 bool _recursive = false; ///< Flag indicating is fractions are treated recursively
135
136 mutable Int_t _coefErrCount ; ///<! Coefficient error counter
137
138 bool redirectServersHook(const RooAbsCollection&, bool, bool, bool) override;
139
140private:
141 std::pair<const RooArgSet*, AddCacheElem*> getNormAndCache(const RooArgSet* nset) const;
143 mutable std::unique_ptr<const RooArgSet> _copyOfLastNormSet = nullptr; ///<!
144
146
147 ClassDefOverride(RooAddPdf,4) // PDF representing a sum of PDFs
148};
149
150#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:71
@ NotAdvised
Definition: RooAbsArg.h:389
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:258
@ CanNotBeExtended
Definition: RooAbsPdf.h:258
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:62
RooAddGenContext is an 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:28
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:34
RooListProxy _coefList
List of coefficients.
Definition: RooAddPdf.h:129
RooArgList * _snormList
! List of supplemental normalization factors
Definition: RooAddPdf.h:130
bool _allExtendable
Flag indicating if all PDF components are extendable.
Definition: RooAddPdf.h:133
RooAICRegistry _codeReg
! Registry of component analytical integration codes
Definition: RooAddPdf.h:126
RooFit::UniqueId< RooArgSet >::Value_t _idOfLastUsedNormSet
!
Definition: RooAddPdf.h:142
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
Definition: RooAddPdf.cxx:639
const char * getCoefRange() const
Definition: RooAddPdf.h:82
std::unique_ptr< const RooArgSet > _copyOfLastNormSet
!
Definition: RooAddPdf.h:143
TObject * clone(const char *newname) const override
Definition: RooAddPdf.h:45
void updateCoefficients(AddCacheElem &cache, const RooArgSet *nset, bool syncCoefValues=true) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
Definition: RooAddPdf.cxx:393
Int_t _coefErrCount
! Coefficient error counter
Definition: RooAddPdf.h:136
bool canComputeBatchWithCuda() const override
Definition: RooAddPdf.h:123
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the ctor.
Definition: RooAddPdf.h:132
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...
Definition: RooAddPdf.cxx:736
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:820
void finalizeConstruction()
Definition: RooAddPdf.cxx:102
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooAddPdf with cache-and-track.
Definition: RooAddPdf.cxx:809
const RooArgList & coefList() const
Definition: RooAddPdf.h:73
bool _recursive
Flag indicating is fractions are treated recursively.
Definition: RooAddPdf.h:134
RooObjCacheManager _projCacheMgr
Definition: RooAddPdf.h:107
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...
Definition: RooAddPdf.cxx:772
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
Definition: RooAddPdf.cxx:558
RooAddPdf()
Definition: RooAddPdf.h:37
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:56
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
Definition: RooAddPdf.cxx:309
std::pair< const RooArgSet *, AddCacheElem * > getNormAndCache(const RooArgSet *nset) const
Look up projection cache and per-PDF norm sets.
Definition: RooAddPdf.cxx:409
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...
Definition: RooAddPdf.cxx:757
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Determine which part (if any) of given integral can be performed analytically.
Definition: RooAddPdf.cxx:574
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:545
ExtendMode extendMode() const override
Returns ability of PDF to provide extended likelihood terms.
Definition: RooAddPdf.h:61
bool forceAnalyticalInt(const RooAbsArg &) const override
Force RooRealIntegral to offer all observables for internal integration.
Definition: RooAddPdf.h:51
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:697
double getValV(const RooArgSet *set=nullptr) const override
Calculate and return the current value.
Definition: RooAddPdf.cxx:463
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooAddPdf.h:118
void fixCoefRange(const char *rangeName)
By default, fraction coefficients are assumed to refer to the default fit range.
Definition: RooAddPdf.cxx:336
CacheMode canNodeBeCached() const override
Definition: RooAddPdf.h:92
AddCacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=nullptr) const
Manager of cache with coefficient projections and transformations.
Definition: RooAddPdf.cxx:359
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:783
RooListProxy _pdfList
List of component PDFs.
Definition: RooAddPdf.h:128
TNamed * _refCoefRangeName
Reference range name for coefficient interpreation.
Definition: RooAddPdf.h:101
const RooArgList & pdfList() const
Definition: RooAddPdf.h:69
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Compute addition of PDFs in batches.
Definition: RooAddPdf.cxx:499
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned, so is their sum.
Definition: RooAddPdf.cxx:800
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
The cache manager.
Definition: RooAddPdf.cxx:826
~RooAddPdf() override
Definition: RooAddPdf.h:46
bool _projectCoefs
If true coefficients need to be projected for use in evaluate()
Definition: RooAddPdf.h:103
std::vector< double > _coefCache
! Transient cache with transformed values of coefficients
Definition: RooAddPdf.h:104
const RooArgSet & getCoefNormalization() const
Definition: RooAddPdf.h:81
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:792
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:56
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:41
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()