Go to the documentation of this file.00001 #include <stdexcept>
00002 #include "../interface/BayesianFlatPrior.h"
00003 #include "RooRealVar.h"
00004 #include "RooArgSet.h"
00005 #include "RooUniform.h"
00006 #include "RooWorkspace.h"
00007 #include "RooPlot.h"
00008 #include "TCanvas.h"
00009 #include "../interface/Combine.h"
00010 #include "RooStats/BayesianCalculator.h"
00011 #include "RooStats/SimpleInterval.h"
00012 #include "RooStats/ModelConfig.h"
00013
00014 #include <stdexcept>
00015 #include <iostream>
00016
00017 using namespace RooStats;
00018
00019 int BayesianFlatPrior::maxDim_ = 4;
00020
00021 BayesianFlatPrior::BayesianFlatPrior() :
00022 LimitAlgo("BayesianSimple specific options")
00023 {
00024 options_.add_options()
00025 ("maxDim", boost::program_options::value<int>(&maxDim_)->default_value(maxDim_), "Maximum number of dimensions to try doing the integration")
00026 ;
00027 }
00028
00029 bool BayesianFlatPrior::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
00030 RooArgSet poi(*mc_s->GetParametersOfInterest());
00031
00032 int dim = poi.getSize();
00033 if (withSystematics) dim += mc_s->GetNuisanceParameters()->getSize();
00034 if (dim >= maxDim_) {
00035 std::cerr << "ERROR: Your model has more parameters than the maximum allowed in the BayesianSimple method. \n" <<
00036 " N(params) = " << dim << ", maxDim = " << maxDim_ << "\n" <<
00037 " Please use MarkovChainMC or BayesianToyMC method to compute Bayesian limits instead of BayesianSimple.\n" <<
00038 " If you really want to run BayesianSimple, change the value of the 'maxDim' option, \n"
00039 " but note that it's really not supposed to work for N(params) above 5 or so " << std::endl;
00040 throw std::logic_error("Too many parameters for BayesianSimple method. Use MarkovChainMC or BayesianToyMC method to compute Bayesian limits instead.");
00041 }
00042
00043 RooRealVar *r = dynamic_cast<RooRealVar *>(poi.first());
00044 double rMax = r->getMax();
00045 std::auto_ptr<RooStats::ModelConfig> mc_noNuis(0);
00046 if (!withSystematics && mc_s->GetNuisanceParameters() != 0) {
00047 mc_noNuis.reset(new RooStats::ModelConfig(w));
00048 mc_noNuis->SetPdf(*mc_s->GetPdf());
00049 mc_noNuis->SetObservables(*mc_s->GetObservables());
00050 mc_noNuis->SetParametersOfInterest(*mc_s->GetParametersOfInterest());
00051 mc_noNuis->SetPriorPdf(*mc_s->GetPriorPdf());
00052 mc_s = mc_noNuis.get();
00053 }
00054 for (;;) {
00055 BayesianCalculator bcalc(data, *mc_s);
00056 bcalc.SetLeftSideTailFraction(0);
00057 bcalc.SetConfidenceLevel(cl);
00058 std::auto_ptr<SimpleInterval> bcInterval(bcalc.GetInterval());
00059 if (bcInterval.get() == 0) return false;
00060 limit = bcInterval->UpperLimit();
00061 if (limit >= 0.5*r->getMax()) {
00062 std::cout << "Limit " << r->GetName() << " < " << limit << "; " << r->GetName() << " max < " << r->getMax() << std::endl;
00063 if (r->getMax()/rMax > 20) return false;
00064 r->setMax(r->getMax()*2);
00065 continue;
00066 }
00067 if (verbose > -1) {
00068 std::cout << "\n -- BayesianSimple -- " << "\n";
00069 std::cout << "Limit: " << r->GetName() << " < " << limit << " @ " << cl * 100 << "% CL" << std::endl;
00070 }
00071 if (verbose > 200) {
00072
00073 TCanvas c1("c1", "c1");
00074 std::auto_ptr<RooPlot> bcPlot(bcalc.GetPosteriorPlot(true, 0.1));
00075 bcPlot->Draw();
00076 c1.Print("plots/bc_plot.png");
00077 }
00078 break;
00079 }
00080 return true;
00081 }