-
Notifications
You must be signed in to change notification settings - Fork 5
/
mk_datacard
executable file
·116 lines (101 loc) · 7.19 KB
/
mk_datacard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
import CombineHarvester.CombineTools.ch as ch
import ROOT as r
import argparse
parser = argparse.ArgumentParser(description='Write some cards.')
parser.add_argument('input', type=str, nargs=1,
help="input ROOT file")
parser.add_argument('-d', '--discriminant', type=str, default='BDT',
help="discriminant to use")
args = parser.parse_args()
cats = [(1, 'ee_p'), (2,'ee_m'), (3,'em_bt_p'), (4,'em_bt_m'), (5,'em_bl_p'), (6,'em_bl_m'), (7,'mm_bt_p'), (8,'mm_bt_m'), (9,'mm_bl_p'), (10,'mm_bl_m')]
sigs = ['ttH']
bkgs = ['fakes', 'flips', 'tttt', 'tWll', 'tZq','WGToLNuG', 'ZGTo2LG', 'TTGJets', 'TGJets', 'Wjets', 'WWqq_rares', 'WW_doublescatering_rares', 'WWW_rares', 'WWZ_rares', 'WZZ_rares', 'ZZZ_rares', 'WW_2l2nu', 'WZ_to3lnu', 'ZZ_to4l', 'ttZ_M10', 'ttZ_M1to10', 'ttjets_semilep', 'ttjets_dilep', 'ttW' ]
convs = ['TTGJets', 'TGJets', 'WGToLNuG', 'ZGTo2LG']
mc_bkg = [x for x in bkgs if x != 'fakes' and x !='flips']
mc = sigs + mc_bkg
mc_syst = sigs + ['tWll','WW_2l2nu', 'WZ_to3lnu', 'ttZ_M10', 'ttZ_M1to10', 'ttW' ]
cb = ch.CombineHarvester()
cb.SetVerbosity(2)
#masses = ch.ValsFromRange('120:130|5')
masses = ['125']
cb.AddObservations(['*'], ['ttH'], ['13TeV'], ['ttl'], cats)
cb.AddProcesses(['*'], ['ttH'], ['13TeV'], ['ttl'], bkgs, cats, False)
cb.AddProcesses(masses, ['ttH'], ['13TeV'], ['ttl'], sigs, cats, True)
cb.cp().AddSyst(cb, 'QCDscale_ttW', 'lnN', ch.SystMap("process")(["ttW"], 1.12) )
cb.cp().AddSyst(cb, 'CMS_ttHl_WZ_4j', 'lnN', ch.SystMap("process")(["WZ_to3lnu"], 2.0) )
cb.cp().AddSyst(cb, 'pdf_Higgs_ttH', 'lnN', ch.SystMap("process")(["ttH"], 1.036) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Clos_e_norm', 'lnN', ch.SystMap("process", "bin")(["fakes"], ["ee_p","ee_m"], 1.2) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Clos_e_norm', 'lnN', ch.SystMap("process", "bin")(["fakes"], ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.1) )
cb.cp().AddSyst(cb, 'pdf_qqbar', 'lnN', ch.SystMap("process")(["ttW"], 1.04) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_eltight', 'lnN', ch.SystMap("process","bin")(mc, ["ee_p","ee_m"], 1.06) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_eltight', 'lnN', ch.SystMap("process","bin")(mc, ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.03) )
cb.cp().AddSyst(cb, 'br_hbb', 'lnN', ch.SystMap("process")(["ttH"], 1.0126) )
cb.cp().AddSyst(cb, 'QCDscale_ttZ', 'lnN', ch.SystMap("process")(["ttZ"], 1.11) )
cb.cp().AddSyst(cb, 'lumi_13TeV', 'lnN', ch.SystMap("process") (mc, 1.026))
cb.cp().AddSyst(cb, 'pdf_gg', 'lnN', ch.SystMap("process")(["ttZ","ttZ_M1to10"], 0.966) )
cb.cp().AddSyst(cb, 'CMS_ttHl16_trigger_ee', 'lnN', ch.SystMap("process","bin")(mc, ["ee_p","ee_m"], 1.02) )
cb.cp().AddSyst(cb, 'CMS_ttHl16_trigger_em', 'lnN', ch.SystMap("process","bin")(mc, ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.01) )
cb.cp().AddSyst(cb, 'CMS_ttHl16_trigger_mm', 'lnN', ch.SystMap("process","bin")(mc, ["mm_bt_p","mm_bt_m","mm_bl_p","mm_bl_m"], 1.01) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Clos_m_norm', 'lnN', ch.SystMap("process", "bin")(["flips"], ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.1) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Clos_m_norm', 'lnN', ch.SystMap("process", "bin")(["flips"], ["mm_bt_p","mm_bt_m","mm_bl_p","mm_bl_m"], 1.2) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_muloose', 'lnN', ch.SystMap("process","bin")(mc, ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.02) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_mutight', 'lnN', ch.SystMap("process","bin")(mc, ["em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.03) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_muloose', 'lnN', ch.SystMap("process","bin")(mc, ["mm_bt_p","mm_bt_m","mm_bl_p","mm_bl_m"], 1.04) )
cb.cp().AddSyst(cb, 'CMS_ttHl_lepEff_mutight', 'lnN', ch.SystMap("process","bin")(mc, ["mm_bt_p","mm_bt_m","mm_bl_p","mm_bl_m"], 1.06) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Convs', 'lnN', ch.SystMap("process","bin")(convs, ["ee_p","ee_m", "em_bt_p","em_bt_m","em_bl_p","em_bl_m"], 1.3) )
cb.cp().AddSyst(cb, 'CMS_ttHl_QF', 'lnN', ch.SystMap("process")(["flips"], 1.3) )
cb.cp().AddSyst(cb, 'CMS_ttHl_Rares', 'lnN', ch.SystMap("process")(["flips"], 1.5) )
cb.cp().AddSyst(cb, 'QCDscale_ttH', 'lnN', ch.SystMap("process") (["ttH"], 0.915/1.058) )
cb.cp().AddSyst(cb, 'jes_', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'hf', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'hfstats1', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'hfstats2', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'lf', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'lfstats1', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'lfstats2', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'cerr1', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'cerr2', 'shape', ch.SystMap("process")(mc_syst,1.0))
cb.cp().AddSyst(cb, 'fr_mva090_', 'shape', ch.SystMap("process")(["fakes"],1.0))
cb.cp().AddSyst(cb, 'fr_mva090_pt', 'shape', ch.SystMap("process")(["fakes"],1.0))
cb.cp().AddSyst(cb, 'fr_mva090_be', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin1_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin2_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin3_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin4_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin5_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin6_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin7_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin8_', 'shape', ch.SystMap("process")(mc_syst,1.0))
# cb.cp().AddSyst(cb, 'bin1_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin2_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin3_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin4_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin5_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin6_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin7_', 'shape', ch.SystMap("process")(["fakes"],1.0))
# cb.cp().AddSyst(cb, 'bin8_', 'shape', ch.SystMap("process")(["fakes"],1.0))
cb.cp().backgrounds().ExtractShapes(
args.input[0],
"final_shape_$PROCESS_$BIN".format(args.discriminant),
"final_shape_$SYSTEMATIC_$PROCESS_$BIN".format(args.discriminant)
# "final_shape_$PROCESS_$BIN_$SYSTEMATIC".format(args.discriminant)
)
cb.cp().signals().ExtractShapes(
args.input[0],
"final_shape_$PROCESS_$BIN".format(args.discriminant),
"final_shape_$SYSTEMATIC_$PROCESS_$BIN".format(args.discriminant)
# "final_shape_$PROCESS_$BIN_$SYSTEMATIC".format(args.discriminant)
)
#add shape nuisances for bin-by-bin uncertainties
bbb = ch.BinByBinFactory()
bbb.SetAddThreshold(0.14).SetMergeThreshold(0.4).SetFixNorm(False)
bbb.MergeBinErrors(cb.cp().backgrounds())
bbb.AddBinByBin(cb.cp().backgrounds(), cb)
bbb.AddBinByBin(cb.cp().signals(), cb)
#cb.PrintObs().PrintProcs().PrintSysts()
cb.WriteDatacard("card.txt", "file.root")
writer = ch.CardWriter('$TAG/$MASS/$ANALYSIS_$CHANNEL.txt',
'$TAG/common/$ANALYSIS_$CHANNEL.root')
writer.SetVerbosity(1)
writer.WriteCards('limits', cb)