ROOT logo
// @(#)root/roostats:$Id: MCMCInterval.h 26805 2009-06-17 14:31:02Z kbelasco $
// Authors: Kevin Belasco        17/06/2009
// Authors: Kyle Cranmer         17/06/2009
/*************************************************************************
 * 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_MCMCInterval
#define RooStats_MCMCInterval

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

#ifndef RooStats_ConfInterval
#include "RooStats/ConfInterval.h"
#endif

#ifndef ROO_ARG_SET
#include "RooArgSet.h"
#endif

#include "RooArgList.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "TH1.h"


namespace RooStats {

   class MCMCInterval : public ConfInterval {


   public:
      MCMCInterval();
      MCMCInterval(const char* name);
      MCMCInterval(const char* name, const char* title);
      MCMCInterval(const char* name, const char* title, RooArgSet& parameters,
                   RooDataSet& chain);

      enum {DEFAULT_NUM_BINS = 50};

      virtual ~MCMCInterval()
      {
         delete[] fAxes;
         delete fHist;
         delete fData;
         delete[] fNumBins;
      }
        
      // determine whether this point is in the confidence interval
      virtual Bool_t IsInInterval(RooArgSet& point);

      // set the desired confidence level (see GetActualConfidenceLevel())
      // Note: calling this function triggers the algorithm that determines
      // the interval, so call this after initializing all other aspects
      // of this IntervalCalculator
      // Also, calling this function again with a different confidence level
      // retriggers the calculation of the interval
      virtual void SetConfidenceLevel(Double_t cl);

      // get the desired confidence level (see GetActualConfidenceLevel())
      virtual Double_t ConfidenceLevel() const {return fConfidenceLevel;}
 
      // do we want it to return list of parameters
      virtual RooArgSet* GetParameters() const;

      // get the cutoff bin height for being considered in the
      // confidence interval
      virtual Double_t GetCutoff() { return fCutoff; }

      // get the actual value of the confidence level for this interval.
      // It is >= the specified confidence level because the interval contains
      // all bins with the cutoff height (or higher), until at least the desired
      // confidence level is reached.
      // Returns (Sum of bin heights in interval) / (Sum of all bin heights)
      virtual Double_t GetActualConfidenceLevel()
      { return fIntervalSum/fHist->GetSumOfWeights(); }

      // whether the specified confidence level is a floor for the actual
      // confidence level (strict), or a ceiling (not strict)
      virtual void SetStrict(Bool_t isStrict) { fIsStrict = isStrict; }

      // check if parameters are correct. (dummy implementation to start)
      Bool_t CheckParameters(RooArgSet& point) const;

      // Set the parameters of interest for this interval
      // and change other internal data members accordingly
      virtual void SetParameters(RooArgSet& parameters);

      // Set which parameters go on which axis.  The first list element
      // goes on the x axis, second (if it exists) on y, third (if it
      // exists) on z.
      virtual void SetAxes(RooArgList& axes);

      // get the lower limit of param in the confidence interval
      // Note that this works better for some distributions (ones with exactly
      // one maximum) than others, and sometimes has little value.
      virtual Double_t LowerLimit(RooRealVar& param);

      // get the upper limit of param in the confidence interval
      // Note that this works better for some distributions (ones with exactly
      // one maximum) than others, and sometimes has little value.
      virtual Double_t UpperLimit(RooRealVar& param);

      // set the number of steps in the chain to discard as burn-in,
      // starting from the first
      virtual void SetNumBurnInSteps(Int_t numBurnInSteps)
      { fNumBurnInSteps = numBurnInSteps; }

      // set the number of bins to use (same for all axes, for now)
      virtual void SetNumBins(Int_t numBins);

      // Get a clone of the histogram of the posterior
      virtual TH1* GetPosteriorHist();

      // Get the markov chain on which this interval is based
      virtual const RooDataSet* GetChain() { return fData; }

   protected:
      // data members
      RooArgSet* fParameters; // parameters of interest for this interval
      RooDataSet* fData; // the markov chain
      TH1* fHist; // histogram generated from data to determine binning
      Double_t fConfidenceLevel; // Requested confidence level (eg. 0.95 for 95% CL)
      Double_t fCutoff; // cutoff bin size to be in interval
      Bool_t fIsStrict; // whether the specified confidence level is a floor
                        // for the actual confidence level (strict), or a 
                        // ceiling (not strict)
      Int_t fDimension; // number of variables
      Int_t fNumBurnInSteps; // number of steps to discard as burn in, starting from the first
      Int_t* fNumBins; // number of bins for each dimension
      Double_t fIntervalSum; // sum of heights of bins in the interval
      RooRealVar** fAxes; // array of pointers to RooRealVars representing
                          // the axes of the histogram
                          // fAxes[0] represents x-axis, [1] y, [2] z
      Int_t fPreferredNumBins; // number of bins client wants

      // functions
      virtual void DetermineInterval();
      virtual void CreateHistogram();

      ClassDef(MCMCInterval,1)  // Concrete implementation of a ConfInterval based on MCMC calculation
      
   };
}

#endif
 MCMCInterval.h:1
 MCMCInterval.h:2
 MCMCInterval.h:3
 MCMCInterval.h:4
 MCMCInterval.h:5
 MCMCInterval.h:6
 MCMCInterval.h:7
 MCMCInterval.h:8
 MCMCInterval.h:9
 MCMCInterval.h:10
 MCMCInterval.h:11
 MCMCInterval.h:12
 MCMCInterval.h:13
 MCMCInterval.h:14
 MCMCInterval.h:15
 MCMCInterval.h:16
 MCMCInterval.h:17
 MCMCInterval.h:18
 MCMCInterval.h:19
 MCMCInterval.h:20
 MCMCInterval.h:21
 MCMCInterval.h:22
 MCMCInterval.h:23
 MCMCInterval.h:24
 MCMCInterval.h:25
 MCMCInterval.h:26
 MCMCInterval.h:27
 MCMCInterval.h:28
 MCMCInterval.h:29
 MCMCInterval.h:30
 MCMCInterval.h:31
 MCMCInterval.h:32
 MCMCInterval.h:33
 MCMCInterval.h:34
 MCMCInterval.h:35
 MCMCInterval.h:36
 MCMCInterval.h:37
 MCMCInterval.h:38
 MCMCInterval.h:39
 MCMCInterval.h:40
 MCMCInterval.h:41
 MCMCInterval.h:42
 MCMCInterval.h:43
 MCMCInterval.h:44
 MCMCInterval.h:45
 MCMCInterval.h:46
 MCMCInterval.h:47
 MCMCInterval.h:48
 MCMCInterval.h:49
 MCMCInterval.h:50
 MCMCInterval.h:51
 MCMCInterval.h:52
 MCMCInterval.h:53
 MCMCInterval.h:54
 MCMCInterval.h:55
 MCMCInterval.h:56
 MCMCInterval.h:57
 MCMCInterval.h:58
 MCMCInterval.h:59
 MCMCInterval.h:60
 MCMCInterval.h:61
 MCMCInterval.h:62
 MCMCInterval.h:63
 MCMCInterval.h:64
 MCMCInterval.h:65
 MCMCInterval.h:66
 MCMCInterval.h:67
 MCMCInterval.h:68
 MCMCInterval.h:69
 MCMCInterval.h:70
 MCMCInterval.h:71
 MCMCInterval.h:72
 MCMCInterval.h:73
 MCMCInterval.h:74
 MCMCInterval.h:75
 MCMCInterval.h:76
 MCMCInterval.h:77
 MCMCInterval.h:78
 MCMCInterval.h:79
 MCMCInterval.h:80
 MCMCInterval.h:81
 MCMCInterval.h:82
 MCMCInterval.h:83
 MCMCInterval.h:84
 MCMCInterval.h:85
 MCMCInterval.h:86
 MCMCInterval.h:87
 MCMCInterval.h:88
 MCMCInterval.h:89
 MCMCInterval.h:90
 MCMCInterval.h:91
 MCMCInterval.h:92
 MCMCInterval.h:93
 MCMCInterval.h:94
 MCMCInterval.h:95
 MCMCInterval.h:96
 MCMCInterval.h:97
 MCMCInterval.h:98
 MCMCInterval.h:99
 MCMCInterval.h:100
 MCMCInterval.h:101
 MCMCInterval.h:102
 MCMCInterval.h:103
 MCMCInterval.h:104
 MCMCInterval.h:105
 MCMCInterval.h:106
 MCMCInterval.h:107
 MCMCInterval.h:108
 MCMCInterval.h:109
 MCMCInterval.h:110
 MCMCInterval.h:111
 MCMCInterval.h:112
 MCMCInterval.h:113
 MCMCInterval.h:114
 MCMCInterval.h:115
 MCMCInterval.h:116
 MCMCInterval.h:117
 MCMCInterval.h:118
 MCMCInterval.h:119
 MCMCInterval.h:120
 MCMCInterval.h:121
 MCMCInterval.h:122
 MCMCInterval.h:123
 MCMCInterval.h:124
 MCMCInterval.h:125
 MCMCInterval.h:126
 MCMCInterval.h:127
 MCMCInterval.h:128
 MCMCInterval.h:129
 MCMCInterval.h:130
 MCMCInterval.h:131
 MCMCInterval.h:132
 MCMCInterval.h:133
 MCMCInterval.h:134
 MCMCInterval.h:135
 MCMCInterval.h:136
 MCMCInterval.h:137
 MCMCInterval.h:138
 MCMCInterval.h:139
 MCMCInterval.h:140
 MCMCInterval.h:141
 MCMCInterval.h:142
 MCMCInterval.h:143
 MCMCInterval.h:144
 MCMCInterval.h:145
 MCMCInterval.h:146
 MCMCInterval.h:147
 MCMCInterval.h:148
 MCMCInterval.h:149
 MCMCInterval.h:150
 MCMCInterval.h:151
 MCMCInterval.h:152