ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooProdPdf.h,v 1.44 2007/07/16 21:04: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_PROD_PDF
#define ROO_PROD_PDF

#include "Riosfwd.h"
#include "RooAbsPdf.h"
#include "RooListProxy.h"
#include "RooLinkedList.h"
#include "RooAICRegistry.h"
#include "RooCacheManager.h"
#include "RooObjCacheManager.h"
#include "RooCmdArg.h"

typedef RooArgList* pRooArgList ;
typedef RooLinkedList* pRooLinkedList ;

class RooProdPdf : public RooAbsPdf {
public:
  RooProdPdf() ;
  RooProdPdf(const char *name, const char *title, Double_t cutOff=0);
  RooProdPdf(const char *name, const char *title,
	    RooAbsPdf& pdf1, RooAbsPdf& pdf2, Double_t cutOff=0) ;
  RooProdPdf(const char* name, const char* title, const RooArgList& pdfList, Double_t cutOff=0) ;
  RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet, const RooLinkedList& cmdArgList) ;

  RooProdPdf(const char* name, const char* title, const RooArgSet& fullPdfSet,
   	     const RooCmdArg& arg1            , const RooCmdArg& arg2=RooCmdArg(),
             const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
             const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
             const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) ;

  RooProdPdf(const char* name, const char* title, 
             const RooCmdArg& arg1,             const RooCmdArg& arg2=RooCmdArg(),
             const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
             const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
             const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) ;

  RooProdPdf(const RooProdPdf& other, const char* name=0) ;
  virtual TObject* clone(const char* newname) const { return new RooProdPdf(*this,newname) ; }
  virtual ~RooProdPdf() ;

  virtual Double_t getVal(const RooArgSet* set=0) const ;
  Double_t evaluate() const ;
  virtual Bool_t checkObservables(const RooArgSet* nset) const ;	

  virtual Bool_t forceAnalyticalInt(const RooAbsArg& dep) const ; 
  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 { return kTRUE ; }

  virtual ExtendMode extendMode() const ;
  virtual Double_t expectedEvents(const RooArgSet* nset) const ; 
  virtual Double_t expectedEvents(const RooArgSet& nset) const { return expectedEvents(&nset) ; }

  const RooArgList& pdfList() const { return _pdfList ; }

  virtual Int_t getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const;
  virtual void initGenerator(Int_t code) ;
  virtual void generateEvent(Int_t code);  
  virtual Bool_t isDirectGenSafe(const RooAbsArg& arg) const ; 

  // Constraint management
  virtual RooArgSet* getConstraints(const RooArgSet& observables, const RooArgSet& constrainedParams) const ;

  virtual std::list<Double_t>* plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const ; 

  void printMetaArgs(ostream& os) const ;


protected:

  void initializeFromCmdArgList(const RooArgSet& fullPdfSet, const RooLinkedList& l) ;

  void factorizeProduct(const RooArgSet& normSet, const RooArgSet& intSet, 
                        RooLinkedList& termList,   RooLinkedList& normList, 
                        RooLinkedList& impDepList, RooLinkedList& crossDepList,
                        RooLinkedList& intList) const;
  const char* makeRGPPName(const char* pfx, const RooArgSet& term, const RooArgSet& iset, const RooArgSet& nset, const char* isetRangeName) const ;
  void groupProductTerms(RooLinkedList& groupedTerms, RooArgSet& outerIntDeps,
                         const RooLinkedList& terms, const RooLinkedList& norms, 
                         const RooLinkedList& imps, const RooLinkedList& ints, const RooLinkedList& cross) const ;
  
  Double_t calculate(const RooArgList* partIntList, const RooLinkedList* normSetList) const ;
	
	
  void getPartIntList(const RooArgSet* nset, const RooArgSet* iset, pRooArgList& partList, pRooLinkedList& nsetList, 
                      Int_t& code, const char* isetRangeName=0) const ;
  RooAbsReal* processProductTerm(const RooArgSet* nset, const RooArgSet* iset, const char* isetRangeName,
                                 const RooArgSet* term,const RooArgSet& termNSet, const RooArgSet& termISet, 
                                 Bool_t& isOwned, Bool_t forceWrap=kFALSE) const ;


  // The cache object
  class CacheElem : public RooAbsCacheElement {
  public:
    virtual ~CacheElem() ;
    // Payload
    RooArgList _partList ;
    RooArgList _ownedList ;
    RooLinkedList _normList ;    
    // Cache management functions
    virtual RooArgList containedArgs(Action) ;
    virtual void printCompactTreeHook(std::ostream&, const char *, Int_t, Int_t) ;
  } ;
  mutable RooObjCacheManager _cacheMgr ; // The cache manager
 
  friend class RooProdGenContext ;
  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype=0, 
	                               const RooArgSet *auxProto=0, Bool_t verbose= kFALSE) const ;

  RooArgSet* findPdfNSet(RooAbsPdf& pdf) const ; 

  mutable RooAICRegistry _genCode ; //! Registry of composite direct generator codes

  mutable RooArgSet* _curNormSet ; //!
  Double_t _cutOff ;       //  Cutoff parameter for running product
  RooListProxy _pdfList ;  //  List of PDF components
  RooLinkedList _pdfNSetList ; // List of PDF component normalization sets
  TIterator* _pdfIter ;    //! Iterator of PDF list
  Int_t _extendedIndex ;   //  Index of extended PDF (if any) 

  void useDefaultGen(Bool_t flag=kTRUE) { _useDefaultGen = flag ; }
  Bool_t _useDefaultGen ; // Use default or distributed event generator
  
private:

  ClassDef(RooProdPdf,1) // PDF representing a product of PDFs
};


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