ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooAddPdf.h,v 1.46 2007/07/12 20:30:28 wouter Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_ADD_MODEL
#define ROO_ADD_MODEL

#include "RooResolutionModel.h"
#include "RooListProxy.h"
#include "RooAICRegistry.h"
#include "RooNormSetCache.h"
#include "RooNameSet.h"
#include "RooCacheManager.h"
#include "RooObjCacheManager.h"

class RooAddModel : public RooResolutionModel {
public:

  RooAddModel() ;
  RooAddModel(const char *name, const char *title, const RooArgList& pdfList, const RooArgList& coefList, Bool_t ownPdfList=kFALSE) ;
  RooAddModel(const RooAddModel& other, const char* name=0) ;
  virtual TObject* clone(const char* newname) const { return new RooAddModel(*this,newname) ; }
  virtual RooResolutionModel* convolution(RooFormulaVar* basis, RooAbsArg* owner) const ;
  virtual ~RooAddModel() ;

  Double_t evaluate() const ;
  virtual Bool_t checkObservables(const RooArgSet* nset) const ;	

  virtual Int_t basisCode(const char* name) const ;

  virtual Bool_t forceAnalyticalInt(const RooAbsArg& /*dep*/) const { 
    // Force RooRealIntegral to offer all observables for internal integration
    return kTRUE ; 
  }
  Int_t getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& numVars, const RooArgSet* normSet, const char* rangeName=0) const ;
  Double_t analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName=0) const ;
  virtual Bool_t selfNormalized() const { 
    // Model is self normalized when used as p.d.f 
    return _basisCode==0 ? kTRUE : kFALSE ; 
  }

  virtual ExtendMode extendMode() const { 
    // Return extended mode capabilities    
    return (_haveLastCoef || _allExtendable) ? MustBeExtended : CanNotBeExtended; 
  }
  virtual Double_t expectedEvents(const RooArgSet* nset) const ;
  virtual Double_t expectedEvents(const RooArgSet& nset) const { 
    // Return expected number of events for extended likelihood calculation
    // which is the sum of all coefficients
    return expectedEvents(&nset) ; 
  }

  const RooArgList& pdfList() const { 
    // Return list of component p.d.fs
    return _pdfList ; 
  }
  const RooArgList& coefList() const { 
    // Return list of coefficients of component p.d.f.s
    return _coefList ; 
  }

  Bool_t isDirectGenSafe(const RooAbsArg& arg) const ;

  Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;
  void generateEvent(Int_t code);


  void fixCoefNormalization(const RooArgSet& refCoefNorm) ;
  void fixCoefRange(const char* rangeName) ;
  virtual void resetErrorCounters(Int_t resetValue=10) ;

  void printMetaArgs(ostream& os) const ;

protected:

  friend class RooAddGenContext ;
  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0, 
                                       const RooArgSet* auxProto=0, Bool_t verbose= kFALSE) const ;

  virtual void selectNormalization(const RooArgSet* depSet=0, Bool_t force=kFALSE) ;
  virtual void selectNormalizationRange(const char* rangeName=0, Bool_t force=kFALSE) ;

  mutable RooSetProxy _refCoefNorm ;   //! Reference observable set for coefficient interpretation
  mutable TNamed* _refCoefRangeName ;  //! Reference range name for coefficient interpreation

  Bool_t _projectCoefs ;         // If true coefficients need to be projected for use in evaluate()
  mutable Double_t* _coefCache ; //! Transiet cache with transformed values of coefficients


  class CacheElem : public RooAbsCacheElement {
  public:
    virtual ~CacheElem() {} ;

    RooArgList _suppNormList ; // Supplemental normalization list

    RooArgList _projList ; // Projection integrals to be multiplied with coefficients
    RooArgList _suppProjList ; // Projection integrals to be multiplied with coefficients for supplemental normalization terms
    RooArgList _refRangeProjList ; // Range integrals to be multiplied with coefficients (reference range)
    RooArgList _rangeProjList ; // Range integrals to be multiplied with coefficients (target range)

    virtual RooArgList containedArgs(Action) ;

  } ;
  mutable RooObjCacheManager _projCacheMgr ;  // Manager of cache with coefficient projections and transformations
  CacheElem* getProjCache(const RooArgSet* nset, const RooArgSet* iset=0, const char* rangeName=0) const ;
  void updateCoefficients(CacheElem& cache, const RooArgSet* nset) const ;

  typedef RooArgList* pRooArgList ;
  void getCompIntList(const RooArgSet* nset, const RooArgSet* iset, pRooArgList& compIntList, Int_t& code, const char* isetRangeName) const ;
  class IntCacheElem : public RooAbsCacheElement {
  public:
    virtual ~IntCacheElem() {} ;
    RooArgList _intList ; // List of component integrals 
    virtual RooArgList containedArgs(Action) ;
  } ;
  
  mutable RooObjCacheManager _intCacheMgr ; // Manager of cache with integrals
 
  mutable RooAICRegistry _codeReg ;  //! Registry of component analytical integration codes

  RooListProxy _pdfList ;   //  List of component PDFs
  RooListProxy _coefList ;  //  List of coefficients
  mutable RooArgList* _snormList ;  //!  List of supplemental normalization factors
  TIterator* _pdfIter ;     //! Iterator over PDF list
  TIterator* _coefIter ;    //! Iterator over coefficient list
  
  Bool_t _haveLastCoef ;    //  Flag indicating if last PDFs coefficient was supplied in the ctor
  Bool_t _allExtendable ;   //  Flag indicating if all PDF components are extendable

  mutable Int_t _coefErrCount ; //! Coefficient error counter

  mutable RooArgSet _ownedComps ; //! Owned components

