-
Notifications
You must be signed in to change notification settings - Fork 3
/
DYModule.py
160 lines (113 loc) · 7.75 KB
/
DYModule.py
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from bamboo.plots import Plot, CutFlowReport
from bamboo.plots import EquidistantBinning as EqBin
from bamboo import treefunctions as op
from bamboo.analysisutils import forceDefine
import src.definitions as defs
from modules.baseModule import NanoBaseJME
class DYModule(NanoBaseJME):
""""""
def __init__(self, args):
super(DYModule, self).__init__(args)
def definePlots(self, tree, noSel, sample=None, sampleCfg=None):
plots = []
yields = CutFlowReport("yields", printInLog=True, recursive=True)
plots.append(yields)
yields.add(noSel, 'No Selection')
# # AK8 Jets
# ak8Jets = op.sort(
# op.select(tree.FatJet, lambda jet: defs.ak8jetDef(jet)), lambda jet: -jet.pt)
# ak8JetsID = op.sort(
# ak8Jets, lambda jet: jet.jetId & 2)
muons, electrons, clElectrons, ak4Jets, clak4Jets, ak4JetsID, ak4Jetspt40, ak4Jetspt100, ak4Jetsetas2p4, ak4Jetsetag2p4, ak8Jets, clak8Jets, clak4genjets = defs.defineObjects(tree)
### Di-leptonic channel ###
# 2 muon and 2 electron selection
hasTwoSFLeptons = noSel.refine('hasTwoSFLeptons', cut=(
op.OR(
op.AND(op.rng_len(muons) == 2, op.rng_len(clElectrons) ==0,
muons[0].charge != muons[1].charge,
muons[0].pt > 25., muons[1].pt > 15.),
op.AND(op.rng_len(clElectrons) == 2, op.rng_len(muons) ==0,
clElectrons[0].charge != clElectrons[1].charge,
clElectrons[0].pt > 25., clElectrons[1].pt > 15. )
)
))
### reconstruct Z boson
Zboson = op.multiSwitch(
(op.rng_len(muons)>0,op.sum(muons[0].p4,muons[1].p4)),
(op.rng_len(clElectrons)>0,op.sum(clElectrons[0].p4,clElectrons[1].p4)),
op.withMass(muons[0].p4,0)
)
### Z mass selection
Zmasscut = hasTwoSFLeptons.refine("Zmasscut", cut = (
op.AND(Zboson.M() > 80, Zboson.M() < 100)
))
#### deltaphi selection on jets
if sampleCfg['type'] == 'mc':
#### efficiency and purity
### efficiency match to generator jets with deltaR<0.2 and pT gen >30, pt reco > 20
# recojetpt30 = op.select(ak4Jets, lambda jet: jet.pt > 30)
# recojetpt20 = op.select(ak4Jets, lambda jet: jet.pt > 20)
# effjets = defs.effjets(recojetpt20)
# purityjets = defs.purityjets(recojetpt30)
pujets = defs.pujets(ak4Jets)
matchedjets = defs.matchedjets(tree,clElectrons, muons, redo_match = True)
#############################################################################
# Plots #
#############################################################################
import src.controlPlots as cp
if "all" in sampleCfg['plot_level']:
### noSel
plots+=cp.muonPlots(muons, noSel, "noSel")
plots+=cp.electronPlots(electrons, noSel, "noSel")
plots+=cp.AK4jetPlots(ak4Jets, noSel, "noSel")
plots+=cp.AK4jetPlots(ak4JetsID, noSel, "noSelJetID")
plots+=cp.AK4jetPlots(ak4Jetspt40, noSel, "noSelJetpt40")
plots+=cp.eventPlots(tree, noSel, "noSel")
### two leptons
plots+=cp.muonPlots(muons, hasTwoSFLeptons, "hasTwoSFLeptons")
plots+=cp.electronPlots(electrons, hasTwoSFLeptons, "hasTwoSFLeptons")
plots+=cp.ZbosonPlots(Zboson, hasTwoSFLeptons, "hasTwoSFLeptons")
### zmass cut
plots+=cp.muonPlots(muons, Zmasscut, "Zmasscut")
plots+=cp.electronPlots(electrons, Zmasscut, "Zmasscut")
plots+=cp.ZbosonPlots(Zboson, Zmasscut, "Zmasscut")
plots+=cp.AK4jetPlots(ak4Jets, Zmasscut, "Zmasscut")
plots+=cp.AK4jetPlots(ak4JetsID, Zmasscut, "ZmasscutJetID")
plots+=cp.AK4jetPlots(ak4Jetspt40, Zmasscut, "ZmasscutJetpt40")
plots+=cp.AK4jetPlots(ak4Jetspt100, Zmasscut, "ZmasscutJetpt100")
plots+=cp.AK4jetPlots(ak4Jetsetas2p4, Zmasscut, "ZmasscutJetetas2p4")
plots+=cp.AK4jetPlots(ak4Jetsetag2p4, Zmasscut, "ZmasscutJetetag2p4")
if sampleCfg['type'] == 'mc':
plots+=cp.effPurityPlots(clak4Jets,clak4genjets,clak4Jets,Zmasscut,"effPurity", tree)
if any([x in sampleCfg['plot_level'] for x in ["all","response"]]):
plots+=cp.responsePlots( Zmasscut, "Zmasscut_AK4response", tree.GenJet, clak4Jets, tree, debug_hists= False)
plots+=cp.responsePlots( Zmasscut, "Zmasscut_AK8response", tree.GenJet, clak8Jets, tree, debug_hists= False, deltaRcut = 0.4)
plots+=cp.responsePlots( noSel, "noSel_AK4response", tree.GenJet, clak4Jets, tree, debug_hists= False)
plots+=cp.responsePlots( noSel, "noSel_AK8response", tree.GenJet, clak8Jets, tree, debug_hists= False, deltaRcut = 0.4)
if any([x in sampleCfg['plot_level'] for x in ["all","rawresponse"]]):
plots+=cp.responsePlots( Zmasscut, "Zmasscut_AK4rawresponse", tree.GenJet, clak4Jets, tree, debug_hists= False, rawpt = True)
plots+=cp.responsePlots( Zmasscut, "Zmasscut_AK8rawresponse", tree.GenJet, clak8Jets, tree, debug_hists= False, deltaRcut = 0.4, rawpt = True)
plots+=cp.responsePlots( noSel, "noSel_AK4rawresponse", tree.GenJet, clak4Jets, tree, debug_hists= False, rawpt = True)
plots+=cp.responsePlots( noSel, "noSel_AK8rawresponse", tree.GenJet, clak8Jets, tree, debug_hists= False, deltaRcut = 0.4, rawpt = True)
plots+=cp.AK4jetPlots(pujets, Zmasscut, "ZmasscutPuJets")
#Hadronic tau decay mode. 0=OneProng0PiZero, 1=OneProng1PiZero, 2=OneProng2PiZero, 10=ThreeProng0PiZero, 11=ThreeProng1PiZero, 15=Other
taustati = [0,1,2,10,11,15]
plots+=cp.efftauPlots(tree.GenVisTau, tree.Jet, noSel, "noJetSel_taueff_leadingtau0p4",ntaus = 1, deltaRcut = 0.4)
plots+=cp.efftauPlots(tree.GenVisTau, tree.Jet, noSel, "noJetSel_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2)
for status in taustati:
plots+=cp.efftauPlots(op.select(tree.GenVisTau, lambda tau: tau.status ==status), tree.Jet, noSel, "noJetSeltaustatus"+str(status)+"_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2)
if sampleCfg['withCHS']:
plots+=cp.efftauPlots(tree.GenVisTau, tree.JetCHS, noSel, "noJetSelCHS_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2)
for status in taustati:
plots+=cp.efftauPlots(op.select(tree.GenVisTau, lambda tau: tau.status ==status), tree.JetCHS, noSel, "noJetSeltaustatus"+str(status)+"CHS_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2)
plots+=cp.efftauPlots(tree.GenVisTau, tree.Tau, noSel, "noJetSelTau_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2, bPNet = False)
for status in taustati:
plots+=cp.efftauPlots(op.select(tree.GenVisTau, lambda tau: tau.status ==status), tree.Tau, noSel, "noJetSeltaustatus"+str(status)+"Tau_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2, bPNet = False)
plots+=cp.efftauPlots(tree.GenVisTau, tree.GenJet, noSel, "noJetSelGenJet_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2, bPNet = False)
for status in taustati:
plots+=cp.efftauPlots(op.select(tree.GenVisTau, lambda tau: tau.status ==status), tree.GenJet, noSel, "noJetSeltaustatus"+str(status)+"GenJet_taueff_leadingtau0p2",ntaus = 1, deltaRcut = 0.2, bPNet = False)
plots+=cp.eventPlots(tree, Zmasscut, "Zmasscut")
# Cutflow report
yields.add(hasTwoSFLeptons, 'two lepton')
yields.add(Zmasscut, 'zmass cut')
return plots