test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ntuple.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 def var( tree, varName, type=float ):
4  tree.var(varName, type)
5 
6 def fill( tree, varName, value ):
7  tree.fill( varName, value )
8 
9 # event information
10 
11 def bookEvent(tree):
12  var(tree, 'run')
13  var(tree, 'lumi')
14  var(tree, 'event')
15 
16 def fillEvent(tree, event):
17  fill(tree, 'run', event.run)
18  fill(tree, 'lumi', event.lumi)
19  fill(tree, 'event', event.eventId)
20 
21 
22 # simple particle
23 
24 def bookParticle( tree, pName ):
25  var(tree, '{pName}_pdgid'.format(pName=pName))
26  var(tree, '{pName}_e'.format(pName=pName))
27  var(tree, '{pName}_pt'.format(pName=pName))
28  var(tree, '{pName}_eta'.format(pName=pName))
29  var(tree, '{pName}_phi'.format(pName=pName))
30  var(tree, '{pName}_m'.format(pName=pName))
31  var(tree, '{pName}_q'.format(pName=pName))
32 
33 def fillParticle( tree, pName, particle ):
34  fill(tree, '{pName}_pdgid'.format(pName=pName), particle.pdgId() )
35  fill(tree, '{pName}_e'.format(pName=pName), particle.energy() )
36  fill(tree, '{pName}_pt'.format(pName=pName), particle.pt() )
37  fill(tree, '{pName}_eta'.format(pName=pName), particle.eta() )
38  fill(tree, '{pName}_phi'.format(pName=pName), particle.phi() )
39  fill(tree, '{pName}_m'.format(pName=pName), particle.mass() )
40  fill(tree, '{pName}_q'.format(pName=pName), particle.charge() )
41 
42 def bookMet(tree, pName):
43  var(tree, '{pName}_pt'.format(pName=pName))
44  var(tree, '{pName}_phi'.format(pName=pName))
45  var(tree, '{pName}_sumet'.format(pName=pName))
46 
47 def fillMet(tree, pName, met):
48  fill(tree, '{pName}_pt'.format(pName=pName), met.pt())
49  fill(tree, '{pName}_phi'.format(pName=pName), met.phi())
50  fill(tree, '{pName}_sumet'.format(pName=pName), met.sumEt())
51 
52 def bookGenTau(tree, pName, pfdiscs, calodiscs):
53  bookJet(tree, pName)
54  bookTau(tree, '{pName}_calo'.format(pName=pName), calodiscs)
55  bookTau(tree, '{pName}_pf'.format(pName=pName), pfdiscs)
56  bookJet(tree, '{pName}_pfjet'.format(pName=pName))
57 
58 def fillGenTau(tree, pName, tau):
59  fillJet(tree, pName, tau)
60  fillTau(tree, '{pName}_calo'.format(pName=pName), tau.match_calo)
61  fillTau(tree, '{pName}_pf'.format(pName=pName), tau.match_pf)
62  fillJet(tree, '{pName}_pfjet'.format(pName=pName), tau.match_pfjet)
63 
64 
65 def bookTau(tree, pName, discNames):
66  bookParticle(tree, pName)
67  var(tree, '{pName}_nsigcharged'.format(pName=pName))
68  var(tree, '{pName}_isolation'.format(pName=pName))
69  for discName in discNames:
70  var(tree, '{pName}_{disc}'.format(pName=pName,
71  disc=discName))
72 
73 def fillTau(tree, pName, tau):
74  if not tau: return
75  fillParticle(tree, pName, tau)
76  fill(tree, '{pName}_nsigcharged'.format(pName=pName), len(tau.signalCharged()))
77  fill(tree, '{pName}_isolation'.format(pName=pName), tau.isolation())
78  for discName, value in tau.discs.iteritems():
79  fill(tree, '{pName}_{disc}'.format(pName=pName,
80  disc=discName), value)
81 
82 
83 # jet
84 
85 def bookComponent( tree, pName ):
86  var(tree, '{pName}_e'.format(pName=pName))
87  var(tree, '{pName}_pt'.format(pName=pName))
88  var(tree, '{pName}_num'.format(pName=pName))
89 
90 def fillComponent(tree, pName, component):
91  fill(tree, '{pName}_e'.format(pName=pName), component.e() )
92  fill(tree, '{pName}_pt'.format(pName=pName), component.pt() )
93  fill(tree, '{pName}_num'.format(pName=pName), component.num() )
94 
95 
96 pdgids = [211, 22, 130, 11, 13]
97 
98 def bookJet( tree, pName ):
99  bookParticle(tree, pName )
100  for pdgid in pdgids:
101  bookComponent(tree, '{pName}_{pdgid:d}'.format(pName=pName, pdgid=pdgid))
102  # var(tree, '{pName}_npart'.format(pName=pName))
103 
104 def fillJet( tree, pName, jet ):
105  if not jet: return
106  fillParticle(tree, pName, jet )
107  for pdgid in pdgids:
108  component = jet.constituents.get(pdgid, None)
109  if component is not None:
110  fillComponent(tree,
111  '{pName}_{pdgid:d}'.format(pName=pName, pdgid=pdgid),
112  component )
113  else:
114  import pdb; pdb.set_trace()
115  print jet
116 
def bookTau
Definition: ntuple.py:65
def bookMet
Definition: ntuple.py:42
def fillJet
Definition: ntuple.py:104
def bookGenTau
Definition: ntuple.py:52
def fillGenTau
Definition: ntuple.py:58
def fillParticle
Definition: ntuple.py:33
def bookJet
Definition: ntuple.py:98
def var
Definition: ntuple.py:3
def bookComponent
Definition: ntuple.py:85
def fillEvent
Definition: ntuple.py:16
def fillTau
Definition: ntuple.py:73
def fill
Definition: ntuple.py:6
def bookParticle
Definition: ntuple.py:24
def fillMet
Definition: ntuple.py:47
def bookEvent
Definition: ntuple.py:11
def fillComponent
Definition: ntuple.py:90