Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 "RooNameSet.h"
25 #include "RooCacheManager.h"
26 #include "RooObjCacheManager.h"
27 #include "RooNameReg.h"
28 
29 class RooAddPdf : public RooAbsPdf {
30 public:
31 
32  RooAddPdf() ;
33  RooAddPdf(const char *name, const char *title=0);
34  RooAddPdf(const char *name, const char *title,
35  RooAbsPdf& pdf1, RooAbsPdf& pdf2, RooAbsReal& coef1) ;
36  RooAddPdf(const char *name, const char *title, const RooArgList& pdfList) ;
37  RooAddPdf(const char *name, const char *title, const RooArgList& pdfList, const RooArgList& coefList, Bool_t recursiveFraction=kFALSE) ;
38 
39  RooAddPdf(const RooAddPdf& other, const char* name=0) ;
40  virtual TObject* clone(const char* newname) const { return new RooAddPdf(*this,newname) ; }
41  virtual ~RooAddPdf() ;
42 
43  virtual Bool_t checkObservables(const RooArgSet* nset) const ;
44 
45  virtual Bool_t forceAnalyticalInt(const RooAbsArg& /*dep*/) const {
46  // Force RooRealIntegral to offer all observables for internal integration
47  return kTRUE ;
48  }
49  Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=0) const ;
50  Double_t analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const ;
51  virtual Bool_t selfNormalized() const {
52  // P.d.f is self normalized
53  return kTRUE ;
54  }
55 
56  virtual ExtendMode extendMode() const {
57  // Return extended mode capabilities
58  return ((_haveLastCoef&&!_recursive) || _allExtendable) ? MustBeExtended : CanNotBeExtended;
59  }
60  virtual Double_t expectedEvents(const RooArgSet* nset) const ;
61  virtual Double_t expectedEvents(const RooArgSet& nset) const {
62  // Return expected number of events for extended likelihood calculation
63  // which is the sum of all coefficients
64  return expectedEvents(&nset) ;
65  }
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 ; }
80  const char* getCoefRange() const { return _refCoefRangeName?RooNameReg::str(_refCoefRangeName):"" ; }
81 
82  virtual void resetErrorCounters(Int_t resetValue=10) ;
83 
84  virtual std::list<Double_t>* plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const ;
85  virtual std::list<Double_t>* binBoundaries(RooAbsRealLValue& /*obs*/, Double_t /*xlo*/, Double_t /*xhi*/) const ;
86  Bool_t isBinnedDistribution(const RooArgSet& obs) const ;
87 
88  void printMetaArgs(std::ostream& os) const ;
89 
90  virtual CacheMode canNodeBeCached() const { return RooAbsArg::NotAdvised ; } ;
91  virtual void setCacheAndTrackHints(RooArgSet&) ;
92 
93 protected:
94 
95  virtual void selectNormalization(const RooArgSet* depSet=0, Bool_t force=kFALSE) ;
96  virtual void selectNormalizationRange(const char* rangeName=0, Bool_t force=kFALSE) ;
97 
98  mutable RooSetProxy _refCoefNorm ; // Reference observable set for coefficient interpretation
99  mutable TNamed* _refCoefRangeName ; // Reference range name for coefficient interpreation
100 
101  Bool_t _projectCoefs ; // 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 
105  class CacheElem : public RooAbsCacheElement {
106  public:
107  virtual ~CacheElem() {} ;
108 
109  RooArgList _suppNormList ; // Supplemental normalization list
110  Bool_t _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 
117  virtual RooArgList containedArgs(Action) ;
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  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0,
127  const RooArgSet* auxProto=0, Bool_t verbose= kFALSE) const ;
128 
129 
130  Double_t evaluate() const;
131  virtual RooSpan<double> evaluateBatch(std::size_t begin, std::size_t batchSize) const;
132 
133 
134  mutable RooAICRegistry _codeReg ; //! Registry of component analytical integration codes
135 
136  RooListProxy _pdfList ; // List of component PDFs
137  RooListProxy _coefList ; // List of coefficients
138  mutable RooArgList* _snormList{nullptr}; //! List of supplemental normalization factors
139 
140  Bool_t _haveLastCoef ; // Flag indicating if last PDFs coefficient was supplied in the ctor
141  Bool_t _allExtendable ; // Flag indicating if all PDF components are extendable
142  Bool_t _recursive ; // Flag indicating is fractions are treated recursively
143 
144  mutable Int_t _coefErrCount ; //! Coefficient error counter
145 
146 private:
147  std::pair<const RooArgSet*, CacheElem*> getNormAndCache() const;
148 
149  ClassDef(RooAddPdf,3) // PDF representing a sum of PDFs
150 };
151 
152 #endif