ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooRealIntegral.h,v 1.44 2007/05/11 09:11:30 verkerke 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_REAL_INTEGRAL
#define ROO_REAL_INTEGRAL

#include "RooAbsReal.h"
#include "RooArgSet.h"
#include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooSetProxy.h"
#include "RooListProxy.h"

class RooArgSet ;
class TH1F ;
class RooAbsCategory ;
class RooRealVar ;
class RooAbsIntegrator ;
class RooNumIntConfig ;

class RooRealIntegral : public RooAbsReal {
public:

  // Constructors, assignment etc
  RooRealIntegral() ;
  RooRealIntegral(const char *name, const char *title, const RooAbsReal& function, const RooArgSet& depList,
		  const RooArgSet* funcNormSet=0, const RooNumIntConfig* config=0, const char* rangeName=0) ;
  RooRealIntegral(const RooRealIntegral& other, const char* name=0);
  virtual TObject* clone(const char* newname) const { return new RooRealIntegral(*this,newname); }
  virtual ~RooRealIntegral();

  Bool_t isValid() const { return _valid; }

  void printMultiline(ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
  void printMetaArgs(ostream& os) const ;

  const RooArgSet& numIntCatVars() const { return _sumList ; }
  const RooArgSet& numIntRealVars() const { return _intList ; }
  const RooArgSet& anaIntVars() const { return _anaList ; }

  void setCacheNumeric(Bool_t flag) { 
    // If true, value of this interal is cached if it is (partially numeric)
    _cacheNum = flag ;
  }

  Bool_t getCacheNumeric() { 
    // If true, value of this interal is cached if it is (partially numeric)
    return _cacheNum ;
  }

  static void setCacheAllNumeric(Int_t ndim) {
    // Global switch to cache all integral values that integrate at least ndim dimensions numerically 
    _cacheAllNDim = ndim ;
  }

  static Int_t getCacheAllNumeric() {
    // Return minimum dimensions of numeric integration for which values are cached. 
    return _cacheAllNDim ;
  }

  virtual std::list<Double_t>* plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const {
    // Forward plot sampling hint of integrand
    return _function.arg().plotSamplingHint(obs,xlo,xhi) ;
  }

  virtual RooAbsReal* createIntegral(const RooArgSet& iset, const RooArgSet* nset=0, const RooNumIntConfig* cfg=0, const char* rangeName=0) const ;  

protected:

  mutable Bool_t _valid;

  const RooArgSet& parameters() const ;

  enum IntOperMode { Hybrid, Analytic, PassThrough } ;
  //friend class RooAbsPdf ;

  Bool_t initNumIntegrator() const;
  void autoSelectDirtyMode() ;

  virtual Double_t sum() const ;
  virtual Double_t integrate() const ;
  virtual Double_t jacobianProduct() const ;

  // Evaluation and validation implementation
  Double_t evaluate() const ;
  virtual Bool_t isValidReal(Double_t value, Bool_t printError=kFALSE) const ;
  Bool_t servesExclusively(const RooAbsArg* server,const RooArgSet& exclLVBranches, const RooArgSet& allBranches) const ;


  virtual Bool_t redirectServersHook(const RooAbsCollection& newServerList, 
				     Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive) ;

  // Function pointer and integrands list
  mutable RooSetProxy _sumList ; // Set of discrete observable over which is summed numerically
  mutable RooSetProxy _intList ; // Set of continuous observables over which is integrated numerically
  mutable RooSetProxy _anaList ; // Set of observables over which is integrated/summed analytically
  mutable RooSetProxy _jacList ; // Set of lvalue observables over which is analytically integration that have a non-unit Jacobian
  mutable RooSetProxy _facList ; // Set of observables on which function does not depends, which are integrated nevertheless

  mutable RooArgSet   _facListOwned ;  // Owned components in _facList
  TIterator*          _facListIter ; //! Iterator over factorizing observables
  TIterator*          _jacListIter ; //! Iterator over lvalue observables with Jacobian
  RooRealProxy       _function ;     // Function being integration
  RooArgSet*      _funcNormSet ;     // Optional normalization set passed to function

  mutable RooArgSet       _saveInt ; //! do not persist
  mutable RooArgSet       _saveSum ; //! do not persist 

  RooNumIntConfig* _iconfig ;

  mutable RooListProxy _sumCat ; //! do not persist  
  TIterator* _sumCatIter ; //!
  
  Int_t _mode ;
  IntOperMode _intOperMode ;   // integration operation mode

  mutable Bool_t _restartNumIntEngine ; //! do not persist
  mutable RooAbsIntegrator* _numIntEngine ;  //! do not persist
  mutable RooAbsFunc *_numIntegrand;         //! do not persist

  TNamed* _rangeName ; 
  
  mutable RooArgSet* _params ; //! cache for set of parameters

  Bool_t _cacheNum ;           // Cache integral if numeric
  static Int_t _cacheAllNDim ; //! Cache all integrals with given numeric dimension


  virtual void operModeHook() ; // cache operation mode

  ClassDef(RooRealIntegral,2) // Real-valued function representing an integral over a RooAbsReal object
};

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