00001
00002
00003
00004
00005
00006
00007
00008
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;
00039 typedef map<Int_t, AcceptanceCriteria> LookupTable;
00040
00041 public:
00042 SamplingSummaryLookup() {}
00043 virtual ~SamplingSummaryLookup() {}
00044
00045 void Add(Double_t cl, Double_t leftside){
00046
00047 AcceptanceCriteria tmp(cl, leftside);
00048
00049
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
00058 AcceptanceCriteria tmp(cl, leftside);
00059
00060 Double_t tolerance = 1E-6;
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;
00068 }
00069
00070
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;
00095
00096 protected:
00097 ClassDef(SamplingSummaryLookup,1)
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;
00118 Double_t fLowerLimit;
00119 Double_t fUpperLimit;
00120
00121 protected:
00122 ClassDef(AcceptanceRegion,1)
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();
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;
00152 TRef fSamplingDistribution;
00153 map<Int_t, AcceptanceRegion> fAcceptanceRegions;
00154
00155 protected:
00156 ClassDef(SamplingSummary,1)
00157
00158 };
00159
00160
00161 class ConfidenceBelt : public TNamed {
00162
00163 private:
00164 SamplingSummaryLookup fSamplingSummaryLookup;
00165 vector<SamplingSummary> fSamplingSummaries;
00166 RooAbsData* fParameterPoints;
00167
00168
00169 public:
00170
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
00179 void AddAcceptanceRegion(RooArgSet&, AcceptanceRegion region, Double_t cl=-1., Double_t leftside=-1.);
00180
00181
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
00190
00191
00192
00193
00194 virtual RooArgSet* GetParameters() const;
00195
00196
00197 Bool_t CheckParameters(RooArgSet&) const ;
00198
00199 protected:
00200 ClassDef(ConfidenceBelt,1)
00201
00202 };
00203 }
00204
00205 #endif