test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MetAnalyzer.py
Go to the documentation of this file.
1 import copy
2 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
3 from PhysicsTools.Heppy.analyzers.AutoHandle import AutoHandle
4 import random
5 
6 def pv(vc):
7  print 'x = {x:5.4f}, y = {y:5.4f}, z = {z:5.4f}'.format(x=vc.X(),
8  y=vc.Y(),
9  z=vc.Z())
10 
11 class MetAnalyzer( Analyzer ):
12  '''Analyze MET in Z+jet events.
13  Need a to provide a module creating event.diLepton
14  earlier in the sequence.
15  '''
16 
17  def declareHandles(self):
18  super(MetAnalyzer, self).declareHandles()
19  self.handles['met'] = AutoHandle(
20  self.cfg_ana.metCol,
21  self.cfg_ana.metType
22  )
23 
24 
25  def beginLoop(self, setup):
26  super(MetAnalyzer,self).beginLoop(setup)
27 
28 
29  def process(self, iEvent, event):
30  self.readCollections( iEvent )
31  event.met = self.handles['met'].product()[0]
32  met = event.met
33  # here, do pure met stuff
34 
35  if not hasattr(event, 'diLepton'):
36  return False
37 
38  diL = event.diLepton
39 
40 ## rnd = random.random()
41 ## leg = diL.leg1()
42 ## if rnd>0.5:
43 ## leg = diL.leg2()
44 
45 
46  # here, do recoil stuff
47 
48  mVect = met.p4().Vect()
49  mVect.SetZ(0.)
50  vVect = diL.p4().Vect()
51  vVect.SetZ(0.)
52  recoilVect = copy.deepcopy(mVect)
53  recoilVect -= vVect
54 
55  uvVect = vVect.Unit()
56  zAxis = type(vVect)(0,0,1)
57  uvVectPerp = vVect.Cross(zAxis).Unit()
58 
59  u1 = - recoilVect.Dot(uvVect)
60  u2 = recoilVect.Dot(uvVectPerp)
61 
62  event.u1 = u1
63  event.u2 = u2
64 
65  if self.cfg_ana.verbose:
66  print 'met', met.pt()
67  print 'diL', diL
68  print 'vVect'
69  pv(vVect)
70  print 'uvVect'
71  pv(uvVect)
72  print 'uvVectPerp'
73  pv(uvVectPerp)
74  print u1, u2
75 
76  return True
77 
78 
79 
80 
81 ## def write(self, setup):
82 ## super(MetAnalyzer, self).write(setup)