private:

  ClassDef(RooAddModel,1) // Resolution model representing a sum of resolution models
};

#endif
 RooAddModel.h:1
 RooAddModel.h:2
 RooAddModel.h:3
 RooAddModel.h:4
 RooAddModel.h:5
 RooAddModel.h:6
 RooAddModel.h:7
 RooAddModel.h:8
 RooAddModel.h:9
 RooAddModel.h:10
 RooAddModel.h:11
 RooAddModel.h:12
 RooAddModel.h:13
 RooAddModel.h:14
 RooAddModel.h:15
 RooAddModel.h:16
 RooAddModel.h:17
 RooAddModel.h:18
 RooAddModel.h:19
 RooAddModel.h:20
 RooAddModel.h:21
 RooAddModel.h:22
 RooAddModel.h:23
 RooAddModel.h:24
 RooAddModel.h:25
 RooAddModel.h:26
 RooAddModel.h:27
 RooAddModel.h:28
 RooAddModel.h:29
 RooAddModel.h:30
 RooAddModel.h:31
 RooAddModel.h:32
 RooAddModel.h:33
 RooAddModel.h:34
 RooAddModel.h:35
 RooAddModel.h:36
 RooAddModel.h:37
 RooAddModel.h:38
 RooAddModel.h:39
 RooAddModel.h:40
 RooAddModel.h:41
 RooAddModel.h:42
 RooAddModel.h:43
 RooAddModel.h:44
 RooAddModel.h:45
 RooAddModel.h:46
 RooAddModel.h:47
 RooAddModel.h:48
 RooAddModel.h:49
 RooAddModel.h:50
 RooAddModel.h:51
 RooAddModel.h:52
 RooAddModel.h:53
 RooAddModel.h:54
 RooAddModel.h:55
 RooAddModel.h:56
 RooAddModel.h:57
 RooAddModel.h:58
 RooAddModel.h:59
 RooAddModel.h:60
 RooAddModel.h:61
 RooAddModel.h:62
 RooAddModel.h:63
 RooAddModel.h:64
 RooAddModel.h:65
 RooAddModel.h:66
 RooAddModel.h:67
 RooAddModel.h:68
 RooAddModel.h:69
 RooAddModel.h:70
 RooAddModel.h:71
 RooAddModel.h:72
 RooAddModel.h:73
 RooAddModel.h:74
 RooAddModel.h:75
 RooAddModel.h:76
 RooAddModel.h:77
 RooAddModel.h:78
 RooAddModel.h:79
 RooAddModel.h:80
 RooAddModel.h:81
 RooAddModel.h:82
 RooAddModel.h:83
 RooAddModel.h:84
 RooAddModel.h:85
 RooAddModel.h:86
 RooAddModel.h:87
 RooAddModel.h:88
 RooAddModel.h:89
 RooAddModel.h:90
 RooAddModel.h:91
 RooAddModel.h:92
 RooAddModel.h:93
 RooAddModel.h:94
 RooAddModel.h:95
 RooAddModel.h:96
 RooAddModel.h:97
 RooAddModel.h:98
 RooAddModel.h:99
 RooAddModel.h:100
 RooAddModel.h:101
 RooAddModel.h:102
 RooAddModel.h:103
 RooAddModel.h:104
 RooAddModel.h:105
 RooAddModel.h:106
 RooAddModel.h:107
 RooAddModel.h:108
 RooAddModel.h:109
 RooAddModel.h:110
 RooAddModel.h:111
 RooAddModel.h:112
 RooAddModel.h:113
 RooAddModel.h:114
 RooAddModel.h:115
 RooAddModel.h:116
 RooAddModel.h:117
 RooAddModel.h:118
 RooAddModel.h:119
 RooAddModel.h:120
 RooAddModel.h:121
 RooAddModel.h:122
 RooAddModel.h:123
 RooAddModel.h:124
 RooAddModel.h:125
 RooAddModel.h:126
 RooAddModel.h:127
 RooAddModel.h:128
 RooAddModel.h:129
 RooAddModel.h:130
 RooAddModel.h:131
 RooAddModel.h:132
 RooAddModel.h:133
 RooAddModel.h:134
 RooAddModel.h:135
 RooAddModel.h:136
 RooAddModel.h:137
 RooAddModel.h:138
 RooAddModel.h:139
 RooAddModel.h:140
 RooAddModel.h:141
 RooAddModel.h:142
 RooAddModel.h:143
 RooAddModel.h:144
 RooAddModel.h:145
 RooAddModel.h:146
 RooAddModel.h:147
 RooAddModel.h:148
 RooAddModel.h:149
 RooAddModel.h:150