/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooMCIntegrator.h,v 1.15 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_MC_INTEGRATOR
#define ROO_MC_INTEGRATOR

#include "RooAbsIntegrator.h"
#include "RooGrid.h"
#include "RooNumIntConfig.h"
#include "TStopwatch.h"

class RooMCIntegrator : public RooAbsIntegrator {
public:

  // Constructors, assignment etc
  enum SamplingMode { Importance, ImportanceOnly, Stratified };
  enum GeneratorType { QuasiRandom, PseudoRandom };
  RooMCIntegrator() ;
  RooMCIntegrator(const RooAbsFunc& function, SamplingMode mode= Importance,
		  GeneratorType genType= QuasiRandom, Bool_t verbose= kFALSE);
  RooMCIntegrator(const RooAbsFunc& function, const RooNumIntConfig& config);
  virtual RooAbsIntegrator* clone(const RooAbsFunc& function, const RooNumIntConfig& config) const ;
  virtual ~RooMCIntegrator();

  virtual Bool_t checkLimits() const;
  virtual Double_t integral(const Double_t* yvec=0);

  enum Stage { AllStages, ReuseGrid, RefineGrid };
  Double_t vegas(Stage stage, UInt_t calls, UInt_t iterations, Double_t *absError= 0);

  Double_t getAlpha() const { return _alpha;   }
  void setAlpha(Double_t alpha) { _alpha= alpha; }

  GeneratorType getGenType() const { return _genType; }
  void setGenType(GeneratorType type) { _genType= type; }

  const RooGrid &grid() const { return _grid; }

  virtual Bool_t canIntegrate1D() const { return kTRUE ; }
  virtual Bool_t canIntegrate2D() const { return kTRUE ; }
  virtual Bool_t canIntegrateND() const { return kTRUE ; }
  virtual Bool_t canIntegrateOpenEnded() const { return kFALSE ; }

protected:

  friend class RooNumIntFactory ;
  static void registerIntegrator(RooNumIntFactory& fact) ;	

  mutable RooGrid _grid;  // Sampling grid definition

  // control variables
  Bool_t _verbose;          // Verbosity control
  Double_t _alpha;          // Grid stiffness parameter
  Int_t _mode;              // Sampling mode
  GeneratorType _genType;   // Generator type
  Int_t _nRefineIter ;      // Number of refinement iterations
  Int_t _nRefinePerDim ;    // Number of refinement samplings (per dim)
  Int_t _nIntegratePerDim ; // Number of integration samplings (per dim)

  TStopwatch _timer;        // Timer

  Double_t _jac,_wtd_int_sum,_sum_wgts,_chi_sum,_chisq,_result,_sigma; // Scratch variables preserved between calls to vegas1/2/2
  UInt_t _it_start,_it_num,_samples,_calls_per_box;                    // Scratch variables preserved between calls to vegas1/2/2

  ClassDef(RooMCIntegrator,0) // VEGAS based multi-dimensional numerical integration engine
};

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