1 from PhysicsTools.NanoAODTools.postprocessing.framework.treeReaderArrayTools
import setExtraBranch
2 from array
import array
4 ROOT.PyConfig.IgnoreCommandLineOptions =
True 7 _rootBranchType2PythonArray = {
22 self, tree, name, rootBranchType, n=1,
23 lenVar=None, title=None, limitedPrecision=False
27 _rootBranchType2PythonArray[rootBranchType], n * [0.
if rootBranchType
in 'FD' else 0])
30 self.
precision = ROOT.MiniFloatConverter.ReduceMantissaToNbitsRounding(
31 limitedPrecision)
if limitedPrecision
and rootBranchType ==
'F' else lambda x: x
33 existingBranch = tree.GetBranch(name)
40 name, self.
buff,
"%s[%s]/%s" % (name, lenVar, rootBranchType))
43 name, self.
buff, name +
"/" + rootBranchType)
46 name, self.
buff,
"%s[%d]/%s" % (name, n, rootBranchType))
48 self.
branch.SetTitle(title)
52 if len(self.
buff) < len(val):
54 len(val), 2 * len(self.
buff)) * [0.
if self.
buff.typecode
in 'fd' else 0])
56 for i, v
in enumerate(val):
61 if len(val) != self.
n:
62 raise RuntimeError(
"Mismatch in filling branch %s of fixed length %d with %d values (%s)" % (
63 self.
branch.GetName(), self.
n, len(val), val))
64 for i, v
in enumerate(val):
76 self, name, rootBranchType, n=1, lenVar=None,
77 title=None, limitedPrecision=False
80 if (lenVar !=
None)
and (lenVar
not in self.
_branches):
83 self.
_tree, name, rootBranchType, n=n,
84 lenVar=lenVar, title=title, limitedPrecision=limitedPrecision
90 if br.lenVar
and (br.lenVar
in self.
_branches):
91 self.
_branches[br.lenVar].buff[0] = len(val)
113 branchSelection=None,
114 outputbranchSelection=None,
127 outputTree = inputTree.CopyTree(
128 '1',
"", maxEntries
if maxEntries
else ROOT.TVirtualTreePlayer.kMaxEntries, firstEntry)
130 outputTree = inputTree.CloneTree(0)
134 inputTree.SetBranchStatus(
"*", 1)
136 branchSelection.selectBranches(inputTree)
138 OutputTree.__init__(self, outputFile, outputTree, inputTree)
142 for k
in inputFile.GetListOfKeys():
146 elif kn
in (
"MetaData",
"ParameterSets"):
150 kn).CopyTree(
'1' if firstEntry == 0
else '0')
151 elif kn
in (
"LuminosityBlocks",
"Runs"):
154 kn).CopyTree(
'1' if firstEntry == 0
else '0')
155 elif firstEntry == 0:
156 _isRun = (kn ==
"Runs")
157 _it = inputFile.Get(kn)
158 _ot = _it.CloneTree(0)
160 if (jsonFilter.filterRunOnly(ev.run)
if _isRun
else jsonFilter.filterRunLumi(ev.run, ev.luminosityBlock)):
163 elif k.GetClassName() ==
"TTree":
164 print(
"Not copying unknown tree %s" % kn)
178 OutputTree.write(self)
182 self.
_file.WriteTObject(ov, on)
186 def __init__(self, inputFile, inputTree, outputFile, treeName="Friends"):
188 outputTree = ROOT.TTree(
189 treeName,
"Friend tree for " + inputTree.GetName())
190 OutputTree.__init__(self, outputFile, outputTree, inputTree)
def __init__(self, tree, name, rootBranchType, n=1, lenVar=None, title=None, limitedPrecision=False)
def __init__(self, inputFile, inputTree, outputFile, branchSelection=None, outputbranchSelection=None, fullClone=False, maxEntries=None, firstEntry=0, provenance=False, jsonFilter=None)
def fillBranch(self, name, val)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def branch(self, name, rootBranchType, n=1, lenVar=None, title=None, limitedPrecision=False)
def __init__(self, inputFile, inputTree, outputFile, treeName="Friends")
def __init__(self, tfile, ttree, intree)