/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id$
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, NIKHEF, verkerke@nikhef.nl                         *
 *                                                                           *
 * Copyright (c) 2000-2011, 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_UNIT_TEST
#define ROO_UNIT_TEST

#include "Rtypes.h"
#include "TNamed.h" 
#include "RooTable.h"
#include "RooWorkspace.h"
#include "RooFitResult.h"
#include "RooPlot.h"
#include "TFile.h"
#include "TH1.h"
#include <list>
#include <string>
#include <map>

/*
 * The tolerance for the curve test is put to 0.4 instead of 0.2 to take into
 * account the small variations in the values of the likelihood which can occur
 * in presence of a different treatment of floating point numbers.
 */

class RooUnitTest : public TNamed {
public:
  RooUnitTest(const char* name, TFile* refFile, Bool_t writeRef, Int_t verbose) ;
  ~RooUnitTest() ;
  
  void setDebug(Bool_t flag) { _debug = flag ; }
  void setSilentMode() ;
  void clearSilentMode() ;
  void regPlot(RooPlot* frame, const char* refName) ;  
  void regResult(RooFitResult* r, const char* refName) ;
  void regValue(Double_t value, const char* refName) ;
  void regTable(RooTable* t, const char* refName) ;
  void regWS(RooWorkspace* ws, const char* refName) ;
  void regTH(TH1* h, const char* refName) ;
  RooWorkspace* getWS(const char* refName) ;
  Bool_t runTest() ;
  Bool_t runCompTests() ;
  Bool_t areTHidentical(TH1* htest, TH1* href) ;

  virtual Bool_t isTestAvailable() { return kTRUE ; }
  virtual Bool_t testCode() = 0 ;  

  virtual Double_t htol() { return 5e-4 ; } // histogram test tolerance (KS dist != prob)
#ifdef R__FAST_MATH
  virtual Double_t ctol() { return 2e-3 ; } // curve test tolerance
#else
  virtual Double_t ctol() { return 4e-3 ; } // curve test tolerance
#endif
  virtual Double_t fptol() { return 1e-3 ; } // fit parameter test tolerance
  virtual Double_t fctol() { return 1e-3 ; } // fit correlation test tolerance
  virtual Double_t vtol() { return 1e-3 ; } // value test tolerance

  static void setMemDir(TDirectory* memDir);

protected:

  static TDirectory* gMemDir ;

  TFile* _refFile ;
  Bool_t _debug ;
  Bool_t _write ;
  Int_t _verb ;
   std::list<std::pair<RooPlot*, std::string> > _regPlots ;
   std::list<std::pair<RooFitResult*, std::string> > _regResults ;
   std::list<std::pair<Double_t, std::string> > _regValues ;
   std::list<std::pair<RooTable*,std::string> > _regTables ;
   std::list<std::pair<RooWorkspace*,std::string> > _regWS ;
   std::list<std::pair<TH1*,std::string> > _regTH ;

  ClassDef(RooUnitTest,0) ; // Abstract base class for RooFit/RooStats unit regression tests
} ;
#endif
 RooUnitTest.h:1
 RooUnitTest.h:2
 RooUnitTest.h:3
 RooUnitTest.h:4
 RooUnitTest.h:5
 RooUnitTest.h:6
 RooUnitTest.h:7
 RooUnitTest.h:8
 RooUnitTest.h:9
 RooUnitTest.h:10
 RooUnitTest.h:11
 RooUnitTest.h:12
 RooUnitTest.h:13
 RooUnitTest.h:14
 RooUnitTest.h:15
 RooUnitTest.h:16
 RooUnitTest.h:17
 RooUnitTest.h:18
 RooUnitTest.h:19
 RooUnitTest.h:20
 RooUnitTest.h:21
 RooUnitTest.h:22
 RooUnitTest.h:23
 RooUnitTest.h:24
 RooUnitTest.h:25
 RooUnitTest.h:26
 RooUnitTest.h:27
 RooUnitTest.h:28
 RooUnitTest.h:29
 RooUnitTest.h:30
 RooUnitTest.h:31
 RooUnitTest.h:32
 RooUnitTest.h:33
 RooUnitTest.h:34
 RooUnitTest.h:35
 RooUnitTest.h:36
 RooUnitTest.h:37
 RooUnitTest.h:38
 RooUnitTest.h:39
 RooUnitTest.h:40
 RooUnitTest.h:41
 RooUnitTest.h:42
 RooUnitTest.h:43
 RooUnitTest.h:44
 RooUnitTest.h:45
 RooUnitTest.h:46
 RooUnitTest.h:47
 RooUnitTest.h:48
 RooUnitTest.h:49
 RooUnitTest.h:50
 RooUnitTest.h:51
 RooUnitTest.h:52
 RooUnitTest.h:53
 RooUnitTest.h:54
 RooUnitTest.h:55
 RooUnitTest.h:56
 RooUnitTest.h:57
 RooUnitTest.h:58
 RooUnitTest.h:59
 RooUnitTest.h:60
 RooUnitTest.h:61
 RooUnitTest.h:62
 RooUnitTest.h:63
 RooUnitTest.h:64
 RooUnitTest.h:65
 RooUnitTest.h:66
 RooUnitTest.h:67
 RooUnitTest.h:68
 RooUnitTest.h:69
 RooUnitTest.h:70
 RooUnitTest.h:71
 RooUnitTest.h:72
 RooUnitTest.h:73
 RooUnitTest.h:74
 RooUnitTest.h:75
 RooUnitTest.h:76
 RooUnitTest.h:77
 RooUnitTest.h:78
 RooUnitTest.h:79
 RooUnitTest.h:80
 RooUnitTest.h:81
 RooUnitTest.h:82
 RooUnitTest.h:83
 RooUnitTest.h:84
 RooUnitTest.h:85
 RooUnitTest.h:86
 RooUnitTest.h:87