// ConfidenceBelt is a concrete implementation of the ConfInterval interface.
// It implements simple general purpose interval of arbitrary dimensions and shape.
// It does not assume the interval is connected.
// It uses either a RooDataSet (eg. a list of parameter points in the interval) or
// a RooDataHist (eg. a Histogram-like object for small regions of the parameter space) to
// store the interval.
// END_HTML
#ifndef RooStats_ConfidenceBelt
#include "RooStats/ConfidenceBelt.h"
#endif
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooStats/RooStatsUtils.h"
ClassImp(RooStats::ConfidenceBelt) ;
using namespace RooStats;
using namespace std;
ConfidenceBelt::ConfidenceBelt() :
TNamed(), fParameterPoints(0)
{
}
ConfidenceBelt::ConfidenceBelt(const char* name) :
TNamed(name,name), fParameterPoints(0)
{
}
ConfidenceBelt::ConfidenceBelt(const char* name, const char* title) :
TNamed(name,title), fParameterPoints(0)
{
}
ConfidenceBelt::ConfidenceBelt(const char* name, RooAbsData& data) :
TNamed(name,name), fParameterPoints((RooAbsData*)data.Clone("PointsToTestForBelt"))
{
}
ConfidenceBelt::ConfidenceBelt(const char* name, const char* title, RooAbsData& data) :
TNamed(name,title), fParameterPoints((RooAbsData*)data.Clone("PointsToTestForBelt"))
{
}
ConfidenceBelt::~ConfidenceBelt()
{
}
Double_t ConfidenceBelt::GetAcceptanceRegionMin(RooArgSet& parameterPoint, Double_t cl, Double_t leftside) {
if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
AcceptanceRegion * region = GetAcceptanceRegion(parameterPoint, cl,leftside);
return (region) ? region->GetLowerLimit() : TMath::QuietNaN();
}
Double_t ConfidenceBelt::GetAcceptanceRegionMax(RooArgSet& parameterPoint, Double_t cl, Double_t leftside) {
if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
AcceptanceRegion * region = GetAcceptanceRegion(parameterPoint, cl,leftside);
return (region) ? region->GetUpperLimit() : TMath::QuietNaN();
}
vector<Double_t> ConfidenceBelt::ConfidenceLevels() const {
vector<Double_t> levels;
return levels;
}
void ConfidenceBelt::AddAcceptanceRegion(RooArgSet& parameterPoint, Int_t dsIndex,
Double_t lower, Double_t upper,
Double_t cl, Double_t leftside){
if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
RooDataSet* tree = dynamic_cast<RooDataSet*>( fParameterPoints );
RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );
if( !this->CheckParameters(parameterPoint) )
std::cout << "problem with parameters" << std::endl;
Int_t luIndex = fSamplingSummaryLookup.GetLookupIndex(cl, leftside);
if(luIndex <0 ) {
fSamplingSummaryLookup.Add(cl,leftside);
luIndex = fSamplingSummaryLookup.GetLookupIndex(cl, leftside);
cout << "lookup index = " << luIndex << endl;
}
AcceptanceRegion* thisRegion = new AcceptanceRegion(luIndex, lower, upper);
if( hist ) {
int index = hist->getIndex(parameterPoint);
if((Int_t)fSamplingSummaries.size() <= index) {
fSamplingSummaries.reserve( hist->numEntries() );
fSamplingSummaries.resize( hist->numEntries() );
}
fSamplingSummaries.at(index) = *thisRegion;
}
else if( tree ){
int index = dsIndex;
if((Int_t)fSamplingSummaries.size() <= index){
fSamplingSummaries.reserve( tree->numEntries() );
fSamplingSummaries.resize( tree->numEntries() );
}
fSamplingSummaries.at( index ) = *thisRegion;
}
}
void ConfidenceBelt::AddAcceptanceRegion(RooArgSet& parameterPoint, AcceptanceRegion region,
Double_t cl, Double_t leftside){
if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
RooDataSet* tree = dynamic_cast<RooDataSet*>( fParameterPoints );
RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );
if( !this->CheckParameters(parameterPoint) )
std::cout << "problem with parameters" << std::endl;
if( hist ) {
int index = hist->getIndex(parameterPoint);
if((Int_t)fSamplingSummaries.size() < index) fSamplingSummaries.reserve( hist->numEntries() );
fSamplingSummaries.at(index) = region;
}
else if( tree ){
tree->add( parameterPoint );
int index = tree->numEntries() - 1;
if((Int_t)fSamplingSummaries.size() < index) fSamplingSummaries.reserve( tree->numEntries() );
fSamplingSummaries.at( index ) = region;
}
}
AcceptanceRegion* ConfidenceBelt::GetAcceptanceRegion(RooArgSet ¶meterPoint, Double_t cl, Double_t leftside)
{
if(cl>0 || leftside > 0) cout <<"using default cl, leftside for now" <<endl;
RooDataSet* tree = dynamic_cast<RooDataSet*>( fParameterPoints );
RooDataHist* hist = dynamic_cast<RooDataHist*>( fParameterPoints );
if( !this->CheckParameters(parameterPoint) ){
std::cout << "problem with parameters" << std::endl;
return 0;
}
if( hist ) {
int index = hist->getIndex(parameterPoint);
return &(fSamplingSummaries.at(index).GetAcceptanceRegion());
}
else if( tree ){
Int_t index = 0;
const RooArgSet* thisPoint = 0;
for(index=0; index<tree->numEntries(); ++index){
thisPoint = tree->get(index);
bool samePoint = true;
TIter it = parameterPoint.createIterator();
RooRealVar *myarg;
while ( samePoint && (myarg = (RooRealVar *)it.Next())) {
if(myarg->getVal() != thisPoint->getRealValue(myarg->GetName()))
samePoint = false;
}
if(samePoint)
break;
}
return &(fSamplingSummaries.at(index).GetAcceptanceRegion());
}
else {
std::cout << "dataset is not initialized properly" << std::endl;
}
return 0;
}
RooArgSet* ConfidenceBelt::GetParameters() const
{
return new RooArgSet(*(fParameterPoints->get()));
}
Bool_t ConfidenceBelt::CheckParameters(RooArgSet ¶meterPoint) const
{
if (parameterPoint.getSize() != fParameterPoints->get()->getSize() ) {
std::cout << "size is wrong, parameters don't match" << std::endl;
return false;
}
if ( ! parameterPoint.equals( *(fParameterPoints->get() ) ) ) {
std::cout << "size is ok, but parameters don't match" << std::endl;
return false;
}
return true;
}