// @(#)root/roostats:$Id$
// Author: Kyle Cranmer, Sven Kreiss   23/05/10
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOSTATS_HypoTestCalculatorGeneric
#define ROOSTATS_HypoTestCalculatorGeneric


#ifndef ROOT_Rtypes
#include "Rtypes.h" // necessary for TNamed
#endif

#ifndef ROOSTATS_HypoTestCalculator
#include "RooStats/HypoTestCalculator.h"
#endif

#ifndef ROOSTATS_ModelConfig
#include "RooStats/ModelConfig.h"
#endif

#ifndef ROOSTATS_TestStatistic
#include "RooStats/TestStatistic.h"
#endif

#ifndef ROOSTATS_TestStatSampler
#include "RooStats/TestStatSampler.h"
#endif

#ifndef ROOSTATS_SamplingDistribution
#include "RooStats/SamplingDistribution.h"
#endif

#ifndef ROOSTATS_HypoTestResult
#include "RooStats/HypoTestResult.h"
#endif

namespace RooStats {

   class HypoTestCalculatorGeneric : public HypoTestCalculator {

   public:
      HypoTestCalculatorGeneric(
                        const RooAbsData &data,
                        const ModelConfig &altModel,
                        const ModelConfig &nullModel,
                        TestStatSampler* sampler=0
      );


      ~HypoTestCalculatorGeneric();


   public:

      /// inherited methods from HypoTestCalculator interface
      virtual HypoTestResult* GetHypoTest() const;

      // set the model for the null hypothesis (only B)
      virtual void SetNullModel(const ModelConfig &nullModel) { fNullModel = &nullModel; }
      const RooAbsData * GetData(void) const { return fData; }
      const ModelConfig* GetNullModel(void) const { return fNullModel; }
      virtual const RooArgSet* GetFitInfo() const { return NULL; }
      // set the model for the alternate hypothesis  (S+B)
      virtual void SetAlternateModel(const ModelConfig &altModel) { fAltModel = &altModel; }
      const ModelConfig* GetAlternateModel(void) const { return fAltModel; }
      // Set the DataSet
      virtual void SetData(RooAbsData &data) { fData = &data; }

      // Returns instance of TestStatSampler. Use to change properties of
      // TestStatSampler, e.g. GetTestStatSampler.SetTestSize(Double_t size);
      TestStatSampler* GetTestStatSampler(void) const { return fTestStatSampler; }

      // set this for re-using always the same toys for alternate hypothesis in 
      // case of calls at dofferent null parameter points
      // This is useful to get more stable bands when running the HypoTest inversion
      void UseSameAltToys(); 
      

   protected:
      // should return zero (to be used later for conditional flow)
      virtual int CheckHook(void) const { return 0; }
      virtual int PreNullHook(RooArgSet* /*parameterPoint*/, double /*obsTestStat*/) const { return 0; }
      virtual int PreAltHook(RooArgSet* /*parameterPoint*/, double /*obsTestStat*/) const { return 0; }
      virtual void PreHook() const { }
      virtual void PostHook() const { }

   protected:
      const ModelConfig *fAltModel;
      const ModelConfig *fNullModel;
      const RooAbsData *fData;
      TestStatSampler *fTestStatSampler;
      TestStatSampler *fDefaultSampler;
      TestStatistic *fDefaultTestStat;

      unsigned int fAltToysSeed;   // to have same toys for alternate 

   private:
      void SetupSampler(const ModelConfig& model) const;
      void SetAdaptiveLimits(Double_t obsTestStat, Bool_t forNull) const;
      SamplingDistribution* GenerateSamplingDistribution(
         ModelConfig *thisModel,
         double obsTestStat,
         RooAbsPdf *impDens=NULL,
         const RooArgSet *impSnapshot=NULL
      ) const;


   protected:
   ClassDef(HypoTestCalculatorGeneric,2)
};
}

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