#ifndef RooStats_ConfidenceBelt
#define RooStats_ConfidenceBelt
#ifndef ROO_ARG_SET
#include "RooArgSet.h"
#endif
#ifndef ROO_TREE_DATA
#include "RooAbsData.h"
#endif
#ifndef RooStats_ConfInterval
#include "RooStats/ConfInterval.h"
#endif
#include "RooStats/SamplingDistribution.h"
#include "TRef.h"
#include <vector>
#include <map>
namespace RooStats {
class SamplingSummaryLookup : public TObject {
typedef std::pair<Double_t, Double_t> AcceptanceCriteria;
typedef std::map<Int_t, AcceptanceCriteria> LookupTable;
public:
SamplingSummaryLookup() {}
virtual ~SamplingSummaryLookup() {}
void Add(Double_t cl, Double_t leftside){
AcceptanceCriteria tmp(cl, leftside);
if(GetLookupIndex(cl,leftside) >=0 ){
std::cout<< "SamplingSummaryLookup::Add, already in lookup table" << std::endl;
} else
fLookupTable[fLookupTable.size()]= tmp;
}
Int_t GetLookupIndex(Double_t cl, Double_t leftside){
AcceptanceCriteria tmp(cl, leftside);
Double_t tolerance = 1E-6;
LookupTable::iterator it = fLookupTable.begin();
Int_t index = -1;
for(; it!= fLookupTable.end(); ++it) {
index++;
if( TMath::Abs( (*it).second.first - cl ) < tolerance &&
TMath::Abs( (*it).second.second - leftside ) < tolerance )
break;
}
if(index == (Int_t)fLookupTable.size())
index = -1;
return index;
}
Double_t GetConfidenceLevel(Int_t index){
if(index<0 || index>(Int_t)fLookupTable.size()) {
std::cout << "SamplingSummaryLookup::GetConfidenceLevel, index not in lookup table" << std::endl;
return -1;
}
return fLookupTable[index].first;
}
Double_t GetLeftSideTailFraction(Int_t index){
if(index<0 || index>(Int_t)fLookupTable.size()) {
std::cout << "SamplingSummaryLookup::GetLeftSideTailFraction, index not in lookup table" << std::endl;
return -1;
}
return fLookupTable[index].second;
}
private:
LookupTable fLookupTable;
protected:
ClassDef(SamplingSummaryLookup,1)
};
class AcceptanceRegion : public TObject{
public:
AcceptanceRegion() : fLookupIndex(0), fLowerLimit(0), fUpperLimit(0) {}
virtual ~AcceptanceRegion() {}
AcceptanceRegion(Int_t lu, Double_t ll, Double_t ul){
fLookupIndex = lu;
fLowerLimit = ll;
fUpperLimit = ul;
}
Int_t GetLookupIndex(){return fLookupIndex;}
Double_t GetLowerLimit(){return fLowerLimit;}
Double_t GetUpperLimit(){return fUpperLimit;}
private:
Int_t fLookupIndex;
Double_t fLowerLimit;
Double_t fUpperLimit;
protected:
ClassDef(AcceptanceRegion,1)
};
class SamplingSummary : public TObject {
public:
SamplingSummary() : fParameterPointIndex(0) {}
virtual ~SamplingSummary() {}
SamplingSummary(AcceptanceRegion& ar) : fParameterPointIndex(0) {
AddAcceptanceRegion(ar);
}
Int_t GetParameterPointIndex(){return fParameterPointIndex;}
SamplingDistribution* GetSamplingDistribution(){
return (SamplingDistribution*) fSamplingDistribution.GetObject();
}
AcceptanceRegion& GetAcceptanceRegion(Int_t index=0){return fAcceptanceRegions[index];}
void AddAcceptanceRegion(AcceptanceRegion& ar){
Int_t index = ar.GetLookupIndex();
if( fAcceptanceRegions.count(index) !=0) {
std::cout << "SamplingSummary::AddAcceptanceRegion, need to implement merging protocol" << std::endl;
} else {
fAcceptanceRegions[index]=ar;
}
}
private:
Int_t fParameterPointIndex;
TRef fSamplingDistribution;
std::map<Int_t, AcceptanceRegion> fAcceptanceRegions;
protected:
ClassDef(SamplingSummary,1)
};
class ConfidenceBelt : public TNamed {
private:
SamplingSummaryLookup fSamplingSummaryLookup;
std::vector<SamplingSummary> fSamplingSummaries;
RooAbsData* fParameterPoints;
public:
ConfidenceBelt();
ConfidenceBelt(const char* name);
ConfidenceBelt(const char* name, const char* title);
ConfidenceBelt(const char* name, RooAbsData&);
ConfidenceBelt(const char* name, const char* title, RooAbsData&);
virtual ~ConfidenceBelt();
void AddAcceptanceRegion(RooArgSet&, AcceptanceRegion region, Double_t cl=-1., Double_t leftside=-1.);
void AddAcceptanceRegion(RooArgSet& point, Int_t dataSetIndex, Double_t lower, Double_t upper, Double_t cl=-1., Double_t leftside=-1.);
AcceptanceRegion* GetAcceptanceRegion(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
Double_t GetAcceptanceRegionMin(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
Double_t GetAcceptanceRegionMax(RooArgSet&, Double_t cl=-1., Double_t leftside=-1.);
std::vector<Double_t> ConfidenceLevels() const ;
virtual RooArgSet* GetParameters() const;
Bool_t CheckParameters(RooArgSet&) const ;
protected:
ClassDef(ConfidenceBelt,1)
};
}
#endif