File indexing completed on 2024-04-06 12:23:46
0001
0002
0003
0004
0005
0006 from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module
0007 import ROOT
0008 import os
0009 ROOT.PyConfig.IgnoreCommandLineOptions = True
0010
0011
0012
0013 class mhtjuProducerCpp(Module):
0014 def __init__(self):
0015 base = os.getenv("NANOAODTOOLS_BASE")
0016 if base:
0017
0018 if "/MhtjuProducerCppWorker_cc.so" not in ROOT.gSystem.GetLibraries():
0019 print("Load C++ MhtjuProducerCppWorker worker module")
0020 ROOT.gROOT.ProcessLine(
0021 ".L %s/test/examples/MhtjuProducerCppWorker.cc+O" % base)
0022 else:
0023
0024
0025
0026 base = "%s/src/PhysicsTools/NanoAODTools" % os.getenv("CMSSW_BASE")
0027 ROOT.gSystem.Load("libPhysicsToolsNanoAODToolsTest.so")
0028 ROOT.gROOT.ProcessLine(".L %s/test/examples/MhtjuProducerCppWorker.h" % base)
0029 self.worker = ROOT.MhtjuProducerCppWorker()
0030 pass
0031
0032 def beginJob(self):
0033 pass
0034
0035 def endJob(self):
0036 pass
0037
0038 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
0039 self.initReaders(inputTree)
0040 self.out = wrappedOutputTree
0041 self.out.branch("MHTju_pt", "F")
0042 self.out.branch("MHTju_phi", "F")
0043
0044 def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
0045 pass
0046
0047
0048
0049 def initReaders(self, tree):
0050 self.nJet = tree.valueReader("nJet")
0051 self.Jet_pt = tree.arrayReader("Jet_pt")
0052 self.Jet_phi = tree.arrayReader("Jet_phi")
0053 self.worker.setJets(self.nJet, self.Jet_pt, self.Jet_phi)
0054
0055
0056 self._ttreereaderversion = tree._ttreereaderversion
0057
0058 def analyze(self, event):
0059 """process event, return True (go to next module) or False (fail,
0060 go to next event)"""
0061
0062
0063
0064 if event._tree._ttreereaderversion > self._ttreereaderversion:
0065 self.initReaders(event._tree)
0066
0067
0068 output = self.worker.getHT()
0069
0070 self.out.fillBranch("MHTju_pt", output[0])
0071 self.out.fillBranch("MHTju_phi", -output[1])
0072 return True
0073
0074
0075
0076
0077
0078 mhtju = lambda: mhtjuProducerCpp()