CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BayesianFlatPrior.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include "../interface/BayesianFlatPrior.h"
3 #include "RooRealVar.h"
4 #include "RooArgSet.h"
5 #include "RooUniform.h"
6 #include "RooWorkspace.h"
7 #include "RooPlot.h"
8 #include "TCanvas.h"
9 #include "../interface/Combine.h"
10 #include "RooStats/BayesianCalculator.h"
11 #include "RooStats/SimpleInterval.h"
12 #include "RooStats/ModelConfig.h"
13 
14 #include <stdexcept>
15 #include <iostream>
16 
17 using namespace RooStats;
18 
20 
22  LimitAlgo("BayesianSimple specific options")
23 {
24  options_.add_options()
25  ("maxDim", boost::program_options::value<int>(&maxDim_)->default_value(maxDim_), "Maximum number of dimensions to try doing the integration")
26  ;
27 }
28 
29 bool BayesianFlatPrior::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
30  RooArgSet poi(*mc_s->GetParametersOfInterest());
31 
32  int dim = poi.getSize();
33  if (withSystematics) dim += mc_s->GetNuisanceParameters()->getSize();
34  if (dim >= maxDim_) {
35  std::cerr << "ERROR: Your model has more parameters than the maximum allowed in the BayesianSimple method. \n" <<
36  " N(params) = " << dim << ", maxDim = " << maxDim_ << "\n" <<
37  " Please use MarkovChainMC or BayesianToyMC method to compute Bayesian limits instead of BayesianSimple.\n" <<
38  " If you really want to run BayesianSimple, change the value of the 'maxDim' option, \n"
39  " but note that it's really not supposed to work for N(params) above 5 or so " << std::endl;
40  throw std::logic_error("Too many parameters for BayesianSimple method. Use MarkovChainMC or BayesianToyMC method to compute Bayesian limits instead.");
41  }
42 
43  RooRealVar *r = dynamic_cast<RooRealVar *>(poi.first());
44  double rMax = r->getMax();
45  std::auto_ptr<RooStats::ModelConfig> mc_noNuis(0);
46  if (!withSystematics && mc_s->GetNuisanceParameters() != 0) {
47  mc_noNuis.reset(new RooStats::ModelConfig(w));
48  mc_noNuis->SetPdf(*mc_s->GetPdf());
49  mc_noNuis->SetObservables(*mc_s->GetObservables());
50  mc_noNuis->SetParametersOfInterest(*mc_s->GetParametersOfInterest());
51  mc_noNuis->SetPriorPdf(*mc_s->GetPriorPdf());
52  mc_s = mc_noNuis.get();
53  }
54  for (;;) {
55  BayesianCalculator bcalc(data, *mc_s);
56  bcalc.SetLeftSideTailFraction(0);
57  bcalc.SetConfidenceLevel(cl);
58  std::auto_ptr<SimpleInterval> bcInterval(bcalc.GetInterval());
59  if (bcInterval.get() == 0) return false;
60  limit = bcInterval->UpperLimit();
61  if (limit >= 0.5*r->getMax()) {
62  std::cout << "Limit " << r->GetName() << " < " << limit << "; " << r->GetName() << " max < " << r->getMax() << std::endl;
63  if (r->getMax()/rMax > 20) return false;
64  r->setMax(r->getMax()*2);
65  continue;
66  }
67  if (verbose > -1) {
68  std::cout << "\n -- BayesianSimple -- " << "\n";
69  std::cout << "Limit: " << r->GetName() << " < " << limit << " @ " << cl * 100 << "% CL" << std::endl;
70  }
71  if (verbose > 200) {
72  // FIXME!!!!!
73  TCanvas c1("c1", "c1");
74  std::auto_ptr<RooPlot> bcPlot(bcalc.GetPosteriorPlot(true, 0.1));
75  bcPlot->Draw();
76  c1.Print("plots/bc_plot.png");
77  }
78  break;
79  }
80  return true;
81 }
bool withSystematics
Definition: Combine.cc:68
float cl
Definition: Combine.cc:71
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
boost::program_options::options_description options_
Definition: LimitAlgo.h:31
T w() const
virtual bool run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint)