forked from cms-nanoAOD/nanoAOD-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
exampleModule.py
43 lines (33 loc) · 1.39 KB
/
exampleModule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection
from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
class exampleProducer(Module):
def __init__(self, jetSelection):
self.jetSel = jetSelection
pass
def beginJob(self):
pass
def endJob(self):
pass
def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
self.out = wrappedOutputTree
self.out.branch("EventMass", "F")
def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
pass
def analyze(self, event):
"""process event, return True (go to next module) or False (fail, go to next event)"""
electrons = Collection(event, "Electron")
muons = Collection(event, "Muon")
jets = Collection(event, "Jet")
eventSum = ROOT.TLorentzVector()
for lep in muons:
eventSum += lep.p4()
for lep in electrons:
eventSum += lep.p4()
for j in filter(self.jetSel, jets):
eventSum += j.p4()
self.out.fillBranch("EventMass", eventSum.M())
return True
# define modules using the syntax 'name = lambda : constructor' to avoid having them loaded when not needed
exampleModuleConstr = lambda: exampleProducer(jetSelection=lambda j: j.pt > 30)