Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooAddModel.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_MODEL
17 #define ROO_ADD_MODEL
18 
19 #include "RooResolutionModel.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 
28 class RooAddModel : public RooResolutionModel {
29 public:
30 
31  RooAddModel() ;
32  RooAddModel(const char *name, const char *title, const RooArgList& pdfList, const RooArgList& coefList, Bool_t ownPdfList=kFALSE) ;
33  RooAddModel(const RooAddModel& other, const char* name=0) ;
34  virtual TObject* clone(const char* newname) const { return new RooAddModel(*this,newname) ; }
35  virtual RooResolutionModel* convolution(RooFormulaVar* basis, RooAbsArg* owner) const ;
36  virtual ~RooAddModel() ;
37 
38  Double_t evaluate() const ;
39  virtual Bool_t checkObservables(const RooArgSet* nset) const ;
40 
41  virtual Int_t basisCode(const char* name) const ;
42 
43  virtual Bool_t forceAnalyticalInt(const RooAbsArg& /*dep*/) const {
44  // Force RooRealIntegral to offer all observables for internal integration
45  return kTRUE ;
46  }
47  Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=0) const ;
48  Double_t analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const ;
49  virtual Bool_t selfNormalized() const {
50  // Model is self normalized when used as p.d.f
51  return _basisCode==0 ? kTRUE : kFALSE ;
52  }
53 
54  virtual ExtendMode extendMode() const {
55  // Return extended mode capabilities
56  return (_haveLastCoef || _allExtendable) ? MustBeExtended : CanNotBeExtended;
57  }
58  virtual Double_t expectedEvents(const RooArgSet* nset) const ;
59  virtual Double_t expectedEvents(const RooArgSet& nset) const {
60  // Return expected number of events for extended likelihood calculation
61  // which is the sum of all coefficients
62  return expectedEvents(&nset) ;
63  }
64 
65  const RooArgList& pdfList() const {
66  // Return list of component p.d.fs
67  return _pdfList ;
68  }
69  const RooArgList& coefList() const {
70  // Return list of coefficients of component p.d.f.s
71  return _coefList ;
72  }
73 
74  Bool_t isDirectGenSafe(const RooAbsArg& arg) const ;
75 
76  Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;
77  void generateEvent(Int_t code);
78 
79 
80  void fixCoefNormalization(const RooArgSet& refCoefNorm) ;
81  void fixCoefRange(const char* rangeName) ;
82  virtual void resetErrorCounters(Int_t resetValue=10) ;
83 
84  void printMetaArgs(std::ostream& os) const ;
85 
86 protected:
87 
88  friend class RooAddGenContext ;
89  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0,
90  const RooArgSet* auxProto=0, Bool_t verbose= kFALSE) const ;
91 
92  virtual void selectNormalization(const RooArgSet* depSet=0, Bool_t force=kFALSE) ;
93  virtual void selectNormalizationRange(const char* rangeName=0, Bool_t force=kFALSE) ;
94 
95  mutable RooSetProxy _refCoefNorm ; //! Reference observable set for coefficient interpretation
96  mutable TNamed* _refCoefRangeName ; //! Reference range name for coefficient interpreation
97 
98  Bool_t _projectCoefs ; // If true coefficients need to be projected for use in evaluate()
99  mutable Double_t* _coefCache ; //! Transiet cache with transformed values of coefficients
100 
101 
102  class CacheElem : public RooAbsCacheElement {
103  public:
104  virtual ~CacheElem() {} ;
105 
106  RooArgList _suppNormList ; // Supplemental normalization list
107 
108  RooArgList _projList ; // Projection integrals to be multiplied with coefficients
109  RooArgList _suppProjList ; // Projection integrals to be multiplied with coefficients for supplemental normalization terms
110  RooArgList _refRangeProjList ; // Range integrals to be multiplied with coefficients (reference range)
111  RooArgList _rangeProjList ; // Range integrals to be multiplied with coefficients (target range)
112 
113  virtual RooArgList containedArgs(Action) ;
114 
115  } ;
116  mutable RooObjCacheManager _projCacheMgr ; // Manager of cache with coefficient projections and transformations
117  CacheElem* getProjCache(const RooArgSet* nset, const RooArgSet* iset=0, const char* rangeName=0) const ;
118  void updateCoefficients(CacheElem& cache, const RooArgSet* nset) const ;
119 
120  typedef RooArgList* pRooArgList ;
121  void getCompIntList(const RooArgSet* nset, const RooArgSet* iset, pRooArgList& compIntList, Int_t& code, const char* isetRangeName) const ;
122  class IntCacheElem : public RooAbsCacheElement {
123  public:
124  virtual ~IntCacheElem() {} ;
125  RooArgList _intList ; // List of component integrals
126  virtual RooArgList containedArgs(Action) ;
127  } ;
128 
129  mutable RooObjCacheManager _intCacheMgr ; // Manager of cache with integrals
130 
131  mutable RooAICRegistry _codeReg ; //! Registry of component analytical integration codes
132 
133  RooListProxy _pdfList ; // List of component PDFs
134  RooListProxy _coefList ; // List of coefficients
135  mutable RooArgList* _snormList ; //! List of supplemental normalization factors
136  TIterator* _pdfIter ; //! Iterator over PDF list
137  TIterator* _coefIter ; //! Iterator over coefficient list
138 
139  Bool_t _haveLastCoef ; // Flag indicating if last PDFs coefficient was supplied in the ctor
140  Bool_t _allExtendable ; // Flag indicating if all PDF components are extendable
141 
142  mutable Int_t _coefErrCount ; //! Coefficient error counter
143 
144  mutable RooArgSet _ownedComps ; //! Owned components
145 
146 private:
147 
148  ClassDef(RooAddModel,1) // Resolution model representing a sum of resolution models
149 };
150 
151 #endif