CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LHEAnalyzer.py
Go to the documentation of this file.
1 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
2 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
4 from math import *
5 from DataFormats.FWLite import Events, Handle
6 
7 class LHEAnalyzer( Analyzer ):
8  """ """
9  def __init__(self, cfg_ana, cfg_comp, looperName ):
10  super(LHEAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
11 
12  def declareHandles(self):
13  super(LHEAnalyzer, self).declareHandles()
14 # self.mchandles['lhestuff'] = AutoHandle( 'externalLHEProducer','LHEEventProduct')
15 
16  def beginLoop(self, setup):
17  super(LHEAnalyzer,self).beginLoop(setup)
18 
19  def process(self, event):
20 
21  # if not MC, nothing to do
22  if not self.cfg_comp.isMC:
23  return True
24  event.lheHT=0
25  event.lheNj=0
26  event.lheV_pt = 0
27  h=Handle('LHEEventProduct')
28  event.input.getByLabel( 'externalLHEProducer',h)
29  if not h.isValid() :
30  return True
31  self.readCollections( event.input )
32  hepeup=h.product().hepeup()
33  pup=hepeup.PUP
34  l=None
35  lBar=None
36  nu=None
37  nuBar=None
38  for i in xrange(0,len(pup)):
39  id=hepeup.IDUP[i]
40  status = hepeup.ISTUP[i]
41  idabs=abs(id)
42 
43  if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks
44  event.lheHT += sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py
45  event.lheNj +=1
46  if idabs in [12,14,16] :
47  if id > 0 :
48  nu = i
49  else :
50  nuBar = i
51  if idabs in [11,13,15] :
52  if id > 0 :
53  l = i
54  else :
55  lBar = i
56  v=None
57  if l and lBar : #Z to LL
58  v=(l,lBar)
59  elif l and nuBar : #W
60  v=(l,nuBar)
61  elif lBar and nu : #W
62  v=(nu,lBar)
63  elif nu and nuBar : #Z to nn
64  v=(nu,nuBar)
65  if v :
66  event.lheV_pt = sqrt( (pup[v[0]][0]+pup[v[1]][0])**2 + (pup[v[0]][1]+pup[v[1]][1])**2 )
67 
68  return True
69 
70 setattr(LHEAnalyzer,"defaultConfig",
71  cfg.Analyzer(LHEAnalyzer,
72  )
73 )
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22