9 #include "TDirectory.h"
21 std::vector<std::string> mass,
22 std::vector<std::string> analysis,
23 std::vector<std::string>
era,
24 std::vector<std::string>
channel,
26 std::vector<unsigned> lengths = {
27 unsigned(
mass.size()),
31 unsigned(
bin.size())};
33 for (
auto const& c : comb) {
34 auto obs = std::make_shared<Observation>();
35 obs->set_mass(
mass[c[0]]);
37 obs->set_era(
era[c[2]]);
38 obs->set_channel(
channel[c[3]]);
39 obs->set_bin_id(
bin[c[4]].first);
40 obs->set_bin(
bin[c[4]].second);
46 std::vector<std::string> mass,
47 std::vector<std::string> analysis,
48 std::vector<std::string>
era,
49 std::vector<std::string>
channel,
50 std::vector<std::string> procs,
53 std::vector<unsigned> lengths = {
54 unsigned(
mass.size()),
58 unsigned(
bin.size())};
60 for (
auto const& c : comb) {
61 for (
unsigned i = 0; i < procs.size(); ++i) {
62 auto proc = std::make_shared<Process>();
63 proc->set_mass(
mass[c[0]]);
65 proc->set_era(
era[c[2]]);
66 proc->set_channel(
channel[c[3]]);
67 proc->set_bin_id(
bin[c[4]].first);
68 proc->set_bin(
bin[c[4]].second);
69 proc->set_process(procs[i]);
70 proc->set_signal(signal);
71 procs_.push_back(proc);
77 std::string
const& name,
78 std::string
const& type,
bool asymm,
79 double val_u,
double val_d,
80 std::string
const& formula,
81 std::string
const& args) {
82 std::string subbed_name = name;
83 boost::replace_all(subbed_name,
"$BINID",
84 boost::lexical_cast<std::string>(proc.
bin_id()));
85 boost::replace_all(subbed_name,
"$BIN", proc.
bin());
86 boost::replace_all(subbed_name,
"$PROCESS", proc.
process());
87 boost::replace_all(subbed_name,
"$MASS", proc.
mass());
88 boost::replace_all(subbed_name,
"$ERA", proc.
era());
89 boost::replace_all(subbed_name,
"$CHANNEL", proc.
channel());
90 boost::replace_all(subbed_name,
"$ANALYSIS", proc.
analysis());
92 for(
const auto it : attrs){
93 boost::replace_all(subbed_name,
"$ATTR("+it.first+
")",proc.
attribute(it.first));
95 auto sys = std::make_shared<Systematic>();
97 sys->set_name(subbed_name);
99 if (type ==
"lnN" || type ==
"lnU") {
100 sys->set_asymm(asymm);
101 sys->set_value_u(val_u);
102 sys->set_value_d(val_d);
104 }
else if (type ==
"shape" || type ==
"shapeN2" || type ==
"shapeU") {
105 sys->set_asymm(
true);
106 sys->set_value_u(1.0);
107 sys->set_value_d(1.0);
108 sys->set_scale(val_u);
110 }
else if (type ==
"rateParam") {
111 sys->set_asymm(
false);
112 if (formula ==
"" && args ==
"") {
113 SetupRateParamVar(subbed_name, val_u);
115 std::string subbed_args = args;
116 boost::replace_all(subbed_args,
"$BINID",
117 boost::lexical_cast<std::string>(proc.
bin_id()));
118 boost::replace_all(subbed_args,
"$BIN", proc.
bin());
119 boost::replace_all(subbed_args,
"$PROCESS", proc.
process());
120 boost::replace_all(subbed_args,
"$MASS", proc.
mass());
121 boost::replace_all(subbed_args,
"$ERA", proc.
era());
122 boost::replace_all(subbed_args,
"$CHANNEL", proc.
channel());
123 boost::replace_all(subbed_args,
"$ANALYSIS", proc.
analysis());
124 for(
const auto it : attrs){
125 boost::replace_all(subbed_args,
"$ATTR("+it.first+
")",proc.
attribute(it.first));
127 SetupRateParamFunc(subbed_name, formula, subbed_args);
130 if (sys->type() ==
"lnU" || sys->type() ==
"shapeU") {
131 params_.at(sys->name())->set_err_d(0.);
132 params_.at(sys->name())->set_err_u(0.);
134 systs_.push_back(sys);
138 double val,
double err) {
139 Parameter * param = SetupRateParamVar(name,val);
143 auto sys = std::make_shared<Systematic>();
145 sys->set_type(
"param");
146 systs_.push_back(sys);
150 std::string
const& new_name) {
151 for(
unsigned i = 0; i<systs_.size(); ++i){
152 if(systs_[i]->name()==old_name){
153 systs_[i]->set_name(new_name);
160 std::string
const& rule,
161 std::string
const& syst_rule) {
162 std::vector<HistMapping> mapping(1);
163 mapping[0].process =
"*";
164 mapping[0].category =
"*";
165 mapping[0].file = std::make_shared<TFile>(file.c_str());
166 mapping[0].pattern = rule;
167 mapping[0].syst_pattern = syst_rule;
171 for (
unsigned i = 0; i < obs_.size(); ++i) {
172 if (obs_[i]->shape() || obs_[i]->
data())
continue;
173 LoadShapes(obs_[i].get(), mapping);
175 for (
unsigned i = 0; i < procs_.size(); ++i) {
176 if (procs_[i]->shape() || procs_[i]->pdf())
continue;
177 LoadShapes(procs_[i].get(), mapping);
179 if (syst_rule ==
"")
return;
180 for (
unsigned i = 0; i < systs_.size(); ++i) {
181 if (systs_[i]->type() !=
"shape" && systs_[i]->type() !=
"shapeN2" &&
182 systs_[i]->type() !=
"shapeU")
184 LoadShapes(systs_[i].get(), mapping);
190 SetupWorkspace(ws, can_rename);
194 std::string
const& ws_name,
195 std::string
const& rule,
196 std::string norm_rule) {
197 std::vector<HistMapping> mapping(1);
198 mapping[0].process =
"*";
199 mapping[0].category =
"*";
200 mapping[0].pattern = ws_name+
":"+rule;
201 if (norm_rule !=
"") mapping[0].syst_pattern = ws_name +
":" + norm_rule;
202 if (!wspaces_.count(ws_name))
return;
203 mapping[0].ws = wspaces_.at(ws_name);
204 for (
unsigned i = 0; i < procs_.size(); ++i) {
205 if (!procs_[i]->pdf()) {
206 target.LoadShapes(procs_[i].get(), mapping);
212 std::string
const &rule) {
213 std::vector<HistMapping> mapping(1);
214 mapping[0].process =
"*";
215 mapping[0].category =
"*";
216 mapping[0].pattern = ws_name+
":"+rule;
217 if (!wspaces_.count(ws_name))
return;
218 mapping[0].ws = wspaces_.at(ws_name);
219 for (
unsigned i = 0; i < obs_.size(); ++i) {
220 if (!obs_[i]->
data()) {
221 LoadShapes(obs_[i].get(), mapping);
241 if (!params_.count(name)) {
242 auto param = std::make_shared<Parameter>(
Parameter());
243 param->set_name(name);
244 params_.insert({name, param});
249 double merge_threshold) {
258 obs_.push_back(std::make_shared<ch::Observation>(obs));
262 procs_.push_back(std::make_shared<ch::Process>(proc));
266 systs_.push_back(std::make_shared<ch::Systematic>(sys));
Merges bin uncertainties and creates bin-by-bin statistical uncertainties.
BinByBinFactory & SetAddThreshold(double val)
Set the fractional bin error threshold for bin-by-bin creation and for participation in the merging a...
BinByBinFactory & SetFixNorm(bool fix)
Whether or not the bin-by-bin systematics are allowed to vary the process normalisation.
void MergeBinErrors(CombineHarvester &cb)
Merges histogram bin errors between processes.
BinByBinFactory & SetVerbosity(unsigned verbosity)
By default this class only produces output on the screen when an error occurs, set to a value greater...
BinByBinFactory & SetMergeThreshold(double val)
The threshold for the merging algorithm.
void AddBinByBin(CombineHarvester &src, CombineHarvester &dest)
Create bin-by-bin shape uncertainties for every process in src, and add these to dest
void AddSystFromProc(Process const &proc, std::string const &name, std::string const &type, bool asymm, double val_u, double val_d, std::string const &formula, std::string const &args)
void AddWorkspace(RooWorkspace const &ws, bool can_rename=false)
void AddProcesses(std::vector< std::string > mass, std::vector< std::string > analysis, std::vector< std::string > era, std::vector< std::string > channel, std::vector< std::string > procs, ch::Categories bin, bool signal)
void AddBinByBin(double threshold, bool fixed_norm, CombineHarvester *other)
Create bin-by-bin uncertainties.
CombineHarvester & mass(std::vector< std::string > const &vec, bool cond=true)
void AddSystVar(std::string const &name, double val, double err)
void CreateParameterIfEmpty(std::string const &name)
void MergeBinErrors(double bbb_threshold, double merge_threshold)
Merge bin errors within a bin.
CombineHarvester & data()
CombineHarvester & analysis(std::vector< std::string > const &vec, bool cond=true)
CombineHarvester & bin(std::vector< std::string > const &vec, bool cond=true)
void InsertProcess(ch::Process const &proc)
void AddObservations(std::vector< std::string > mass, std::vector< std::string > analysis, std::vector< std::string > era, std::vector< std::string > channel, ch::Categories bin)
void InsertSystematic(ch::Systematic const &sys)
void ExtractData(std::string const &ws_name, std::string const &rule)
void InsertObservation(ch::Observation const &obs)
void ExtractShapes(std::string const &file, std::string const &rule, std::string const &syst_rule)
void RenameSystematic(CombineHarvester &target, std::string const &old_name, std::string const &new_name)
Rename a systematic from 'old_name' to 'new_name' and add a parameter 'new_name' to CH instance 'targ...
void ExtractPdfs(CombineHarvester &target, std::string const &ws_name, std::string const &rule, std::string norm_rule="")
virtual std::string const attribute(std::string const &attr_label) const
virtual std::string const & process() const
virtual std::string const & bin() const
virtual int bin_id() const
virtual std::string const & analysis() const
virtual std::string const & era() const
virtual std::string const & mass() const
virtual std::string const & channel() const
virtual std::map< std::string, std::string > const & all_attributes() const
void set_err_u(double const &err_u)
void set_err_d(double const &err_d)
void set_val(double const &val)
void SetProperties(T *first, U const *second)
std::vector< std::vector< unsigned > > GenerateCombinations(std::vector< unsigned > vec)
std::vector< std::pair< int, std::string > > Categories