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
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>')
26 self.counters.addCounter(
'events')
27 count = self.counters.counter(
'events')
28 count.register(
'all events')
29 count.register(
'has >=1 tau at preselection')
30 count.register(
'has >=1 selected taus')
31 count.register(
'has >=1 loose taus')
32 count.register(
'has >=1 inclusive taus')
38 event.selectedTaus = []
40 event.inclusiveTaus = []
43 alltaus =
map( Tau, self.handles[
'taus'].product() )
47 tau.associatedVertex = event.goodVertices[0]
if len(event.goodVertices)>0
else event.vertices[0]
49 tau.idDecayMode = tau.tauID(
"decayModeFinding")
50 tau.idDecayModeNewDMs = tau.tauID(
"decayModeFindingNewDMs")
51 if hasattr(self.cfg_ana,
'decayModeID')
and self.cfg_ana.decayModeID
and not tau.tauID(self.cfg_ana.decayModeID):
54 if self.cfg_ana.vetoLeptons:
55 for lep
in event.selectedLeptons:
56 if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.leptonVetoDR:
58 if tau.lepVeto:
continue
59 if self.cfg_ana.vetoLeptonsPOG:
60 if not tau.tauID(self.cfg_ana.tauAntiMuonID):
62 if not tau.tauID(self.cfg_ana.tauAntiElectronID):
64 if tau.lepVeto:
continue
66 if tau.pt() < self.cfg_ana.ptMin:
continue
67 if abs(tau.eta()) > self.cfg_ana.etaMax:
continue
68 if abs(tau.dxy()) > self.cfg_ana.dxyMax
or abs(tau.dz()) > self.cfg_ana.dzMax:
continue
72 """Create an integer equal to 1-2-3 for (loose,medium,tight)"""
73 return tau.tauID(X%
"Loose") + tau.tauID(X%
"Medium") + tau.tauID(X%
"Tight")
75 """Create an integer equal to 1-2-3-4-5 for (very loose,
76 loose, medium, tight, very tight)"""
77 return id3(tau, X) + tau.tauID(X%
"VLoose") + tau.tauID(X%
"VTight")
79 """Create an integer equal to 1-2-3-4-5-6 for (very loose,
80 loose, medium, tight, very tight, very very tight)"""
81 return id5(tau, X) + tau.tauID(X%
"VVTight")
83 tau.idMVA = id6(tau,
"by%sIsolationMVA3oldDMwLT")
84 tau.idMVANewDM = id6(tau,
"by%sIsolationMVA3newDMwLT")
85 tau.idCI3hit = id3(tau,
"by%sCombinedIsolationDeltaBetaCorr3Hits")
86 tau.idAntiMu = tau.tauID(
"againstMuonLoose") + tau.tauID(
"againstMuonTight")
87 tau.idAntiE = id5(tau,
"againstElectron%sMVA5")
89 if tau.tauID(self.cfg_ana.tauID):
90 event.selectedTaus.append(tau)
91 event.inclusiveTaus.append(tau)
92 elif tau.tauID(self.cfg_ana.tauLooseID):
93 event.looseTaus.append(tau)
94 event.inclusiveTaus.append(tau)
96 event.selectedTaus.sort(key =
lambda l : l.pt(), reverse =
True)
97 event.looseTaus.sort(key =
lambda l : l.pt(), reverse =
True)
98 self.counters.counter(
'events').inc(
'all events')
99 if foundTau: self.counters.counter(
'events').inc(
'has >=1 tau at preselection')
100 if len(event.selectedTaus): self.counters.counter(
'events').inc(
'has >=1 selected taus')
101 if len(event.looseTaus): self.counters.counter(
'events').inc(
'has >=1 loose taus')
102 if len(event.inclusiveTaus): self.counters.counter(
'events').inc(
'has >=1 inclusive taus')
107 for lep
in event.inclusiveTaus:
109 lep.mcMatchId = 1
if gen
else 0
112 self.readCollections( event.input )
116 if not self.cfg_comp.isMC:
119 if hasattr(event,
'gentaus'):
127 setattr(TauAnalyzer,
"defaultConfig",cfg.Analyzer(
128 class_object=TauAnalyzer,
135 decayModeID =
"decayModeFindingNewDMs",
136 tauID =
"byLooseCombinedIsolationDeltaBetaCorr3Hits",
137 vetoLeptonsPOG =
False,
138 tauAntiMuonID =
"againstMuonLoose3",
139 tauAntiElectronID =
"againstElectronLooseMVA5",
140 tauLooseID =
"decayModeFinding",
Abs< T >::type abs(const T &t)
double deltaR(double eta1, double eta2, double phi1, double phi2)
def matchObjectCollection3