/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id$
 * 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_HIST_PDF
#define ROO_HIST_PDF

#include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooSetProxy.h"
#include "RooAICRegistry.h"

class RooRealVar;
class RooAbsReal;
class RooDataHist ;

class RooHistPdf : public RooAbsPdf {
public:
  RooHistPdf() ; 
  RooHistPdf(const char *name, const char *title, const RooArgSet& vars, const RooDataHist& dhist, Int_t intOrder=0);
  RooHistPdf(const char *name, const char *title, const RooArgList& pdfObs, const RooArgList& histObs, const RooDataHist& dhist, Int_t intOrder=0);
  RooHistPdf(const RooHistPdf& other, const char* name=0);
  virtual TObject* clone(const char* newname) const { return new RooHistPdf(*this,newname); }
  virtual ~RooHistPdf() ;

  RooDataHist& dataHist()  { 
    // Return RooDataHist that is represented
    return *_dataHist ; 
  }
  const RooDataHist& dataHist() const { 
    // Return RooDataHist that is represented
    return *_dataHist ; 
  }
  
  void setInterpolationOrder(Int_t order) { 
    // Set histogram interpolation order 
    _intOrder = order ; 
  }
  Int_t getInterpolationOrder() const { 
    // Return histogram interpolation order
    return _intOrder ; 
  }

  Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const ;
  Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const ;

  void setCdfBoundaries(Bool_t flag) { 
    // Set use of special boundary conditions for c.d.f.s
    _cdfBoundaries = flag ; 
  }
  Bool_t getCdfBoundaries() const { 
    // If true, special boundary conditions for c.d.f.s are used
    return _cdfBoundaries ; 
  }

  void setUnitNorm(Bool_t flag) { 
    // Declare contents to have unit normalization
    _unitNorm = flag ; 
  }
  Bool_t haveUnitNorm() const { 
    // Return true if contents is declared to be unit normalized
    return _unitNorm ; 
  }

  virtual Bool_t selfNormalized() const { return _unitNorm ; }

  virtual Int_t getMaxVal(const RooArgSet& vars) const ;
  virtual Double_t maxVal(Int_t code) const ;

  virtual std::list<Double_t>* plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi) const ; 
  virtual std::list<Double_t>* binBoundaries(RooAbsRealLValue& /*obs*/, Double_t /*xlo*/, Double_t /*xhi*/) const ;
  virtual Bool_t isBinnedDistribution(const RooArgSet&) const { return _intOrder==0 ; }


protected:

  Bool_t areIdentical(const RooDataHist& dh1, const RooDataHist& dh2) ;

  Bool_t importWorkspaceHook(RooWorkspace& ws) ;
  
  Double_t evaluate() const;
  Double_t totalVolume() const ;
  friend class RooAbsCachedPdf ;
  Double_t totVolume() const ;

  RooArgSet         _histObsList ; // List of observables defining dimensions of histogram
  RooSetProxy       _pdfObsList ;  // List of observables mapped onto histogram observables
  RooDataHist*      _dataHist ;  // Unowned pointer to underlying histogram
  TIterator*         _histObsIter ; //! 
  TIterator*         _pdfObsIter ; //! 
  mutable RooAICRegistry _codeReg ; //! Auxiliary class keeping tracking of analytical integration code
  Int_t             _intOrder ; // Interpolation order
  Bool_t            _cdfBoundaries ; // Use boundary conditions for CDFs.
  mutable Double_t  _totVolume ; //! Total volume of space (product of ranges of observables)
  Bool_t            _unitNorm  ; // Assume contents is unit normalized (for use as pdf cache)

  ClassDef(RooHistPdf,4) // Histogram based PDF
};

#endif
 RooHistPdf.h:1
 RooHistPdf.h:2
 RooHistPdf.h:3
 RooHistPdf.h:4
 RooHistPdf.h:5
 RooHistPdf.h:6
 RooHistPdf.h:7
 RooHistPdf.h:8
 RooHistPdf.h:9
 RooHistPdf.h:10
 RooHistPdf.h:11
 RooHistPdf.h:12
 RooHistPdf.h:13
 RooHistPdf.h:14
 RooHistPdf.h:15
 RooHistPdf.h:16
 RooHistPdf.h:17
 RooHistPdf.h:18
 RooHistPdf.h:19
 RooHistPdf.h:20
 RooHistPdf.h:21
 RooHistPdf.h:22
 RooHistPdf.h:23
 RooHistPdf.h:24
 RooHistPdf.h:25
 RooHistPdf.h:26
 RooHistPdf.h:27
 RooHistPdf.h:28
 RooHistPdf.h:29
 RooHistPdf.h:30
 RooHistPdf.h:31
 RooHistPdf.h:32
 RooHistPdf.h:33
 RooHistPdf.h:34
 RooHistPdf.h:35
 RooHistPdf.h:36
 RooHistPdf.h:37
 RooHistPdf.h:38
 RooHistPdf.h:39
 RooHistPdf.h:40
 RooHistPdf.h:41
 RooHistPdf.h:42
 RooHistPdf.h:43
 RooHistPdf.h:44
 RooHistPdf.h:45
 RooHistPdf.h:46
 RooHistPdf.h:47
 RooHistPdf.h:48
 RooHistPdf.h:49
 RooHistPdf.h:50
 RooHistPdf.h:51
 RooHistPdf.h:52
 RooHistPdf.h:53
 RooHistPdf.h:54
 RooHistPdf.h:55
 RooHistPdf.h:56
 RooHistPdf.h:57
 RooHistPdf.h:58
 RooHistPdf.h:59
 RooHistPdf.h:60
 RooHistPdf.h:61
 RooHistPdf.h:62
 RooHistPdf.h:63
 RooHistPdf.h:64
 RooHistPdf.h:65
 RooHistPdf.h:66
 RooHistPdf.h:67
 RooHistPdf.h:68
 RooHistPdf.h:69
 RooHistPdf.h:70
 RooHistPdf.h:71
 RooHistPdf.h:72
 RooHistPdf.h:73
 RooHistPdf.h:74
 RooHistPdf.h:75
 RooHistPdf.h:76
 RooHistPdf.h:77
 RooHistPdf.h:78
 RooHistPdf.h:79
 RooHistPdf.h:80
 RooHistPdf.h:81
 RooHistPdf.h:82
 RooHistPdf.h:83
 RooHistPdf.h:84
 RooHistPdf.h:85
 RooHistPdf.h:86
 RooHistPdf.h:87
 RooHistPdf.h:88
 RooHistPdf.h:89
 RooHistPdf.h:90
 RooHistPdf.h:91
 RooHistPdf.h:92
 RooHistPdf.h:93
 RooHistPdf.h:94
 RooHistPdf.h:95
 RooHistPdf.h:96
 RooHistPdf.h:97
 RooHistPdf.h:98
 RooHistPdf.h:99
 RooHistPdf.h:100
 RooHistPdf.h:101
 RooHistPdf.h:102
 RooHistPdf.h:103
 RooHistPdf.h:104
 RooHistPdf.h:105
 RooHistPdf.h:106
 RooHistPdf.h:107
 RooHistPdf.h:108
 RooHistPdf.h:109
 RooHistPdf.h:110
 RooHistPdf.h:111