Skip to content

Commit 52ac317

Browse files
committed
Merge pull request #640 from ajgilbert/ch-june-15
CombineHarvester June updates
2 parents 6e6cb33 + aea666d commit 52ac317

File tree

15 files changed

+1032
-183
lines changed

15 files changed

+1032
-183
lines changed

CombineHarvester/CombinePdfs/test/MorphingMSSM.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ int main() {
227227
signal_types["ggH"], {mt_cats[0]}, true);
228228
cb.AddProcesses(masses, {"htt"}, {"8TeV"}, {"mt"},
229229
signal_types["bbH"], {mt_cats[1]}, true);
230+
cb.AddProcesses(masses, {"htt"}, {"8TeV"}, {"mt"},
231+
signal_types["bbH"], {mt_cats[0]}, true);
232+
cb.AddProcesses(masses, {"htt"}, {"8TeV"}, {"mt"},
233+
signal_types["ggH"], {mt_cats[1]}, true);
230234
cout << " done\n";
231235

232236
cout << "Adding systematic uncertainties...";
@@ -251,18 +255,15 @@ int main() {
251255
cout << " done\n";
252256

253257
cout << "Scaling signal process rates for acceptance...\n";
254-
map<string, TGraph> xs;
255258
for (string e : {"8TeV"}) {
256259
for (string p : {"ggH", "bbH"}) {
257-
ch::ParseTable(&xs, "input/xsecs_brs/mssm_" + p + "_" + e + "_accept.txt",
258-
{p + "_" + e});
259-
}
260-
}
261-
for (string const& e : {"8TeV"}) {
262-
for (string const& p : {"ggH", "bbH"}) {
263260
cout << "Scaling for process " << p << " and era " << e << "\n";
261+
auto gr = ch::TGraphFromTable(
262+
"input/xsecs_brs/mssm_" + p + "_" + e + "_accept.txt", "mPhi",
263+
"accept");
264264
cb.cp().process(signal_types[p]).era({e}).ForEachProc([&](ch::Process *proc) {
265-
ch::ScaleProcessRate(proc, &xs, p+"_"+e, "");
265+
double m = boost::lexical_cast<double>(proc->mass());
266+
proc->set_rate(proc->rate() * gr.Eval(m));
266267
});
267268
}
268269
}
@@ -336,6 +337,11 @@ int main() {
336337
// bbA.Write("bbA");
337338
// bbX.Write("bbX");
338339
cb.cp().mass({"*"}).WriteDatacard(folder + "/htt_mt_mssm.txt", output);
340+
auto bins = cb.bin_set();
341+
for (auto b : bins) {
342+
cb.cp().bin({b}).mass({"*"}).WriteDatacard(
343+
folder + "/" + b + ".txt", output);
344+
}
339345
output.Close();
340346
}
341347

CombineHarvester/CombinePdfs/test/ParametricMSSM.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,15 @@ int main() {
8282
std::cout << " done\n";
8383

8484
std::cout << "Scaling signal process rates for acceptance...\n";
85-
map<string, TGraph> xs;
86-
for (std::string const& e : {"7TeV", "8TeV"}) {
87-
for (std::string const& p : {"ggH", "bbH"}) {
88-
ch::ParseTable(&xs, "data/xsecs_brs/mssm_" + p + "_" + e + "_accept.txt",
89-
{p + "_" + e});
90-
}
91-
}
92-
for (std::string const& e : {"7TeV", "8TeV"}) {
93-
for (std::string const& p : {"ggH", "bbH"}) {
85+
for (string e : {"8TeV"}) {
86+
for (string p : {"ggH", "bbH"}) {
9487
std::cout << "Scaling for process " << p << " and era " << e << "\n";
88+
auto gr = ch::TGraphFromTable(
89+
"input/xsecs_brs/mssm_" + p + "_" + e + "_accept.txt", "mPhi",
90+
"accept");
9591
cb.cp().process({p}).era({e}).ForEachProc([&](ch::Process *proc) {
96-
ch::ScaleProcessRate(proc, &xs, p+"_"+e, "");
92+
double m = boost::lexical_cast<double>(proc->mass());
93+
proc->set_rate(proc->rate() * gr.Eval(m));
9794
});
9895
}
9996
}

CombineHarvester/CombinePdfs/test/Test.cpp renamed to CombineHarvester/CombinePdfs/test/SMLegacyMorphing.cpp

Lines changed: 68 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include "CombineTools/interface/Utilities.h"
1111
#include "CombineTools/interface/HttSystematics.h"
1212
#include "CombinePdfs/interface/MorphFunctions.h"
13+
#include "CombineTools/interface/BinByBin.h"
1314

1415
using namespace std;
1516

1617
int main() {
1718
ch::CombineHarvester cb;
18-
1919
// cb.SetVerbosity(1);
2020

2121
typedef vector<pair<int, string>> Categories;
@@ -103,7 +103,7 @@ int main() {
103103
{0, "tauTau_1jet_high_mediumhiggs"}, {1, "tauTau_1jet_high_highhiggs"},
104104
{2, "tauTau_vbf"}};
105105

106-
vector<string> masses = ch::MassesFromRange("110-145:5");
106+
vector<string> masses = ch::ValsFromRange("110:145|5");
107107

108108
cout << ">> Creating processes and observations...\n";
109109
for (string era : {"7TeV", "8TeV"}) {
@@ -145,117 +145,67 @@ int main() {
145145
cout << ">> Scaling signal process rates...\n";
146146
map<string, TGraph> xs;
147147
// Get the table of H->tau tau BRs vs mass
148-
ch::ParseTable(&xs, "input/xsecs_brs/htt_YR3.txt", {"htt"});
148+
xs["htt"] = ch::TGraphFromTable("input/xsecs_brs/htt_YR3.txt", "mH", "br");
149149
for (string const& e : {"7TeV", "8TeV"}) {
150150
for (string const& p : sig_procs) {
151151
// Get the table of xsecs vs mass for process "p" and era "e":
152-
ch::ParseTable(&xs, "data/xsecs_brs/"+p+"_"+e+"_YR3.txt", {p+"_"+e});
152+
xs[p+"_"+e] = ch::TGraphFromTable("input/xsecs_brs/"+p+"_"+e+"_YR3.txt", "mH", "xsec");
153153
cout << ">>>> Scaling for process " << p << " and era " << e << "\n";
154154
cb.cp().process({p}).era({e}).ForEachProc([&](ch::Process *proc) {
155-
ch::ScaleProcessRate(proc, &xs, p+"_"+e, "htt");
155+
double m = boost::lexical_cast<double>(proc->mass());
156+
proc->set_rate(proc->rate() * xs[p+"_"+e].Eval(m) * xs["htt"].Eval(m));
156157
});
157158
}
158159
}
159-
ch::ParseTable(&xs, "input/xsecs_brs/hww_over_htt.txt", {"hww_over_htt"});
160+
xs["hww_over_htt"] = ch::TGraphFromTable("input/xsecs_brs/hww_over_htt.txt", "mH", "ratio");
160161
for (string const& e : {"7TeV", "8TeV"}) {
161162
for (string const& p : {"ggH", "qqH"}) {
162163
cb.cp().channel({"em"}).process({p+"_hww125"}).era({e})
163164
.ForEachProc([&](ch::Process *proc) {
164-
ch::ScaleProcessRate(proc, &xs, p+"_"+e, "htt", "125");
165-
ch::ScaleProcessRate(proc, &xs, "hww_over_htt", "", "125");
165+
proc->set_rate(proc->rate() * xs[p+"_"+e].Eval(125.) * xs["htt"].Eval(125.));
166+
proc->set_rate(proc->rate() * xs["hww_over_htt"].Eval(125.));
166167
});
167168
}
168169
}
169170

170-
cout << ">> Merging bin errors...\n";
171-
ch::CombineHarvester cb_et = move(cb.cp().channel({"et"}));
172-
for (string era : {"7TeV", "8TeV"}) {
173-
cb_et.cp().era({era}).bin_id({1, 2}).process({"ZL", "ZJ", "QCD", "W"})
174-
.MergeBinErrors(0.1, 0.5);
175-
cb_et.cp().era({era}).bin_id({3, 5}).process({"W"})
176-
.MergeBinErrors(0.1, 0.5);
177-
}
178-
cb_et.cp().era({"7TeV"}).bin_id({6}).process({"ZL", "ZJ", "W", "ZTT"})
179-
.MergeBinErrors(0.1, 0.5);
180-
cb_et.cp().era({"8TeV"}).bin_id({7}).process({"ZL", "ZJ", "W", "ZTT"})
181-
.MergeBinErrors(0.1, 0.5);
182-
cb_et.cp().era({"8TeV"}).bin_id({6}).process({"ZL", "ZJ", "W"})
183-
.MergeBinErrors(0.1, 0.5);
184-
185-
ch::CombineHarvester cb_mt = move(cb.cp().channel({"mt"}));
186-
for (string era : {"7TeV", "8TeV"}) {
187-
cb_mt.cp().era({era}).bin_id({1, 2, 3, 4}).process({"W", "QCD"})
188-
.MergeBinErrors(0.1, 0.5);
189-
}
190-
cb_mt.cp().era({"7TeV"}).bin_id({5}).process({"W"})
191-
.MergeBinErrors(0.1, 0.5);
192-
cb_mt.cp().era({"7TeV"}).bin_id({6}).process({"W", "ZTT"})
193-
.MergeBinErrors(0.1, 0.5);
194-
cb_mt.cp().era({"8TeV"}).bin_id({5, 6}).process({"W"})
195-
.MergeBinErrors(0.1, 0.5);
196-
cb_mt.cp().era({"8TeV"}).bin_id({7}).process({"W", "ZTT"})
197-
.MergeBinErrors(0.1, 0.5);
198-
199-
ch::CombineHarvester cb_em = move(cb.cp().channel({"em"}));
200-
for (string era : {"7TeV", "8TeV"}) {
201-
cb_em.cp().era({era}).bin_id({1, 3}).process({"Fakes"})
202-
.MergeBinErrors(0.1, 0.5);
203-
}
204-
cb_em.cp().era({"7TeV"}).bin_id({4}).process({"Fakes", "EWK", "Ztt"})
205-
.MergeBinErrors(0.1, 0.5);
206-
cb_em.cp().era({"8TeV"}).bin_id({5}).process({"Fakes", "EWK", "Ztt"})
207-
.MergeBinErrors(0.1, 0.5);
208-
cb_em.cp().era({"8TeV"}).bin_id({4}).process({"Fakes", "EWK"})
209-
.MergeBinErrors(0.1, 0.5);
210-
211-
ch::CombineHarvester cb_ee_mm = move(cb.cp().channel({"ee", "mm"}));
212-
for (string era : {"7TeV", "8TeV"}) {
213-
cb_ee_mm.cp().era({era}).bin_id({1, 3, 4})
214-
.process({"ZTT", "ZEE", "ZMM", "TTJ"})
215-
.MergeBinErrors(0.0, 0.5);
216-
}
217-
218-
ch::CombineHarvester cb_tt = move(cb.cp().channel({"tt"}));
219-
cb_tt.cp().bin_id({0, 1, 2}).era({"8TeV"}).process({"ZTT", "QCD"})
220-
.MergeBinErrors(0.1, 0.5);
221-
222-
cout << ">> Generating bbb uncertainties...\n";
223-
cb_mt.cp().bin_id({0, 1, 2, 3, 4}).process({"W", "QCD"})
224-
.AddBinByBin(0.1, true, &cb);
225-
cb_mt.cp().era({"7TeV"}).bin_id({5}).process({"W"})
226-
.AddBinByBin(0.1, true, &cb);
227-
cb_mt.cp().era({"7TeV"}).bin_id({6}).process({"W", "ZTT"})
228-
.AddBinByBin(0.1, true, &cb);
229-
cb_mt.cp().era({"8TeV"}).bin_id({5, 6}).process({"W"})
230-
.AddBinByBin(0.1, true, &cb);
231-
cb_mt.cp().era({"8TeV"}).bin_id({7}).process({"W", "ZTT"})
232-
.AddBinByBin(0.1, true, &cb);
233-
234-
cb_et.cp().bin_id({1, 2}).process({"ZL", "ZJ", "QCD", "W"})
235-
.AddBinByBin(0.1, true, &cb);
236-
cb_et.cp().bin_id({3, 5}).process({"W"})
237-
.AddBinByBin(0.1, true, &cb);
238-
cb_et.cp().era({"7TeV"}).bin_id({6}).process({"ZL", "ZJ", "W", "ZTT"})
239-
.AddBinByBin(0.1, true, &cb);
240-
cb_et.cp().era({"8TeV"}).bin_id({7}).process({"ZL", "ZJ", "W", "ZTT"})
241-
.AddBinByBin(0.1, true, &cb);
242-
cb_et.cp().era({"8TeV"}).bin_id({6}).process({"ZL", "ZJ", "W"})
243-
.AddBinByBin(0.1, true, &cb);
244-
245-
cb_em.cp().bin_id({1, 3}).process({"Fakes"})
246-
.AddBinByBin(0.1, true, &cb);
247-
cb_em.cp().era({"7TeV"}).bin_id({4}).process({"Fakes", "EWK", "Ztt"})
248-
.AddBinByBin(0.1, true, &cb);
249-
cb_em.cp().era({"8TeV"}).bin_id({5}).process({"Fakes", "EWK", "Ztt"})
250-
.AddBinByBin(0.1, true, &cb);
251-
cb_em.cp().era({"8TeV"}).bin_id({4}).process({"Fakes", "EWK"})
252-
.AddBinByBin(0.1, true, &cb);
253-
254-
cb_ee_mm.cp().bin_id({1, 3, 4}).process({"ZTT", "ZEE", "ZMM", "TTJ"})
255-
.AddBinByBin(0.0, true, &cb);
256-
257-
cb_tt.cp().bin_id({0, 1, 2}).era({"8TeV"}).process({"QCD", "ZTT"})
258-
.AddBinByBin(0.1, true, &cb);
171+
cout << ">> Merging bin errors and generating bbb uncertainties...\n";
172+
173+
auto bbb = ch::BinByBinFactory()
174+
.SetAddThreshold(0.1)
175+
.SetMergeThreshold(0.5)
176+
.SetFixNorm(true);
177+
178+
ch::CombineHarvester cb_et = cb.cp().channel({"et"});
179+
bbb.MergeAndAdd(cb_et.cp().era({"7TeV"}).bin_id({1, 2}).process({"ZL", "ZJ", "QCD", "W"}), cb);
180+
bbb.MergeAndAdd(cb_et.cp().era({"7TeV"}).bin_id({3, 5}).process({"W"}), cb);
181+
bbb.MergeAndAdd(cb_et.cp().era({"8TeV"}).bin_id({1, 2}).process({"ZL", "ZJ", "QCD", "W"}), cb);
182+
bbb.MergeAndAdd(cb_et.cp().era({"8TeV"}).bin_id({3, 5}).process({"W"}), cb);
183+
bbb.MergeAndAdd(cb_et.cp().era({"7TeV"}).bin_id({6}).process({"ZL", "ZJ", "W", "ZTT"}), cb);
184+
bbb.MergeAndAdd(cb_et.cp().era({"8TeV"}).bin_id({6}).process({"ZL", "ZJ", "W"}), cb);
185+
bbb.MergeAndAdd(cb_et.cp().era({"8TeV"}).bin_id({7}).process({"ZL", "ZJ", "W", "ZTT"}), cb);
186+
187+
ch::CombineHarvester cb_mt = cb.cp().channel({"mt"});
188+
bbb.MergeAndAdd(cb_mt.cp().era({"7TeV"}).bin_id({1, 2, 3, 4}).process({"W", "QCD"}), cb);
189+
bbb.MergeAndAdd(cb_mt.cp().era({"8TeV"}).bin_id({1, 2, 3, 4}).process({"W", "QCD"}), cb);
190+
bbb.MergeAndAdd(cb_mt.cp().era({"7TeV"}).bin_id({5}).process({"W"}), cb);
191+
bbb.MergeAndAdd(cb_mt.cp().era({"7TeV"}).bin_id({6}).process({"W", "ZTT"}), cb);
192+
bbb.MergeAndAdd(cb_mt.cp().era({"8TeV"}).bin_id({5, 6}).process({"W"}), cb);
193+
bbb.MergeAndAdd(cb_mt.cp().era({"8TeV"}).bin_id({7}).process({"W", "ZTT"}), cb);
194+
195+
ch::CombineHarvester cb_em = cb.cp().channel({"em"});
196+
bbb.MergeAndAdd(cb_em.cp().era({"7TeV"}).bin_id({1, 3}).process({"Fakes"}), cb);
197+
bbb.MergeAndAdd(cb_em.cp().era({"8TeV"}).bin_id({1, 3}).process({"Fakes"}), cb);
198+
bbb.MergeAndAdd(cb_em.cp().era({"7TeV"}).bin_id({4}).process({"Fakes", "EWK", "Ztt"}), cb);
199+
bbb.MergeAndAdd(cb_em.cp().era({"8TeV"}).bin_id({5}).process({"Fakes", "EWK", "Ztt"}), cb);
200+
bbb.MergeAndAdd(cb_em.cp().era({"8TeV"}).bin_id({4}).process({"Fakes", "EWK"}), cb);
201+
202+
ch::CombineHarvester cb_tt = cb.cp().channel({"tt"});
203+
bbb.MergeAndAdd(cb_tt.cp().era({"8TeV"}).bin_id({0, 1, 2}).process({"ZTT", "QCD"}), cb);
204+
205+
bbb.SetAddThreshold(0.); // ee and mm use a different threshold
206+
ch::CombineHarvester cb_ll = cb.cp().channel({"ee", "mm"});
207+
bbb.MergeAndAdd(cb_ll.cp().era({"7TeV"}).bin_id({1, 3, 4}).process({"ZTT", "ZEE", "ZMM", "TTJ"}), cb);
208+
bbb.MergeAndAdd(cb_ll.cp().era({"8TeV"}).bin_id({1, 3, 4}).process({"ZTT", "ZEE", "ZMM", "TTJ"}), cb);
259209

260210
cout << ">> Setting standardised bin names...\n";
261211
ch::SetStandardBinNames(cb);
@@ -303,30 +253,30 @@ int main() {
303253
string folder = "output/sm_cards_morphed";
304254
boost::filesystem::create_directories(folder);
305255

256+
TFile output((folder + "/htt.input.root").c_str(),
257+
"RECREATE");
306258
for (string chn : chns) {
307-
TFile output((folder + "/htt_" + chn + ".input.root").c_str(),
308-
"RECREATE");
309-
// auto bins = cb.cp().channel({chn}).bin_set();
310-
// for (auto b : bins) {
311-
// for (auto m : masses) {
312-
// cout << ">> Writing datacard for bin: " << b << " and mass: " << m
313-
// << "\r" << flush;
314-
// cb.cp().channel({chn}).bin({b}).mass({m, "*"}).WriteDatacard(
315-
// folder+"/"+b + "_" + m + ".txt", output);
316-
// }
317-
// }
318-
cb.cp().channel({chn}).mass({"125", "*"}).WriteDatacard(
319-
folder+"/htt_" + chn + "_125.txt", output);
320-
output.Close();
259+
boost::filesystem::create_directories(folder+"/"+chn);
260+
//Use CH to create combined card for each channel
261+
cb.cp().channel({chn}).mass({"*"}).WriteDatacard(
262+
folder + "/" + chn + "/combinedCard.txt", output);
263+
auto bins = cb.cp().channel({chn}).bin_set();
264+
for (auto b : bins) {
265+
cout << ">> Writing datacard for bin: " << b << "\r" << flush;
266+
//Also print individual datacards for each category of each channel
267+
boost::filesystem::create_directories(folder+"/"+chn);
268+
cb.cp().channel({chn}).bin({b}).mass({"*"}).WriteDatacard(
269+
folder + "/" + chn + "/" + b + ".txt", output);
270+
//Also print individual datacards for each category of each channel in the combined directory
271+
boost::filesystem::create_directories(folder+"/cmb");
272+
cb.cp().channel({chn}).bin({b}).mass({"*"}).WriteDatacard(
273+
folder + "/cmb/"+ b + ".txt", output);
274+
}
321275
}
322-
TFile output((folder + "/htt_combined.input.root").c_str(),
323-
"RECREATE");
324-
cb.cp().mass({"125", "*"}).WriteDatacard(
325-
folder+"/htt_combined_125.txt", output);
276+
//Use CH to create combined card for full combination
277+
cb.cp().mass({"*"}).WriteDatacard(
278+
folder + "/cmb/combinedCard.txt", output);
326279
output.Close();
327280
cout << "\n>> Done!\n";
328281
}
329-
330-
331-
332282
}

CombineHarvester/CombineTools/Rules.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ $(d)/interface/GitVersion.h: $(TOP)/../.git/logs/HEAD
88
@echo -e "Updating $@"
99
@echo -e "namespace ch { inline std::string GitVersion() { return \""$(shell git describe --dirty)"\"; } }\n" > $@
1010

11+
$(d)/src/CombineHarvester_Datacards.cc : $(d)/interface/GitVersion.h
12+
1113
clean_$(d)/interface/GitVersion.h :
1214
rm -f $(subst clean_,,$@)
1315

CombineHarvester/CombineTools/interface/TFileIO.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void ch::WriteToTFile(T const* ptr, TFile* file, std::string const& path) {
4242
}
4343
gDirectory->cd(as_vec[i].c_str());
4444
}
45-
if (!gDirectory->Get(as_vec.back().c_str())) {
45+
if (!gDirectory->FindKey(as_vec.back().c_str())) {
4646
gDirectory->WriteTObject(ptr, as_vec.back().c_str());
4747
}
4848
gDirectory->cd("/");

0 commit comments

Comments
 (0)