CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AsymptoticNew.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <RooStats/ModelConfig.h>
3 #include <RooStats/HypoTestInverter.h>
4 #include <RooStats/HypoTestInverterResult.h>
5 #include "RooStats/AsymptoticCalculator.h"
6 #include "../interface/AsymptoticNew.h"
7 #include "../interface/Combine.h"
8 #include "../interface/CloseCoutSentry.h"
9 #include "../interface/RooFitGlobalKillSentry.h"
10 #include "../interface/ProfiledLikelihoodRatioTestStatExt.h"
11 #include "../interface/utils.h"
12 
13 using namespace RooStats;
14 
15 std::string AsymptoticNew::what_ = "both";
16 bool AsymptoticNew::qtilde_ = true;
18 double AsymptoticNew::minrscan_ = 0.;
19 double AsymptoticNew::maxrscan_ = 20.;
20 
22 LimitAlgo("AsymptoticNew specific options"){
23  options_.add_options()
24  ("run", boost::program_options::value<std::string>(&what_)->default_value(what_), "What to run: both (default), observed, expected.")
25  ("nPoints", boost::program_options::value<int>(&nscanpoints_)->default_value(nscanpoints_), "Number of points in scan for CLs")
26  ("qtilde", boost::program_options::value<bool>(&qtilde_)->default_value(qtilde_), "Allow only non-negative signal strengths (default is true).")
27  ("scanMin", boost::program_options::value<double>(&minrscan_)->default_value(minrscan_), "Minimum value for scan in r.")
28  ("scanMax", boost::program_options::value<double>(&maxrscan_)->default_value(maxrscan_), "Maximum value for scan in r.")
29  ;
30 }
31 
32 void AsymptoticNew::applyOptions(const boost::program_options::variables_map &vm) {
33  if (what_ != "observed" && what_ != "expected" && what_ != "both")
34  throw std::invalid_argument("Asymptotic: option 'run' can only be 'observed', 'expected' or 'both' (the default)");
35 
36 }
37 
39  what_ = "observed";
40  nscanpoints_ = 20;
41  qtilde_ = true;
42  minrscan_=0.;
43  maxrscan_=20.;
44 }
45 
46 bool AsymptoticNew::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
48  if (verbose > 0) std::cout << "Will compute " << what_ << " limit(s) " << std::endl;
49 
50  std::vector<std::pair<float,float> > expected;
51  expected = runLimit(w, mc_s, mc_b, data, limit, limitErr, hint);
52 
53  if (verbose >= 0) {
54  const char *rname = mc_s->GetParametersOfInterest()->first()->GetName();
55  std::cout << "\n -- AsymptoticNew -- " << "\n";
56  if (what_ != "expected") {
57  printf("Observed Limit: %s < %6.4f\n", rname, limit);
58  }
59  for (std::vector<std::pair<float,float> >::const_iterator it = expected.begin(), ed = expected.end(); it != ed; ++it) {
60  printf("Expected %4.1f%%: %s < %6.4f\n", it->first*100, rname, it->second);
61  }
62  std::cout << std::endl;
63  }
64 
65  return true;
66 }
67 
68 std::vector<std::pair<float,float> > AsymptoticNew::runLimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint) {
69 
70  RooRealVar *poi = (RooRealVar*)mc_s->GetParametersOfInterest()->first();
71  mc_s->SetSnapshot(*poi);
72  double oldval = poi->getVal();
73  poi->setVal(0); mc_b->SetSnapshot(*poi);
74  poi->setVal(oldval);
75 
76  // Set up asymptotic calculator
77  AsymptoticCalculator * ac = new RooStats::AsymptoticCalculator(data, *mc_b, *mc_s);
78  AsymptoticCalculator::SetPrintLevel(verbose>2);
79  ac->SetOneSided(true);
80  ac->SetQTilde(qtilde_);
81  HypoTestInverter calc(*ac);
82  calc.SetVerbose(verbose>2);
83  calc.UseCLs(true);
84 
85  calc.SetFixedScan(nscanpoints_,minrscan_,maxrscan_);
86  RooStats::HypoTestInverterResult * r = calc.GetInterval();
87 
88  // Expected Median + bands
89  // bands will be based on Z-values
90  std::vector<std::pair<float,float> > expected;
91  const double quantiles[5] = { 0.025, 0.16, 0.50, 0.84, 0.975 };
92  const double zvals[5] = { -2, -1, 0, 1, 2 };
93 
94  for (int iq = 0; iq < 5; ++iq) {
95  limit = r->GetExpectedUpperLimit(zvals[iq]);
96  limitErr = 0;
97  Combine::commitPoint(true, quantiles[iq]);
98  expected.push_back(std::pair<float,float>(quantiles[iq], limit));
99  }
100 
101 
102  // Observed Limit
103  if (what_!="expected") {
104  limit = r->UpperLimit();
105  } else {
106  limit = 0 ;
107  }
108 
109  return expected;
110 
111 }
#define DEBUG
static const int WARNING
static int nscanpoints_
Definition: AsymptoticNew.h:28
static double minrscan_
Definition: AsymptoticNew.h:30
static void commitPoint(bool expected, float quantile)
Save a point into the output tree. Usually if expected = false, quantile should be set to -1 (except ...
Definition: Combine.cc:557
static bool qtilde_
Definition: AsymptoticNew.h:29
static std::string what_
Definition: AsymptoticNew.h:26
virtual void applyOptions(const boost::program_options::variables_map &vm)
static double maxrscan_
Definition: AsymptoticNew.h:30
std::vector< std::pair< float, float > > runLimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint)
virtual bool run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats::ModelConfig *mc_b, RooAbsData &data, double &limit, double &limitErr, const double *hint)
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:32
T w() const
virtual void applyDefaultOptions()