ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
workspace_generator.hpp
Go to the documentation of this file.
1 #ifndef H_WORKSPACE_GENERATOR
2 #define H_WORKSPACE_GENERATOR
3 
4 #include <ostream>
5 #include <set>
6 #include <string>
7 #include <utility>
8 #include <random>
9 
10 #include "RooWorkspace.h"
11 
12 #include "cut.hpp"
13 #include "block.hpp"
14 #include "process.hpp"
15 #include "yield_key.hpp"
16 #include "gamma_params.hpp"
17 #include "block_yields.hpp"
18 #include "yield_manager.hpp"
19 #include "free_systematic.hpp"
20 
22 public:
23  WorkspaceGenerator(const Cut &baseline,
24  const std::set<Block> &blocks,
25  const std::set<Process> &backgrounds,
26  const Process &signal,
27  const Process &data,
28  const std::string &systematics_file = "",
29  const bool use_r4 = true,
30  const double sig_strength = 0.,
31  const double sig_xsec_f = 1.);
32 
34 
35  void WriteToFile(const std::string &file_name);
36 
37  double GetLuminosity() const;
38  WorkspaceGenerator & SetLuminosity(double luminosity);
39 
40  bool GetDoSystematics() const;
42 
43  bool GetDoDilepton() const;
44  WorkspaceGenerator & SetDoDilepton(bool do_systematics);
45 
46  PrintLevel GetPrintLevel() const;
48 
49  bool GetKappaCorrected() const;
50  WorkspaceGenerator & SetKappaCorrected(bool do_kappa_correction);
51 
52  double GetRMax() const;
54 
55  bool UseGausApprox() const;
56  WorkspaceGenerator & UseGausApprox(bool use_gaus_approx);
57 
58  GammaParams GetYield(const YieldKey &key) const;
59  GammaParams GetYield(const Bin &bin,
60  const Process &process,
61  const Cut &cut) const;
62  GammaParams GetYield(const Bin &bin,
63  const Process &process) const;
64 
65  size_t AddToys(size_t num_toys = 0);
66 
67  const Process & GetInjectionModel() const;
68  WorkspaceGenerator & SetInjectionModel(const Process &injection);
69  bool GetDefaultInjectionModel() const;
71 
72  friend std::ostream & operator<<(std::ostream& stream, const WorkspaceGenerator &wg);
73 
74 private:
76  std::set<Process> backgrounds_;
80  std::set<Block> blocks_;
81  std::map<std::string, double> obs_vals_;
82  std::map<std::string, std::poisson_distribution<> > obs_gens_;
83  std::string systematics_file_;
84  bool use_r4_;
86  double rmax_;
87  RooWorkspace w_;
89  std::set<FreeSystematic> free_systematics_;
90  double luminosity_;
95  size_t num_toys_;
97  mutable bool w_is_valid_;
98 
100  static std::mt19937_64 prng_;
101  static std::poisson_distribution<> dist_;
102 
103  static std::mt19937_64 InitializePRNG();
104  static int GetPoisson(double rate);
105 
106  void SetupToys(const RooArgSet &obs);
107  void GenerateToys(RooArgSet &obs);
108  void ResetToys(RooArgSet &obs);
109  void UpdateWorkspace();
110  void AddPOI();
111  void ReadSystematicsFile();
112  static void CleanLine(std::string &line);
113  void AddDileptonSystematic();
114  bool NeedsDileptonBin(const Bin &bin) const;
115  void MakeDileptonBin(const Bin &bin, Bin &dilep_bin, Cut &dilep_cut) const;
117  void AddSystematicGenerator(const std::string &name);
118  void AddData(const Block &block);
119  void AddBackgroundFractions(const Block &block);
120  void AddABCDParameters(const Block &block);
121  void AddRawBackgroundPredictions(const Block &block);
122  void AddKappas(const Block &block);
123  void AddMCYields(const Block &block);
124  void AddMCPdfs(const Block &block);
125  void AddMCProcessSums(const Block &block);
126  void AddMCRowSums(const Block &block);
127  void AddMCColSums(const Block &block);
128  void AddMCTotal(const Block &block);
129  void AddMCPrediction(const Block &block);
130  void AddMCKappa(const Block &block);
131  void AddFullBackgroundPredictions(const Block &block);
132  void AddSignalPredictions(const Block &block);
133  void AddPdfs(const Block &block);
134  void AddDebug(const Block &block);
135  void AddDummyNuisance();
136  void AddFullPdf();
137  void AddParameterSets();
138  void DefineParameterSet(const std::string &cat_name,
139  const std::set<std::string> &var_names);
140  void AddModels();
141  void AddPoisson(const std::string &pdf_name,
142  const std::string &n_name,
143  const std::string &mu_name,
144  bool allow_approx);
145  void PrintComparison(std::ostream &stream, const Bin &bin,
146  const Process &process, const Block &block) const;
147 };
148 
149 #endif
WorkspaceGenerator & SetLuminosity(double luminosity)
void SetupToys(const RooArgSet &obs)
std::set< std::string > observables_
void AddFullBackgroundPredictions(const Block &block)
WorkspaceGenerator(const Cut &baseline, const std::set< Block > &blocks, const std::set< Process > &backgrounds, const Process &signal, const Process &data, const std::string &systematics_file="", const bool use_r4=true, const double sig_strength=0., const double sig_xsec_f=1.)
Definition: bin.hpp:12
WorkspaceGenerator & SetRMax(double rmax)
std::set< std::string > poi_
void AddRawBackgroundPredictions(const Block &block)
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
void AddMCTotal(const Block &block)
std::set< std::string > nuisances_
WorkspaceGenerator & SetInjectionModel(const Process &injection)
void MakeDileptonBin(const Bin &bin, Bin &dilep_bin, Cut &dilep_cut) const
Definition: cut.hpp:8
void AddMCRowSums(const Block &block)
static void CleanLine(std::string &line)
bool GetDefaultInjectionModel() const
bool GetDoSystematics() const
friend std::ostream & operator<<(std::ostream &stream, const WorkspaceGenerator &wg)
std::map< std::string, std::poisson_distribution<> > obs_gens_
static std::mt19937_64 prng_
void AddKappas(const Block &block)
void AddMCPrediction(const Block &block)
void AddMCKappa(const Block &block)
std::map< std::string, double > obs_vals_
std::tuple< Bin, Process, Cut > YieldKey
Definition: yield_key.hpp:11
WorkspaceGenerator & SetKappaCorrected(bool do_kappa_correction)
void AddSignalPredictions(const Block &block)
void AddSystematicGenerator(const std::string &name)
std::set< std::string > systematics_
WorkspaceGenerator & SetDoDilepton(bool do_systematics)
void AddABCDParameters(const Block &block)
void AddMCColSums(const Block &block)
void WriteToFile(const std::string &file_name)
void AddMCYields(const Block &block)
int rmax
Definition: change_r.py:20
bool NeedsDileptonBin(const Bin &bin) const
static int GetPoisson(double rate)
Definition: block.hpp:12
std::set< std::string > glob_observables_
void DefineParameterSet(const std::string &cat_name, const std::set< std::string > &var_names)
static std::poisson_distribution dist_
static YieldManager yields_
std::set< Block > blocks_
std::set< FreeSystematic > free_systematics_
void AddPdfs(const Block &block)
void GenerateToys(RooArgSet &obs)
GammaParams GetYield(const YieldKey &key) const
const Process & GetInjectionModel() const
void PrintComparison(std::ostream &stream, const Bin &bin, const Process &process, const Block &block) const
void ResetToys(RooArgSet &obs)
void AddData(const Block &block)
void AddMCPdfs(const Block &block)
std::set< Process > backgrounds_
PrintLevel GetPrintLevel() const
WorkspaceGenerator & SetDefaultInjectionModel()
void AddMCProcessSums(const Block &block)
void AddBackgroundFractions(const Block &block)
WorkspaceGenerator & SetPrintLevel(PrintLevel print_level)
bool GetKappaCorrected() const
void AddDebug(const Block &block)
double GetLuminosity() const
static std::mt19937_64 InitializePRNG()
size_t AddToys(size_t num_toys=0)
void AddPoisson(const std::string &pdf_name, const std::string &n_name, const std::string &mu_name, bool allow_approx)