test
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
3 import PhysicsTools.HeppyCore.framework.config as cfg
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.lheHTIncoming=0 #restrict HT computation to particles that have status<0 mothers
27  event.lheNj=0
28  event.lheNb=0
29  event.lheNc=0
30  event.lheNl=0
31  event.lheNg=0
32  event.lheV_pt = 0
33  try:
34  event.input.getByLabel( 'externalLHEProducer',self.lheh)
35  except :
36  return True
37  if not self.lheh.isValid() :
38  return True
39  self.readCollections( event.input )
40  hepeup=self.lheh.product().hepeup()
41  pup=hepeup.PUP
42  l=None
43  lBar=None
44  nu=None
45  nuBar=None
46  for i in xrange(0,len(pup)):
47  id=hepeup.IDUP[i]
48  status = hepeup.ISTUP[i]
49  idabs=abs(id)
50 
51  mothIdx = max(hepeup.MOTHUP[i][0]-1,0) #first and last mother as pair; first entry has index 1 in LHE; incoming particles return motherindex 0
52  mothIdxTwo = max(hepeup.MOTHUP[i][1]-1,0)
53 
54  mothStatus = hepeup.ISTUP[mothIdx]
55  mothStatusTwo = hepeup.ISTUP[mothIdxTwo]
56 
57  hasIncomingAsMother = mothStatus<0 or mothStatusTwo<0
58 
59  if status == 1 and ( ( idabs == 21 ) or (idabs > 0 and idabs < 7) ) : # gluons and quarks
60  pt = sqrt( pup[i][0]**2 + pup[i][1]**2 ) # first entry is px, second py
61  event.lheHT += pt
62  if hasIncomingAsMother: event.lheHTIncoming += pt
63  event.lheNj +=1
64  if idabs==5:
65  event.lheNb += 1
66  if idabs==4:
67  event.lheNc += 1
68  if idabs in [1,2,3]:
69  event.lheNl += 1
70  if idabs==21:
71  event.lheNg += 1
72  if idabs in [12,14,16] :
73  if id > 0 :
74  nu = i
75  else :
76  nuBar = i
77  if idabs in [11,13,15] :
78  if id > 0 :
79  l = i
80  else :
81  lBar = i
82  v=None
83  if l and lBar : #Z to LL
84  v=(l,lBar)
85  elif l and nuBar : #W
86  v=(l,nuBar)
87  elif lBar and nu : #W
88  v=(nu,lBar)
89  elif nu and nuBar : #Z to nn
90  v=(nu,nuBar)
91  if v :
92  event.lheV_pt = sqrt( (pup[v[0]][0]+pup[v[1]][0])**2 + (pup[v[0]][1]+pup[v[1]][1])**2 )
93 
94  return True
95 
96 setattr(LHEAnalyzer,"defaultConfig",
97  cfg.Analyzer(LHEAnalyzer,
98  )
99 )
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22