CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TauAnalyzer.py
Go to the documentation of this file.
1 
2 import operator
3 import itertools
4 import copy
5 import types
6 
7 from ROOT import TLorentzVector
8 
9 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
10 from PhysicsTools.HeppyCore.framework.event import Event
11 from PhysicsTools.HeppyCore.statistics.counter import Counter, Counters
12 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
13 from PhysicsTools.Heppy.physicsobjects.Lepton import Lepton
14 from PhysicsTools.Heppy.physicsobjects.Tau import Tau
15 
16 from PhysicsTools.HeppyCore.utils.deltar import deltaR, deltaPhi, bestMatch
17 
19 
20 
22 
23 
24  def __init__(self, cfg_ana, cfg_comp, looperName ):
25  super(TauAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
26 
27  #----------------------------------------
28  # DECLARATION OF HANDLES OF LEPTONS STUFF
29  #----------------------------------------
30  def declareHandles(self):
31  super(TauAnalyzer, self).declareHandles()
32  self.handles['taus'] = AutoHandle( ('slimmedTaus',''),'std::vector<pat::Tau>')
33 
34 
35  def beginLoop(self):
36  super(TauAnalyzer,self).beginLoop()
37  self.counters.addCounter('events')
38  count = self.counters.counter('events')
39  count.register('all events')
40  count.register('has >=1 tau at preselection')
41  count.register('has >=1 selected taus')
42  count.register('has >=1 loose taus')
43  count.register('has >=1 inclusive taus')
44 
45  #------------------
46  # MAKE LEPTON LISTS
47  #------------------
48  def makeTaus(self, event):
49  event.selectedTaus = []
50  event.looseTaus = []
51  event.inclusiveTaus = []
52 
53  #get all
54  alltaus = map( Tau, self.handles['taus'].product() )
55 
56  foundTau = False
57  for tau in alltaus:
58  tau.associatedVertex = event.goodVertices[0]
59  tau.lepVeto = False
60  if self.cfg_ana.vetoLeptons:
61  for lep in event.selectedLeptons:
62  if deltaR(lep.eta(), lep.phi(), tau.eta(), tau.phi()) < self.cfg_ana.leptonVetoDR:
63  tau.lepVeto = True
64  if tau.lepVeto: continue
65  if self.cfg_ana.vetoLeptonsPOG:
66  if not tau.tauID("againstMuonTight"):
67  tau.lepVeto = True
68  if not tau.tauID("againstElectronLoose"):
69  tau.lepVeto = True
70  if tau.lepVeto: continue
71  if tau.pt() < self.cfg_ana.ptMin: continue
72  if abs(tau.eta()) > self.cfg_ana.etaMax: continue
73 ### tau.dxy and tau.dz are zero
74 ### if abs(tau.dxy()) > self.cfg_ana.dxyMax or abs(tau.dz()) > self.cfg_ana.dzMax: continue
75  foundTau = True
76  def id3(tau,X):
77  """Create an integer equal to 1-2-3 for (loose,medium,tight)"""
78  return tau.tauID(X%"Loose") + tau.tauID(X%"Medium") + tau.tauID(X%"Tight")
79  #tau.idMVA2 = id3(tau, "by%sIsolationMVA2")
80  tau.idCI3hit = id3(tau, "by%sCombinedIsolationDeltaBetaCorr3Hits")
81  #print "Tau pt %5.1f: idMVA2 %d, idCI3hit %d, %s, %s" % (tau.pt(), tau.idMVA2, tau.idCI3hit, tau.tauID(self.cfg_ana.tauID), tau.tauID(self.cfg_ana.tauLooseID))
82  if tau.tauID(self.cfg_ana.tauID):
83  event.selectedTaus.append(tau)
84  event.inclusiveTaus.append(tau)
85  elif tau.tauID(self.cfg_ana.tauLooseID):
86  event.looseTaus.append(tau)
87  event.inclusiveTaus.append(tau)
88 
89  event.selectedTaus.sort(key = lambda l : l.pt(), reverse = True)
90  event.looseTaus.sort(key = lambda l : l.pt(), reverse = True)
91  self.counters.counter('events').inc('all events')
92  if foundTau: self.counters.counter('events').inc('has >=1 tau at preselection')
93  if len(event.selectedTaus): self.counters.counter('events').inc('has >=1 selected taus')
94  if len(event.looseTaus): self.counters.counter('events').inc('has >=1 loose taus')
95  if len(event.inclusiveTaus): self.counters.counter('events').inc('has >=1 inclusive taus')
96  def process(self, event):
97  self.readCollections( event.input )
98  self.makeTaus(event)
99  return True
100 
101 setattr(TauAnalyzer,"defaultConfig",cfg.Analyzer(
102  class_object=TauAnalyzer,
103  ptMin = 20,
104  etaMax = 9999,
105  dxyMax = 0.5,
106  dzMax = 1.0,
107  vetoLeptons = True,
108  leptonVetoDR = 0.4,
109  vetoLeptonsPOG = False,
110  tauID = "byLooseCombinedIsolationDeltaBetaCorr3Hits",
111  tauLooseID = "decayModeFinding",
112  )
113 )
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17