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  self.lheh=Handle('LHEEventProduct')
12 
13  def declareHandles(self):
14  super(LHEAnalyzer, self).declareHandles()
15 # self.mchandles['lhestuff'] = AutoHandle( 'externalLHEProducer','LHEEventProduct')
16 
17  def beginLoop(self, setup):
18  super(LHEAnalyzer,self).beginLoop(setup)
19 
20  def process(self, event):
21 
22  # if not MC, nothing to do
23  if not self.cfg_comp.isMC:
24  return True
25  event.lheHT=0
26  event.lheNj=0
27  event.lheNb=0
28  event.lheNc=0
29  event.lheNl=0
30  event.lheNg=0
31  event.lheV_pt = 0
32  try:
33  event.input.getByLabel( 'externalLHEProducer',self.lheh)
34  except :
35  return True
36  if not self.lheh.isValid() :
37  return True
38  self.readCollections( event.input )
39  hepeup=self.lheh.product().hepeup()
40  pup=hepeup.PUP
41  l=None
42  lBar=None
43  nu=None
44  nuBar=None
45  for i in xrange(0,len(pup)):
46  id=hepeup.IDUP[i]
47  status = hepeup.ISTUP[i]
48  idabs=abs(id)
49 
50  if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks
51  event.lheHT += sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py
52  event.lheNj +=1
53  if idabs==5:
54  event.lheNb += 1
55  if idabs==4:
56  event.lheNc += 1
57  if idabs in [1,2,3]:
58  event.lheNl += 1
59  if idabs==21:
60  event.lheNg += 1
61  if idabs in [12,14,16] :
62  if id > 0 :
63  nu = i
64  else :
65  nuBar = i
66  if idabs in [11,13,15] :
67  if id > 0 :
68  l = i
69  else :
70  lBar = i
71  v=None
72  if l and lBar : #Z to LL
73  v=(l,lBar)
74  elif l and nuBar : #W
75  v=(l,nuBar)
76  elif lBar and nu : #W
77  v=(nu,lBar)
78  elif nu and nuBar : #Z to nn
79  v=(nu,nuBar)
80  if v :
81  event.lheV_pt = sqrt( (pup[v[0]][0]+pup[v[1]][0])**2 + (pup[v[0]][1]+pup[v[1]][1])**2 )
82 
83  return True
84 
85 setattr(LHEAnalyzer,"defaultConfig",
86  cfg.Analyzer(LHEAnalyzer,
87  )
88 )
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22