Logo ROOT  
Reference Guide
RooProdPdf.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooProdPdf.h,v 1.44 2007/07/16 21:04: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_PROD_PDF
17#define ROO_PROD_PDF
18
19#include "RooAbsPdf.h"
20#include "RooListProxy.h"
21#include "RooLinkedList.h"
22#include "RooAICRegistry.h"
23#include "RooObjCacheManager.h"
24#include "RooCmdArg.h"
25
26#include <vector>
27#include <list>
28#include <string>
29
32
33class RooProdPdf : public RooAbsPdf {
34public:
35
36 RooProdPdf() ;
37 RooProdPdf(const char *name, const char *title,
38 RooAbsPdf& pdf1, RooAbsPdf& pdf2, double cutOff=0.0) ;
39 RooProdPdf(const char* name, const char* title, const RooArgList& pdfList, double cutOff=0.0) ;
40 RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet, const RooLinkedList& cmdArgList) ;
41
42 RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet,
43 const RooCmdArg& arg1 , const RooCmdArg& arg2=RooCmdArg(),
44 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
45 const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
46 const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) ;
47
48 RooProdPdf(const char* name, const char* title,
49 const RooCmdArg& arg1, const RooCmdArg& arg2=RooCmdArg(),
50 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
51 const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
52 const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) ;
53
54 RooProdPdf(const RooProdPdf& other, const char* name=nullptr) ;
55 TObject* clone(const char* newname) const override { return new RooProdPdf(*this,newname) ; }
56 ~RooProdPdf() override ;
57
58 bool forceAnalyticalInt(const RooAbsArg& dep) const override ;
59 Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
60 double analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=nullptr) const override ;
61 bool selfNormalized() const override { return _selfNorm ; }
62
63 ExtendMode extendMode() const override ;
64 double expectedEvents(const RooArgSet* nset) const override ;
65
66 const RooArgList& pdfList() const { return _pdfList ; }
67
68 void addPdfs(RooAbsCollection const& pdfs);
69 void removePdfs(RooAbsCollection const& pdfs);
70
71 Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool staticInitOK=true) const override;
72 void initGenerator(Int_t code) override ;
73 void generateEvent(Int_t code) override;
74 bool isDirectGenSafe(const RooAbsArg& arg) const override ;
75
76 // Constraint management
77 RooArgSet* getConstraints(const RooArgSet& observables, RooArgSet& constrainedParams,
78 bool stripDisconnected, bool removeConstraintsFromPdf=false) const override ;
79
80 std::list<double>* plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const override ;
81 std::list<double>* binBoundaries(RooAbsRealLValue& /*obs*/, double /*xlo*/, double /*xhi*/) const override ;
82 bool isBinnedDistribution(const RooArgSet& obs) const override ;
83
84 void printMetaArgs(std::ostream& os) const override ;
85
86 void selectNormalizationRange(const char* rangeName=nullptr, bool force=false) override ;
87 void fixRefRange(const char* rangeName) ;
88
89 void setSelfNormalized(bool flag) { _selfNorm = flag ; }
91
92
93 bool redirectServersHook(const RooAbsCollection& /*newServerList*/, bool /*mustReplaceAll*/, bool /*nameChange*/, bool /*isRecursive*/) override ;
94
95 RooArgSet* getConnectedParameters(const RooArgSet& observables) const ;
96
97 RooArgSet* findPdfNSet(RooAbsPdf const& pdf) const ;
98
99 void writeCacheToStream(std::ostream& os, RooArgSet const* nset) const;
100
101 std::unique_ptr<RooAbsArg> compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext & ctx) const override;
102
103private:
104
105 std::unique_ptr<RooArgSet> fillNormSetForServer(RooArgSet const& normSet, RooAbsArg const& server) const;
106
107 double evaluate() const override ;
108
109 std::unique_ptr<RooAbsReal> makeCondPdfRatioCorr(RooAbsReal& term, const RooArgSet& termNset, const RooArgSet& termImpSet, const char* normRange, const char* refRange) const ;
110
111 void getParametersHook(const RooArgSet* /*nset*/, RooArgSet* /*list*/, bool stripDisconnected) const override ;
112
113 void initializeFromCmdArgList(const RooArgSet& fullPdfSet, const RooLinkedList& l) ;
114
115 void factorizeProduct(const RooArgSet& normSet, const RooArgSet& intSet,
116 RooLinkedList& termList, RooLinkedList& normList,
117 RooLinkedList& impDepList, RooLinkedList& crossDepList,
118 RooLinkedList& intList) const;
119 std::string makeRGPPName(const char* pfx, const RooArgSet& term, const RooArgSet& iset, const RooArgSet& nset, const char* isetRangeName) const ;
120 void groupProductTerms(std::list<std::vector<RooArgSet*>>& groupedTerms, RooArgSet& outerIntDeps,
121 const RooLinkedList& terms, const RooLinkedList& norms,
122 const RooLinkedList& imps, const RooLinkedList& ints, const RooLinkedList& cross) const ;
123
124
125
126 Int_t getPartIntList(const RooArgSet* nset, const RooArgSet* iset, const char* isetRangeName=nullptr) const ;
127
128 std::vector<RooAbsReal*> processProductTerm(const RooArgSet* nset, const RooArgSet* iset, const char* isetRangeName,
129 const RooArgSet* term,const RooArgSet& termNSet, const RooArgSet& termISet,
130 bool& isOwned, bool forceWrap=false) const ;
131
132
133 CacheMode canNodeBeCached() const override { return RooAbsArg::NotAdvised ; } ;
134 void setCacheAndTrackHints(RooArgSet&) override ;
135
136 // The cache object
137 class CacheElem final : public RooAbsCacheElement {
138 public:
140 ~CacheElem() override = default;
141 // Payload
146 std::vector<std::unique_ptr<RooArgSet>> _normList;
148 std::unique_ptr<RooAbsReal> _rearrangedNum{};
149 std::unique_ptr<RooAbsReal> _rearrangedDen{};
150 // Cache management functions
152 void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) override ;
153 void writeToStream(std::ostream& os) const ;
154 } ;
155
156 std::unique_ptr<CacheElem> createCacheElem(const RooArgSet* nset, const RooArgSet* iset, const char* isetRangeName=nullptr) const;
157
158 mutable RooObjCacheManager _cacheMgr ; //! The cache manager
159
160 CacheElem* getCacheElem(RooArgSet const* nset) const ;
161 void rearrangeProduct(CacheElem&) const;
162 RooAbsReal* specializeIntegral(RooAbsReal& orig, const char* targetRangeName) const ;
163 RooAbsReal* specializeRatio(RooFormulaVar& input, const char* targetRangeName) const ;
164 double calculate(const RooProdPdf::CacheElem& cache, bool verbose=false) const ;
165 void calculateBatch(const RooProdPdf::CacheElem& cache, cudaStream_t*, double* output, size_t nEvents, RooFit::Detail::DataMap const&) const;
166
167
168 friend class RooProdGenContext ;
169 friend class RooFixedProdPdf ;
170 RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr,
171 const RooArgSet *auxProto=nullptr, bool verbose= false) const override ;
172
173
174 mutable RooAICRegistry _genCode ; ///<! Registry of composite direct generator codes
175
176 double _cutOff = 0.0; ///< Cutoff parameter for running product
177 RooListProxy _pdfList ; ///< List of PDF components
178 std::vector<std::unique_ptr<RooArgSet>> _pdfNSetList ; ///< List of PDF component normalization sets
179 Int_t _extendedIndex = -1; ///< Index of extended PDF (if any)
180
181 void useDefaultGen(bool flag=true) { _useDefaultGen = flag ; }
182 bool _useDefaultGen = false; ///< Use default or distributed event generator
183
184 mutable TNamed* _refRangeName = nullptr; ///< Reference range name for interpretation of conditional products
185
186 bool _selfNorm = true; ///< Is self-normalized
187 RooArgSet _defNormSet ; ///< Default normalization set
188
189private:
190
191
192
193 ClassDefOverride(RooProdPdf,6) // PDF representing a product of PDFs
194};
195
196
197#endif
RooArgList * pRooArgList
Definition: RooProdPdf.h:30
RooLinkedList * pRooLinkedList
Definition: RooProdPdf.h:31
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
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:392
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.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
const char * normRange() const
Definition: RooAbsPdf.h:308
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:60
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
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:55
A RooProdPdf with a fixed normalization set can be replaced by this class.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement> and specia...
RooProdGenContext is an efficient implementation of the generator context specific for RooProdPdf PDF...
RooArgList containedArgs(Action) override
Return RooAbsArg components contained in the cache.
~CacheElem() override=default
std::unique_ptr< RooAbsReal > _rearrangedNum
Definition: RooProdPdf.h:148
void printCompactTreeHook(std::ostream &, const char *, Int_t, Int_t) override
Hook function to print cache contents in tree printing of RooProdPdf.
RooArgList _ownedList
Definition: RooProdPdf.h:145
RooArgList _partList
Definition: RooProdPdf.h:142
std::vector< std::unique_ptr< RooArgSet > > _normList
Definition: RooProdPdf.h:146
std::unique_ptr< RooAbsReal > _rearrangedDen
Definition: RooProdPdf.h:149
void writeToStream(std::ostream &os) const
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:33
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooProdPdf with cache-and-track, and label all RooProdPdf descendants wit...
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Query internal generation capabilities of component p.d.f.s and aggregate capabilities into master co...
void rearrangeProduct(CacheElem &) const
bool selfNormalized() const override
Shows if a PDF is self-normalized, which means that no attempt is made to add a normalization term.
Definition: RooProdPdf.h:61
void factorizeProduct(const RooArgSet &normSet, const RooArgSet &intSet, RooLinkedList &termList, RooLinkedList &normList, RooLinkedList &impDepList, RooLinkedList &crossDepList, RooLinkedList &intList) const
Factorize product in irreducible terms for given choice of integration/normalization.
Definition: RooProdPdf.cxx:474
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
RooArgSet * getConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, bool stripDisconnected, bool removeConstraintsFromPdf=false) const override
Return all parameter constraint p.d.f.s on parameters listed in constrainedParams.
~RooProdPdf() override
Destructor.
Definition: RooProdPdf.cxx:349
Int_t _extendedIndex
Index of extended PDF (if any)
Definition: RooProdPdf.h:179
RooProdPdf()
Default constructor.
Definition: RooProdPdf.cxx:82
void removePdfs(RooAbsCollection const &pdfs)
Remove some PDFs from the factors of this RooProdPdf.
bool _useDefaultGen
Use default or distributed event generator.
Definition: RooProdPdf.h:182
std::vector< std::unique_ptr< RooArgSet > > _pdfNSetList
List of PDF component normalization sets.
Definition: RooProdPdf.h:178
std::unique_ptr< RooArgSet > fillNormSetForServer(RooArgSet const &normSet, RooAbsArg const &server) const
void useDefaultGen(bool flag=true)
Definition: RooProdPdf.h:181
bool forceAnalyticalInt(const RooAbsArg &dep) const override
Force RooRealIntegral to offer all observables for internal integration.
void calculateBatch(const RooProdPdf::CacheElem &cache, cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const
Evaluate product of PDFs in batch mode.
Definition: RooProdPdf.cxx:413
void writeCacheToStream(std::ostream &os, RooArgSet const *nset) const
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
void getParametersHook(const RooArgSet *, RooArgSet *, bool stripDisconnected) const override
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Return generator context optimized for generating events from product p.d.f.s.
void setSelfNormalized(bool flag)
Definition: RooProdPdf.h:89
TNamed * _refRangeName
Reference range name for interpretation of conditional products.
Definition: RooProdPdf.h:184
RooAICRegistry _genCode
! Registry of composite direct generator codes
Definition: RooProdPdf.h:174
void addPdfs(RooAbsCollection const &pdfs)
Add some full PDFs to the factors of this RooProdPdf.
RooListProxy _pdfList
List of PDF components.
Definition: RooProdPdf.h:177
Int_t getPartIntList(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName=nullptr) const
Return list of (partial) integrals of product terms for integration of p.d.f over observables iset wh...
Definition: RooProdPdf.cxx:660
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooProdPdf to more intuitively reflect the contents of the prod...
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
RooAbsReal * specializeIntegral(RooAbsReal &orig, const char *targetRangeName) const
CacheMode canNodeBeCached() const override
Definition: RooProdPdf.h:133
RooObjCacheManager _cacheMgr
Definition: RooProdPdf.h:158
std::string makeRGPPName(const char *pfx, const RooArgSet &term, const RooArgSet &iset, const RooArgSet &nset, const char *isetRangeName) const
Make an appropriate automatic name for a RooGenProdProj object in getPartIntList()
bool isDirectGenSafe(const RooAbsArg &arg) const override
Forward determination of safety of internal generator code to component p.d.f that would generate the...
std::unique_ptr< RooAbsReal > makeCondPdfRatioCorr(RooAbsReal &term, const RooArgSet &termNset, const RooArgSet &termImpSet, const char *normRange, const char *refRange) const
For single normalization ranges.
RooArgSet * findPdfNSet(RooAbsPdf const &pdf) const
Look up user specified normalization set for given input PDF component.
ExtendMode extendMode() const override
If this product contains exactly one extendable p.d.f return the extension abilities of that p....
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
double expectedEvents(const RooArgSet *nset) const override
Return the expected number of events associated with the extendable input PDF in the product.
std::vector< RooAbsReal * > processProductTerm(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName, const RooArgSet *term, const RooArgSet &termNSet, const RooArgSet &termISet, bool &isOwned, bool forceWrap=false) const
Calculate integrals of factorized product terms over observables iset while normalized to observables...
TObject * clone(const char *newname) const override
Definition: RooProdPdf.h:55
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.
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned that so is the product.
RooArgSet * getConnectedParameters(const RooArgSet &observables) const
Return all parameter constraint p.d.f.s on parameters listed in constrainedParams.
double calculate(const RooProdPdf::CacheElem &cache, bool verbose=false) const
Calculate running product of pdfs terms, using the supplied normalization set in 'normSetList' for ea...
Definition: RooProdPdf.cxx:382
RooArgSet _defNormSet
Default normalization set.
Definition: RooProdPdf.h:187
RooAbsReal * specializeRatio(RooFormulaVar &input, const char *targetRangeName) const
CacheElem * getCacheElem(RooArgSet const *nset) const
The cache manager.
Definition: RooProdPdf.cxx:355
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Implement support for node removal.
void initGenerator(Int_t code) override
Forward one-time initialization call to component generation initialization methods.
void generateEvent(Int_t code) override
Generate a single event with configuration specified by 'code' Defer internal generation to component...
const RooArgList & pdfList() const
Definition: RooProdPdf.h:66
void groupProductTerms(std::list< std::vector< RooArgSet * > > &groupedTerms, RooArgSet &outerIntDeps, const RooLinkedList &terms, const RooLinkedList &norms, const RooLinkedList &imps, const RooLinkedList &ints, const RooLinkedList &cross) const
Group product into terms that can be calculated independently.
void fixRefRange(const char *rangeName)
std::unique_ptr< CacheElem > createCacheElem(const RooArgSet *nset, const RooArgSet *iset, const char *isetRangeName=nullptr) const
Definition: RooProdPdf.cxx:677
double evaluate() const override
Calculate current value of object.
Definition: RooProdPdf.cxx:371
void initializeFromCmdArgList(const RooArgSet &fullPdfSet, const RooLinkedList &l)
Initialize RooProdPdf configuration from given list of RooCmdArg configuration arguments and set of '...
Definition: RooProdPdf.cxx:290
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of conditiona...
bool _selfNorm
Is self-normalized.
Definition: RooProdPdf.h:186
double _cutOff
Cutoff parameter for running product.
Definition: RooProdPdf.h:176
void setDefNormSet(const RooArgSet &nset)
Definition: RooProdPdf.h:90
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
TLine l
Definition: textangle.C:4
static void output()