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 std::string
const& new_name) {
139 for(
unsigned i = 0; i<systs_.size(); ++i){
140 if(systs_[i]->name()==old_name){
141 systs_[i]->set_name(new_name);
148 std::string
const& rule,
149 std::string
const& syst_rule) {
150 std::vector<HistMapping> mapping(1);
151 mapping[0].process =
"*";
152 mapping[0].category =
"*";
153 mapping[0].file = std::make_shared<TFile>(file.c_str());
154 mapping[0].pattern = rule;
155 mapping[0].syst_pattern = syst_rule;
159 for (
unsigned i = 0; i < obs_.size(); ++i) {
160 if (obs_[i]->shape() || obs_[i]->data())
continue;
161 LoadShapes(obs_[i].get(), mapping);
163 for (
unsigned i = 0; i < procs_.size(); ++i) {
164 if (procs_[i]->shape() || procs_[i]->pdf())
continue;
165 LoadShapes(procs_[i].get(), mapping);
167 if (syst_rule ==
"")
return;
168 for (
unsigned i = 0; i < systs_.size(); ++i) {
169 if (systs_[i]->type() !=
"shape" && systs_[i]->type() !=
"shapeN2" &&
170 systs_[i]->type() !=
"shapeU")
172 LoadShapes(systs_[i].get(), mapping);
178 SetupWorkspace(ws, can_rename);
182 std::string
const& ws_name,
183 std::string
const& rule,
184 std::string norm_rule) {
185 std::vector<HistMapping> mapping(1);
186 mapping[0].process =
"*";
187 mapping[0].category =
"*";
188 mapping[0].pattern = ws_name+
":"+rule;
189 if (norm_rule !=
"") mapping[0].syst_pattern = ws_name +
":" + norm_rule;
190 if (!wspaces_.count(ws_name))
return;
191 mapping[0].ws = wspaces_.at(ws_name);
192 for (
unsigned i = 0; i < procs_.size(); ++i) {
193 if (!procs_[i]->pdf()) {
194 target.LoadShapes(procs_[i].get(), mapping);
200 std::string
const &rule) {
201 std::vector<HistMapping> mapping(1);
202 mapping[0].process =
"*";
203 mapping[0].category =
"*";
204 mapping[0].pattern = ws_name+
":"+rule;
205 if (!wspaces_.count(ws_name))
return;
206 mapping[0].ws = wspaces_.at(ws_name);
207 for (
unsigned i = 0; i < obs_.size(); ++i) {
208 if (!obs_[i]->
data()) {
209 LoadShapes(obs_[i].get(), mapping);
229 if (!params_.count(name)) {
230 auto param = std::make_shared<Parameter>(
Parameter());
231 param->set_name(name);
232 params_.insert({name, param});
237 double merge_threshold) {
246 obs_.push_back(std::make_shared<ch::Observation>(obs));
250 procs_.push_back(std::make_shared<ch::Process>(proc));
254 systs_.push_back(std::make_shared<ch::Systematic>(sys));