1 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
2 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
3 from PhysicsTools.Heppy.physicsobjects.Tau
import Tau
7 import PhysicsTools.HeppyCore.framework.config
as cfg
13 def __init__(self, cfg_ana, cfg_comp, looperName ):
14 super(TauAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
21 self.handles[
'taus'] = AutoHandle( (
'slimmedTaus',
''),
'std::vector<pat::Tau>')
25 self.counters.addCounter(
'events')
26 count = self.counters.
counter(
'events')
27 count.register(
'all events')
28 count.register(
'has >=1 tau at preselection')
29 count.register(
'has >=1 selected taus')
30 count.register(
'has >=1 other taus')
36 event.inclusiveTaus = []
37 event.selectedTaus = []
41 alltaus =
map( Tau, self.handles[
'taus'].product() )
45 tau.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
47 tau.idDecayMode = tau.tauID(
"decayModeFinding")
48 tau.idDecayModeNewDMs = tau.tauID(
"decayModeFindingNewDMs")
50 if hasattr(self.cfg_ana,
'inclusive_decayModeID')
and self.cfg_ana.inclusive_decayModeID
and not tau.tauID(self.cfg_ana.inclusive_decayModeID):
53 tau.inclusive_lepVeto =
False 54 if self.cfg_ana.inclusive_vetoLeptons:
55 for lep
in event.selectedLeptons:
56 if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.inclusive_leptonVetoDR:
57 tau.inclusive_lepVeto =
True 58 if tau.inclusive_lepVeto:
continue 59 if self.cfg_ana.inclusive_vetoLeptonsPOG:
60 if not tau.tauID(self.cfg_ana.inclusive_tauAntiMuonID):
61 tau.inclusive_lepVeto =
True 62 if not tau.tauID(self.cfg_ana.inclusive_tauAntiElectronID):
63 tau.inclusive_lepVeto =
True 64 if tau.inclusive_lepVeto:
continue 66 if tau.pt() < self.cfg_ana.inclusive_ptMin:
continue 67 if abs(tau.eta()) > self.cfg_ana.inclusive_etaMax:
continue 68 if abs(tau.dxy()) > self.cfg_ana.inclusive_dxyMax
or abs(tau.dz()) > self.cfg_ana.inclusive_dzMax:
continue 71 """Create an integer equal to 1-2-3 for (loose,medium,tight)""" 72 return tau.tauID(X%
"Loose") + tau.tauID(X%
"Medium") + tau.tauID(X%
"Tight")
74 """Create an integer equal to 1-2-3-4-5 for (very loose, 75 loose, medium, tight, very tight)""" 76 return id3(tau, X) + tau.tauID(X%
"VLoose") + tau.tauID(X%
"VTight")
78 """Create an integer equal to 1-2-3-4-5-6 for (very loose, 79 loose, medium, tight, very tight, very very tight)""" 80 return id5(tau, X) + tau.tauID(X%
"VVTight")
82 tau.idMVA = id6(tau,
"by%sIsolationMVArun2v1DBoldDMwLT")
83 tau.idMVANewDM = id6(tau,
"by%sIsolationMVArun2v1DBnewDMwLT")
84 tau.idCI3hit = id3(tau,
"by%sCombinedIsolationDeltaBetaCorr3Hits")
85 tau.idAntiMu = tau.tauID(
"againstMuonLoose3") + tau.tauID(
"againstMuonTight3")
86 tau.idAntiE = id5(tau,
"againstElectron%sMVA6")
89 if tau.tauID(self.cfg_ana.inclusive_tauID):
90 event.inclusiveTaus.append(tau)
92 for tau
in event.inclusiveTaus:
94 tau.loose_lepVeto =
False 95 if self.cfg_ana.loose_vetoLeptons:
96 for lep
in event.selectedLeptons:
97 if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.loose_leptonVetoDR:
98 tau.loose_lepVeto =
True 99 if self.cfg_ana.loose_vetoLeptonsPOG:
100 if not tau.tauID(self.cfg_ana.loose_tauAntiMuonID):
101 tau.loose_lepVeto =
True 102 if not tau.tauID(self.cfg_ana.loose_tauAntiElectronID):
103 tau.loose_lepVeto =
True 105 if tau.tauID(self.cfg_ana.loose_decayModeID)
and \
106 tau.pt() > self.cfg_ana.loose_ptMin
and abs(tau.eta()) < self.cfg_ana.loose_etaMax
and \
107 abs(tau.dxy()) < self.cfg_ana.loose_dxyMax
and abs(tau.dz()) < self.cfg_ana.loose_dzMax
and \
108 tau.tauID(self.cfg_ana.loose_tauID)
and not tau.loose_lepVeto:
109 event.selectedTaus.append(tau)
111 event.otherTaus.append(tau)
113 event.inclusiveTaus.sort(key =
lambda l : l.pt(), reverse =
True)
114 event.selectedTaus.sort(key =
lambda l : l.pt(), reverse =
True)
115 event.otherTaus.sort(key =
lambda l : l.pt(), reverse =
True)
116 self.counters.
counter(
'events').inc(
'all events')
117 if len(event.inclusiveTaus): self.counters.
counter(
'events').inc(
'has >=1 tau at preselection')
118 if len(event.selectedTaus): self.counters.
counter(
'events').inc(
'has >=1 selected taus')
119 if len(event.otherTaus): self.counters.
counter(
'events').inc(
'has >=1 other taus')
123 for lep
in event.inclusiveTaus:
125 lep.mcMatchId = 1
if gen
else 0
129 self.readCollections( event.input )
133 if not self.cfg_comp.isMC:
136 if hasattr(event,
'gentaus'):
144 setattr(TauAnalyzer,
"defaultConfig",cfg.Analyzer(
145 class_object = TauAnalyzer,
147 inclusive_ptMin = 18,
148 inclusive_etaMax = 9999,
149 inclusive_dxyMax = 1000.,
150 inclusive_dzMax = 0.4,
151 inclusive_vetoLeptons =
False,
152 inclusive_leptonVetoDR = 0.4,
153 inclusive_decayModeID =
"decayModeFindingNewDMs",
154 inclusive_tauID =
"decayModeFindingNewDMs",
155 inclusive_vetoLeptonsPOG =
False,
156 inclusive_tauAntiMuonID =
"",
157 inclusive_tauAntiElectronID =
"",
161 loose_dxyMax = 1000.,
163 loose_vetoLeptons =
True,
164 loose_leptonVetoDR = 0.4,
165 loose_decayModeID =
"decayModeFindingNewDMs",
166 loose_tauID =
"byLooseCombinedIsolationDeltaBetaCorr3Hits",
167 loose_vetoLeptonsPOG =
False,
168 loose_tauAntiMuonID =
"againstMuonLoose3",
169 loose_tauAntiElectronID =
"againstElectronLooseMVA5"
def __init__(self, cfg_ana, cfg_comp, looperName)
def makeTaus(self, event)
def beginLoop(self, setup)
def matchTaus(self, event)
Abs< T >::type abs(const T &t)
def matchObjectCollection3