File indexing completed on 2024-04-06 12:23:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection
0013 from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
0014 import ROOT
0015 ROOT.PyConfig.IgnoreCommandLineOptions = True
0016
0017
0018 class exampleProducer(Module):
0019 def __init__(self, jetSelection):
0020 self.jetSel = jetSelection
0021 pass
0022
0023 def beginJob(self):
0024 pass
0025
0026 def endJob(self):
0027 pass
0028
0029 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
0030 self.out = wrappedOutputTree
0031 self.out.branch("EventMass", "F")
0032
0033 def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
0034 pass
0035
0036 def analyze(self, event):
0037 """process event, return True (go to next module) or False (fail, go to next event)"""
0038 electrons = Collection(event, "Electron")
0039 muons = Collection(event, "Muon")
0040 jets = Collection(event, "Jet")
0041 eventSum = ROOT.TLorentzVector()
0042 for lep in muons:
0043 eventSum += lep.p4()
0044 for lep in electrons:
0045 eventSum += lep.p4()
0046 for j in filter(self.jetSel, jets):
0047 eventSum += j.p4()
0048 self.out.fillBranch("EventMass", eventSum.M())
0049 return True
0050
0051
0052
0053
0054 exampleModuleConstr = lambda: exampleProducer(jetSelection=lambda j: j.pt > 30)