8 #include "boost/filesystem.hpp"
22 typedef vector<string> VString;
24 string auxiliaries = string(getenv(
"CMSSW_BASE")) +
"/src/auxiliaries/";
25 string aux_shapes = auxiliaries +
"shapes/";
26 string aux_pruning = auxiliaries +
"pruning/";
28 string(getenv(
"CMSSW_BASE")) +
"/src/CombineHarvester/CombineTools/input";
31 {
"et",
"mt",
"em",
"ee",
"mm",
"tt"};
33 map<string, string> input_folders = {
42 map<string, VString> bkg_procs;
43 bkg_procs[
"et"] = {
"ZTT",
"W",
"QCD",
"ZL",
"ZJ",
"TT",
"VV"};
44 bkg_procs[
"mt"] = {
"ZTT",
"W",
"QCD",
"ZL",
"ZJ",
"TT",
"VV"};
45 bkg_procs[
"em"] = {
"Ztt",
"EWK",
"Fakes",
"ttbar",
"ggH_hww125",
"qqH_hww125"};
46 bkg_procs[
"ee"] = {
"ZTT",
"WJets",
"QCD",
"ZEE",
"TTJ",
"Dibosons",
"ggH_hww125",
"qqH_hww125"};
47 bkg_procs[
"mm"] = {
"ZTT",
"WJets",
"QCD",
"ZMM",
"TTJ",
"Dibosons",
"ggH_hww125",
"qqH_hww125"};
48 bkg_procs[
"tt"] = {
"ZTT",
"W",
"QCD",
"ZL",
"ZJ",
"TT",
"VV"};
50 VString sig_procs = {
"ggH",
"qqH",
"WH",
"ZH"};
52 map<string, Categories> cats;
54 {1,
"eleTau_0jet_medium"}, {2,
"eleTau_0jet_high"},
55 {3,
"eleTau_1jet_medium"}, {5,
"eleTau_1jet_high_mediumhiggs"},
59 {1,
"eleTau_0jet_medium"}, {2,
"eleTau_0jet_high"},
60 {3,
"eleTau_1jet_medium"}, {5,
"eleTau_1jet_high_mediumhiggs"},
61 {6,
"eleTau_vbf_loose"}, {7,
"eleTau_vbf_tight"}};
64 {1,
"muTau_0jet_medium"}, {2,
"muTau_0jet_high"},
65 {3,
"muTau_1jet_medium"}, {4,
"muTau_1jet_high_lowhiggs"}, {5,
"muTau_1jet_high_mediumhiggs"},
69 {1,
"muTau_0jet_medium"}, {2,
"muTau_0jet_high"},
70 {3,
"muTau_1jet_medium"}, {4,
"muTau_1jet_high_lowhiggs"}, {5,
"muTau_1jet_high_mediumhiggs"},
71 {6,
"muTau_vbf_loose"}, {7,
"muTau_vbf_tight"}};
74 {0,
"emu_0jet_low"}, {1,
"emu_0jet_high"},
75 {2,
"emu_1jet_low"}, {3,
"emu_1jet_high"},
76 {4,
"emu_vbf_loose"}};
79 {0,
"emu_0jet_low"}, {1,
"emu_0jet_high"},
80 {2,
"emu_1jet_low"}, {3,
"emu_1jet_high"},
81 {4,
"emu_vbf_loose"}, {5,
"emu_vbf_tight"}};
84 {0,
"ee_0jet_low"}, {1,
"ee_0jet_high"},
85 {2,
"ee_1jet_low"}, {3,
"ee_1jet_high"},
87 cats[
"ee_8TeV"] = cats[
"ee_7TeV"];
90 {0,
"mumu_0jet_low"}, {1,
"mumu_0jet_high"},
91 {2,
"mumu_1jet_low"}, {3,
"mumu_1jet_high"},
93 cats[
"mm_8TeV"] = cats[
"mm_7TeV"];
96 {0,
"tauTau_1jet_high_mediumhiggs"}, {1,
"tauTau_1jet_high_highhiggs"},
101 cout <<
">> Creating processes and observations...\n";
102 for (
string era : {
"7TeV",
"8TeV"}) {
103 for (
auto chn : chns) {
105 {
"*"}, {
"htt"}, {era}, {chn}, cats[chn+
"_"+era]);
107 {
"*"}, {
"htt"}, {era}, {chn}, bkg_procs[chn], cats[chn+
"_"+era],
false);
109 masses, {
"htt"}, {era}, {chn}, sig_procs, cats[chn+
"_"+era],
true);
114 return p->
bin() ==
"tauTau_vbf" && p->
process() ==
"ZL";
117 cout <<
">> Adding systematic uncertainties...\n";
123 cout <<
">> Extracting histograms from input root files...\n";
124 for (
string era : {
"7TeV",
"8TeV"}) {
125 for (
string chn : chns) {
127 if (chn ==
"tt" && era ==
"7TeV")
continue;
128 string file = aux_shapes + input_folders[chn] +
"/htt_" + chn +
129 ".inputs-sm-" + era +
"-hcg.root";
131 file,
"$BIN/$PROCESS",
"$BIN/$PROCESS_$SYSTEMATIC");
133 file,
"$BIN/$PROCESS$MASS",
"$BIN/$PROCESS$MASS_$SYSTEMATIC");
138 cout <<
">> Scaling signal process rates...\n";
139 map<string, TGraph> xs;
142 for (
string const& e : {
"7TeV",
"8TeV"}) {
143 for (
string const& p : sig_procs) {
145 xs[p+
"_"+e] =
ch::TGraphFromTable(input_dir+
"/xsecs_brs/"+p+
"_"+e+
"_YR3.txt",
"mH",
"xsec");
146 cout <<
">>>> Scaling for process " << p <<
" and era " << e <<
"\n";
148 double m = boost::lexical_cast<double>(proc->
mass());
149 proc->
set_rate(proc->
rate() * xs[p+
"_"+e].Eval(m) * xs[
"htt"].Eval(m));
154 xs[
"hww_over_htt"] =
ch::TGraphFromTable(input_dir+
"/xsecs_brs/hww_over_htt.txt",
"mH",
"ratio");
155 for (
string const& e : {
"7TeV",
"8TeV"}) {
156 for (
string const& p : {
"ggH",
"qqH"}) {
157 cb.
cp().
channel({
"em"}).process({p+
"_hww125"}).era({e})
159 proc->
set_rate(proc->
rate() * xs[p+
"_"+e].Eval(125.) * xs[
"htt"].Eval(125.));
160 proc->
set_rate(proc->
rate() * xs[
"hww_over_htt"].Eval(125.));
165 cout <<
">> Merging bin errors and generating bbb uncertainties...\n";
175 bbb.MergeAndAdd(cb_et.
cp().
era({
"7TeV"}).
bin_id({1, 2}).
process({
"ZL",
"ZJ",
"QCD",
"W"}), cb);
177 bbb.MergeAndAdd(cb_et.
cp().
era({
"8TeV"}).
bin_id({1, 2}).
process({
"ZL",
"ZJ",
"QCD",
"W"}), cb);
179 bbb.MergeAndAdd(cb_et.
cp().
era({
"7TeV"}).
bin_id({6}).
process({
"ZL",
"ZJ",
"W",
"ZTT"}), cb);
183 bbb.MergeAndAdd(cb_et.
cp().
era({
"8TeV"}).
bin_id({7}).
process({
"ZL",
"ZJ",
"W",
"ZTT"}), cb);
186 bbb.MergeAndAdd(cb_mt.
cp().
era({
"7TeV"}).
bin_id({1, 2, 3, 4}).
process({
"W",
"QCD"}), cb);
187 bbb.MergeAndAdd(cb_mt.
cp().
era({
"8TeV"}).
bin_id({1, 2, 3, 4}).
process({
"W",
"QCD"}), cb);
196 bbb.MergeAndAdd(cb_em.
cp().
era({
"7TeV"}).
bin_id({4}).
process({
"Fakes",
"EWK",
"Ztt"}), cb);
197 bbb.MergeAndAdd(cb_em.
cp().
era({
"8TeV"}).
bin_id({5}).
process({
"Fakes",
"EWK",
"Ztt"}), cb);
201 bbb.MergeAndAdd(cb_tt.
cp().
era({
"8TeV"}).
bin_id({0, 1, 2}).
process({
"ZTT",
"QCD"}), cb);
203 bbb.SetAddThreshold(0.);
205 bbb.MergeAndAdd(cb_ll.
cp().
era({
"7TeV"}).
bin_id({1, 3, 4}).
process({
"ZTT",
"ZEE",
"ZMM",
"TTJ"}), cb);
206 bbb.MergeAndAdd(cb_ll.
cp().
era({
"8TeV"}).
bin_id({1, 3, 4}).
process({
"ZTT",
"ZEE",
"ZMM",
"TTJ"}), cb);
208 cout <<
">> Setting standardised bin names...\n";
212 aux_pruning +
"uncertainty-pruning-drop-131128-sm.txt");
213 cout <<
">> Droplist contains " << droplist.size() <<
" entries\n";
216 for (
auto x : droplist) to_drop.insert(x);
221 cout <<
">> Systematics dropped: " << pre_drop.size() - post_drop.size()
266 ch::CardWriter writer(
"$TAG/$MASS/$ANALYSIS_$CHANNEL_$BINID_$ERA.txt",
267 "$TAG/common/$ANALYSIS_$CHANNEL.input_$ERA.root");
274 cout <<
"\n>> Done!\n";
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.
BinByBinFactory & SetMergeThreshold(double val)
The threshold for the merging algorithm.
Automates the writing of datacards into directory structures.
std::map< std::string, CombineHarvester > WriteCards(std::string const &tag, ch::CombineHarvester &cmb) const
Write datacards according to patterns, substituting $TAG for tag
CombineHarvester & bin_id(std::vector< int > const &vec, bool cond=true)
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)
CombineHarvester & process(std::vector< std::string > const &vec, bool cond=true)
CombineHarvester & era(std::vector< std::string > const &vec, bool cond=true)
CombineHarvester & syst_name(std::vector< std::string > const &vec, bool cond=true)
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)
std::set< std::string > channel_set()
CombineHarvester & FilterProcs(Function func)
std::set< std::string > syst_name_set()
void ExtractShapes(std::string const &file, std::string const &rule, std::string const &syst_rule)
CombineHarvester cp()
Creates and returns a shallow copy of the CombineHarvester instance.
CombineHarvester & channel(std::vector< std::string > const &vec, bool cond=true)
virtual std::string const & process() const
virtual std::string const & bin() const
virtual std::string const & mass() const
void set_rate(double const &rate)
std::vector< std::string > ParseFileLines(std::string const &file_name)
void AddSystematics_ee_mm(CombineHarvester &cb)
TGraph TGraphFromTable(std::string filename, std::string const &x_column, std::string const &y_column)
void SetStandardBinNames(CombineHarvester &cb, std::string const &pattern="$ANALYSIS_$CHANNEL_$BINID_$ERA")
std::vector< std::pair< int, std::string > > Categories
void AddSystematics_et_mt(CombineHarvester &cb)
std::vector< std::string > ValsFromRange(std::string const &input, std::string const &fmt="%.0f")
Generate a vector of values using ranges and intervals specified in a string.
void AddSystematics_tt(CombineHarvester &cb)
void AddSystematics_em(CombineHarvester &cb)