2 from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel
import Collection
6 ROOT.PyConfig.IgnoreCommandLineOptions =
True 8 _rootLeafType2rootBranchType = {
25 sortkey=lambda x: x.pt,
35 self.
selector = [(selector[coll]
if coll
in selector
else 37 for coll
in self.
input]
if selector
else None 49 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
52 _brlist_in = inputTree.GetListOfBranches()
54 [_brlist_in.At(i)
for i
in range(_brlist_in.GetEntries())])
56 x
for x
in branches_in
if inputTree.GetBranchStatus(x.GetName())
60 _brlist_out = wrappedOutputTree._tree.GetListOfBranches()
62 [_brlist_out.At(i)
for i
in range(_brlist_out.GetEntries())])
64 x
for x
in branches_out
65 if wrappedOutputTree._tree.GetBranchStatus(x.GetName())
69 branches = branches_in + branches_out
85 self.
out = wrappedOutputTree
88 _rootLeafType2rootBranchType[self.
branchType[br]],
89 lenVar=
"n%s" % self.
output)
91 def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
98 if not name.startswith(collection +
'_'):
100 out.append(name.replace(collection +
'_',
''))
101 self.branchType[out[-1]] = br.FindLeaf(br.GetName()).GetTypeName()
105 """process event, return True (go to next module) or False (fail, go to next event)""" 106 coll = [Collection(event, x)
for x
in self.
input]
107 objects = [(coll[j][i], j, i)
for j
in range(self.
nInputs)
108 for i
in range(len(coll[j]))]
111 obj_j_i
for obj_j_i
in objects
112 if self.
selector[obj_j_i[1]](obj_j_i[0])
119 for obj, j, i
in objects:
120 out.append(getattr(obj, br)
if self.
is_there[bridx][j]
else 0)
121 self.
out.fillBranch(
"%s_%s" % (self.
output, br), out)
130 input=[
"Electron",
"Muon"],
134 selector=dict([(
"Electron",
lambda x: x.pt > 20),
135 (
"Muon",
lambda x: x.pt > 40)]),
def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree)
def __init__(self, input, output, sortkey=lambda x:x.pt, reverse=True, selector=None, maxObjects=None)
def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree)
def filterBranchNames(self, branches, collection)