/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitModels                                                     *
 *    File: $Id: RooEffProd.h,v 1.2 2007/05/11 10:14:56 verkerke Exp $
 * Authors:                                                                  *
 *   GR, Gerhard Raven, NIKHEF/VU                                            *
 *                                                                           *
 * 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_EFF_PROD
#define ROO_EFF_PROD

#include "RooAbsPdf.h"
#include "RooAbsReal.h"
#include "RooRealProxy.h"
#include "RooObjCacheManager.h"

class RooEffProd: public RooAbsPdf {
public:
  // Constructors, assignment etc
  inline RooEffProd() : _nset(0), _fixedNset(0) { };
  virtual ~RooEffProd();
  RooEffProd(const char *name, const char *title, RooAbsPdf& pdf, RooAbsReal& efficiency);
  RooEffProd(const RooEffProd& other, const char* name=0);

  virtual TObject* clone(const char* newname) const { return new RooEffProd(*this,newname); }

  virtual RooAbsGenContext* genContext(const RooArgSet &vars, const RooDataSet *prototype,
                                       const RooArgSet* auxProto, Bool_t verbose) const;

  virtual Double_t getValV(const RooArgSet* set=0) const ;

  virtual Bool_t forceAnalyticalInt(const RooAbsArg& /*dep*/) const { 
    // Return kTRUE to 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 ;
  
protected:
  
  const RooAbsPdf* pdf() const { 
    // Return pointer to pdf in product
    return (RooAbsPdf*) _pdf.absArg() ; 
  }
  const RooAbsReal* eff() const { 
    // Return pointer to efficiency function in product
    return (RooAbsReal*) _eff.absArg() ; 
  }

  // Function evaluation
  virtual Double_t evaluate() const ;

  class CacheElem : public RooAbsCacheElement {
  public:
    CacheElem() : _clone(0), _int(0) {} 
    virtual ~CacheElem() { delete _int ; delete _clone ; }
    // Payload
    RooArgSet   _intObs ;
    RooEffProd* _clone ;
    RooAbsReal* _int ;    
    // Cache management functions
    virtual RooArgList containedArgs(Action) ;
  } ;
  mutable RooObjCacheManager _cacheMgr ; //! The cache manager


  // the real stuff...
  RooRealProxy _pdf ;               // Probability Density function
  RooRealProxy _eff;                // Efficiency function
  mutable const RooArgSet* _nset  ; //! Normalization set to be used in evaluation

  RooArgSet* _fixedNset ; //! Fixed normalization set overriding default normalization set (if provided)

  ClassDef(RooEffProd,2) // Product operator p.d.f of (PDF x efficiency) implementing optimized generator context
};

#endif
 RooEffProd.h:1
 RooEffProd.h:2
 RooEffProd.h:3
 RooEffProd.h:4
 RooEffProd.h:5
 RooEffProd.h:6
 RooEffProd.h:7
 RooEffProd.h:8
 RooEffProd.h:9
 RooEffProd.h:10
 RooEffProd.h:11
 RooEffProd.h:12
 RooEffProd.h:13
 RooEffProd.h:14
 RooEffProd.h:15
 RooEffProd.h:16
 RooEffProd.h:17
 RooEffProd.h:18
 RooEffProd.h:19
 RooEffProd.h:20
 RooEffProd.h:21
 RooEffProd.h:22
 RooEffProd.h:23
 RooEffProd.h:24
 RooEffProd.h:25
 RooEffProd.h:26
 RooEffProd.h:27
 RooEffProd.h:28
 RooEffProd.h:29
 RooEffProd.h:30
 RooEffProd.h:31
 RooEffProd.h:32
 RooEffProd.h:33
 RooEffProd.h:34
 RooEffProd.h:35
 RooEffProd.h:36
 RooEffProd.h:37
 RooEffProd.h:38
 RooEffProd.h:39
 RooEffProd.h:40
 RooEffProd.h:41
 RooEffProd.h:42
 RooEffProd.h:43
 RooEffProd.h:44
 RooEffProd.h:45
 RooEffProd.h:46
 RooEffProd.h:47
 RooEffProd.h:48
 RooEffProd.h:49
 RooEffProd.h:50
 RooEffProd.h:51
 RooEffProd.h:52
 RooEffProd.h:53
 RooEffProd.h:54
 RooEffProd.h:55
 RooEffProd.h:56
 RooEffProd.h:57
 RooEffProd.h:58
 RooEffProd.h:59
 RooEffProd.h:60
 RooEffProd.h:61
 RooEffProd.h:62
 RooEffProd.h:63
 RooEffProd.h:64
 RooEffProd.h:65
 RooEffProd.h:66
 RooEffProd.h:67
 RooEffProd.h:68
 RooEffProd.h:69
 RooEffProd.h:70
 RooEffProd.h:71
 RooEffProd.h:72
 RooEffProd.h:73
 RooEffProd.h:74
 RooEffProd.h:75
 RooEffProd.h:76
 RooEffProd.h:77
 RooEffProd.h:78
 RooEffProd.h:79
 RooEffProd.h:80