2 #include "../interface/FeldmanCousins.h"
3 #include "../interface/Combine.h"
4 #include <RooRealVar.h>
7 #include <RooWorkspace.h>
8 #include <RooDataHist.h>
9 #include <RooStats/ModelConfig.h>
10 #include <RooStats/FeldmanCousins.h>
11 #include <RooStats/PointSetInterval.h>
18 LimitAlgo(
"FeldmanCousins specific options") {
20 (
"rAbsAcc", boost::program_options::value<float>(&
rAbsAccuracy_)->default_value(
rAbsAccuracy_),
"Absolute accuracy on r to reach to terminate the scan")
21 (
"rRelAcc", boost::program_options::value<float>(&
rRelAccuracy_)->default_value(
rRelAccuracy_),
"Relative accuracy on r to reach to terminate the scan")
22 (
"toysFactor", boost::program_options::value<float>(&
toysFactor_)->default_value(
toysFactor_),
"Increase the toys per point by this factor w.r.t. the minimum from adaptive sampling")
30 bool FeldmanCousins::run(RooWorkspace *
w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &
data,
double &
limit,
double &limitErr,
const double *hint) {
31 RooArgSet poi(*mc_s->GetParametersOfInterest());
32 RooRealVar *
r =
dynamic_cast<RooRealVar *
>(poi.first());
34 if ((hint != 0) && (*hint > r->getMin())) {
35 r->setMax(std::min<double>(3*(*hint), r->getMax()));
38 RooStats::ModelConfig modelConfig(*mc_s);
39 modelConfig.SetSnapshot(poi);
41 RooStats::FeldmanCousins
fc(data, modelConfig);
42 fc.FluctuateNumDataEntries(mc_s->GetPdf()->canBeExtended());
43 fc.UseAdaptiveSampling(
true);
44 fc.SetConfidenceLevel(
cl);
49 if (
verbose > 1)
std::cout <<
"scan in range [" << r->getMin() <<
", " << r->getMax() <<
"]" << std::endl;
50 std::auto_ptr<RooStats::PointSetInterval> fcInterval((RooStats::PointSetInterval *)fc.GetInterval());
51 if (fcInterval.get() == 0)
return false;
52 if (
verbose > 1) fcInterval->GetParameterPoints()->Print(
"V");
53 RooDataHist* parameterScan = (RooDataHist*) fc.GetPointsToScan();
56 for(
int i=0;
i<parameterScan->numEntries(); ++
i){
57 const RooArgSet * tmpPoint = parameterScan->get(
i);
58 if (!fcInterval->IsInInterval(*tmpPoint)) found =
i;
62 for(
int i=0;
i<parameterScan->numEntries(); ++
i){
63 const RooArgSet * tmpPoint = parameterScan->get(
i);
64 bool inside = fcInterval->IsInInterval(*tmpPoint);
65 if (inside) found =
i;
66 else if (found != -1)
break;
69 if (
verbose)
std::cout <<
"Points are either all inside or all outside the bound." << std::endl;
73 double fcBefore = (found > -1 ? parameterScan->get(found)->getRealValue(r->GetName()) : r->getMin());
74 double fcAfter = (found < parameterScan->numEntries()-1 ?
75 parameterScan->get(found+1)->getRealValue(r->GetName()) : r->getMax());
76 limit = 0.5*(fcAfter+fcBefore);
77 limitErr = 0.5*(fcAfter-fcBefore);
78 if (
verbose > 0)
std::cout <<
" would be " << r->GetName() <<
" < " << limit <<
" +/- "<<limitErr << std::endl;
79 r->setMin(
std::max(r->getMin(), limit-3*limitErr));
80 r->setMax(
std::min(r->getMax(), limit+3*limitErr));
87 std::cout <<
"\n -- FeldmanCousins++ -- \n";
88 std::cout <<
"Limit: " << r->GetName() << (
lowerLimit_ ?
"> " :
"< ") << limit <<
" +/- " << limitErr <<
" @ " <<
cl * 100 <<
"% CL" << std::endl;
const T & max(const T &a, const T &b)
virtual bool run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint)
virtual void applyOptions(const boost::program_options::variables_map &vm)
static float rRelAccuracy_
char data[epos_bytes_allocation]
static float rAbsAccuracy_
boost::program_options::options_description options_