ConfidenceBelt.h

Go to the documentation of this file.
00001 // @(#)root/roostats:$Id: ConfidenceBelt.h 36024 2010-10-01 16:03:30Z moneta $
00002 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
00003 /*************************************************************************
00004  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 
00011 #ifndef RooStats_ConfidenceBelt
00012 #define RooStats_ConfidenceBelt
00013 
00014 #ifndef ROO_ARG_SET
00015 #include "RooArgSet.h"
00016 #endif
00017 #ifndef ROO_TREE_DATA
00018 #include "RooAbsData.h"
00019 #endif
00020 #ifndef RooStats_ConfInterval
00021 #include "RooStats/ConfInterval.h"
00022 #endif
00023 
00024 #include "RooStats/SamplingDistribution.h"
00025 
00026 #include "TRef.h"
00027 
00028 #include <vector>
00029 #include <map>
00030 
00031 using namespace std;
00032 
00033 namespace RooStats {
00034 
00035   ///////////////////////////
00036   class SamplingSummaryLookup : public TObject {
00037 
00038     typedef pair<Double_t, Double_t> AcceptanceCriteria; // defined by Confidence level, leftside tail probability
00039     typedef map<Int_t, AcceptanceCriteria> LookupTable; // map ( Index, ( CL, leftside tail prob) )
00040 
00041   public:
00042     SamplingSummaryLookup() {}
00043     virtual ~SamplingSummaryLookup() {}
00044 
00045     void Add(Double_t cl, Double_t leftside){
00046       // add cl,leftside pair to lookup table
00047       AcceptanceCriteria tmp(cl, leftside);
00048 
00049       // should check to see if this is already in the map
00050       if(GetLookupIndex(cl,leftside) >=0 ){
00051         cout<< "SamplingSummaryLookup::Add, already in lookup table" << endl;
00052       } else
00053         fLookupTable[fLookupTable.size()]= tmp;
00054     }
00055 
00056     Int_t GetLookupIndex(Double_t cl, Double_t leftside){
00057       // get index for cl,leftside pair
00058       AcceptanceCriteria tmp(cl, leftside);
00059 
00060       Double_t tolerance = 1E-6; // some small number to protect floating point comparison.  What is better way?
00061       LookupTable::iterator it = fLookupTable.begin();
00062       Int_t index = -1;
00063       for(; it!= fLookupTable.end(); ++it) {
00064         index++;
00065         if( TMath::Abs( (*it).second.first - cl ) < tolerance &&
00066             TMath::Abs( (*it).second.second - leftside ) < tolerance )
00067           break; // exit loop, found 
00068       }
00069 
00070       // check that it was found
00071       if(index == (Int_t)fLookupTable.size())
00072         index = -1;
00073 
00074       return index;
00075     }
00076 
00077   Double_t GetConfidenceLevel(Int_t index){
00078     if(index<0 || index>(Int_t)fLookupTable.size()) {
00079       cout << "SamplingSummaryLookup::GetConfidenceLevel, index not in lookup table" << endl;
00080       return -1;
00081     }
00082     return fLookupTable[index].first;
00083   }
00084 
00085   Double_t GetLeftSideTailFraction(Int_t index){
00086     if(index<0 || index>(Int_t)fLookupTable.size()) {
00087       cout << "SamplingSummaryLookup::GetLeftSideTailFraction, index not in lookup table" << endl;
00088       return -1;
00089     }
00090     return fLookupTable[index].second;
00091   }
00092 
00093   private:
00094     LookupTable fLookupTable; // map ( Index, ( CL, leftside tail prob) )
00095 
00096   protected:
00097     ClassDef(SamplingSummaryLookup,1)  // A simple class used by ConfidenceBelt
00098   };
00099 
00100 
00101   ///////////////////////////
00102   class AcceptanceRegion : public TObject{
00103   public:
00104      AcceptanceRegion() : fLookupIndex(0), fLowerLimit(0), fUpperLimit(0) {}
00105     virtual ~AcceptanceRegion() {}
00106 
00107     AcceptanceRegion(Int_t lu, Double_t ll, Double_t ul){
00108       fLookupIndex = lu;
00109       fLowerLimit = ll;
00110       fUpperLimit = ul;
00111     }
00112     Int_t GetLookupIndex(){return fLookupIndex;}
00113     Double_t GetLowerLimit(){return fLowerLimit;}
00114     Double_t GetUpperLimit(){return fUpperLimit;}
00115 
00116   private:
00117     Int_t fLookupIndex; // want a small footprint reference to the RooArgSet for particular parameter point
00118     Double_t fLowerLimit;  // lower limit on test statistic
00119     Double_t fUpperLimit;  // upper limit on test statistic
00120 
00121   protected:
00122     ClassDef(AcceptanceRegion,1)  // A simple class for acceptance regions used for ConfidenceBelt
00123 
00124   };
00125 
00126 
00127   ///////////////////////////
00128   class SamplingSummary : public TObject {
00129   public:
00130      SamplingSummary() : fParameterPointIndex(0) {}
00131     virtual ~SamplingSummary() {}
00132      SamplingSummary(AcceptanceRegion& ar) : fParameterPointIndex(0) {
00133       AddAcceptanceRegion(ar);
00134     }
00135     Int_t GetParameterPointIndex(){return fParameterPointIndex;}
00136     SamplingDistribution* GetSamplingDistribution(){
00137       return (SamplingDistribution*) fSamplingDistribution.GetObject(); // dereference TRef
00138     }
00139     AcceptanceRegion& GetAcceptanceRegion(Int_t index=0){return fAcceptanceRegions[index];}
00140 
00141     void AddAcceptanceRegion(AcceptanceRegion& ar){
00142       Int_t index =  ar.GetLookupIndex();
00143       if( fAcceptanceRegions.count(index) !=0) {
00144         std::cout << "SamplingSummary::AddAcceptanceRegion, need to implement merging protocol" << std::endl;
00145       } else {
00146         fAcceptanceRegions[index]=ar;
00147       }
00148     }
00149     
00150   private:
00151     Int_t fParameterPointIndex; // want a small footprint reference to the RooArgSet for particular parameter point
00152     TRef fSamplingDistribution; // persistent pointer to a SamplingDistribution
00153     map<Int_t, AcceptanceRegion> fAcceptanceRegions;
00154 
00155   protected:
00156     ClassDef(SamplingSummary,1)  // A summary of acceptance regions for confidence belt
00157 
00158   };
00159 
00160   /////////////////////////////////////////
00161  class ConfidenceBelt : public TNamed {
00162 
00163   private:
00164     SamplingSummaryLookup fSamplingSummaryLookup;
00165     vector<SamplingSummary> fSamplingSummaries; // composite of several AcceptanceRegions
00166     RooAbsData* fParameterPoints;  // either a histogram (RooDataHist) or a tree (RooDataSet)
00167 
00168 
00169   public:
00170     // constructors,destructors
00171     ConfidenceBelt();
00172     ConfidenceBelt(const char* name);
00173     ConfidenceBelt(const char* name, const char* title);
00174     ConfidenceBelt(const char* name, RooAbsData&);
00175     ConfidenceBelt(const char* name, const char* title, RooAbsData&);
00176     virtual ~ConfidenceBelt();
00177         
00178     // add after creating a region
00179     void AddAcceptanceRegion(RooArgSet&, AcceptanceRegion region, Double_t cl=-1., Double_t leftside=-1.);
00180 
00181     // add without creating a region, more useful for clients
00182     void AddAcceptanceRegion(RooArgSet& point, Int_t dataSetIndex, Double_t lower, Double_t upper, Double_t cl=-1., Double_t leftside=-1.);
00183 
00184     AcceptanceRegion* GetAcceptanceRegion(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
00185     Double_t GetAcceptanceRegionMin(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
00186     Double_t GetAcceptanceRegionMax(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
00187     vector<Double_t> ConfidenceLevels() const ;
00188  
00189     // Method to return lower limit on a given parameter 
00190     //  Double_t LowerLimit(RooRealVar& param) ; // could provide, but misleading?
00191     //      Double_t UpperLimit(RooRealVar& param) ; // could provide, but misleading?
00192     
00193     // do we want it to return list of parameters
00194     virtual RooArgSet* GetParameters() const;
00195 
00196     // check if parameters are correct. (dummy implementation to start)
00197     Bool_t CheckParameters(RooArgSet&) const ;
00198     
00199   protected:
00200     ClassDef(ConfidenceBelt,1)  // A confidence belt for the Neyman Construction
00201       
00202   };
00203 }
00204 
00205 #endif

Generated on Tue Jul 5 14:26:21 2011 for ROOT_528-00b_version by  doxygen 1.5.1