test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlphaTAnalyzer.py
Go to the documentation of this file.
1 import operator
2 import itertools
3 import copy
4 from math import *
5 
6 #from ROOT import TLorentzVector, TVectorD
7 
8 from PhysicsTools.HeppyCore.utils.deltar import deltaR, deltaPhi
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 
14 # from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Lepton
15 # from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Photon
16 # from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Electron
17 # from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Muon
18 # from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Tau
19 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import Jet
20 
21 import ROOT
22 from ROOT.heppy import AlphaT
23 
24 
25 import os
26 
27 class AlphaTAnalyzer( Analyzer ):
28  def __init__(self, cfg_ana, cfg_comp, looperName ):
29  super(AlphaTAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
30 
31  def declareHandles(self):
32  super(AlphaTAnalyzer, self).declareHandles()
33  #genJets
34  self.handles['genJets'] = AutoHandle( 'slimmedGenJets','std::vector<reco::GenJet>')
35 
36  def beginLoop(self,setup):
37  super(AlphaTAnalyzer,self).beginLoop(setup)
38  self.counters.addCounter('pairs')
39  count = self.counters.counter('pairs')
40  count.register('all events')
41 
42 
43  # Calculate alphaT using jet ET
44  def makeAlphaT(self, jets):
45 
46  if len(jets) == 0:
47  return 0.
48 
49  px = ROOT.std.vector('double')()
50  py = ROOT.std.vector('double')()
51  et = ROOT.std.vector('double')()
52 
53  #Make alphaT from lead 10 jets
54  for jet in jets[:10]:
55  px.push_back(jet.px())
56  py.push_back(jet.py())
57  et.push_back(jet.et())
58 
59  alphaTCalc = AlphaT()
60  return alphaTCalc.getAlphaT( et, px, py )
61 
62  def process(self, event):
63  self.readCollections( event.input )
64 
65  event.alphaT = self.makeAlphaT(event.cleanJets)
66 
67  #Do the same with gen jets for MC
68  if self.cfg_comp.isMC:
69  event.genAlphaT = self.makeAlphaT(event.cleanGenJets)
70 
71  return True