1 from PhysicsTools.NanoAODTools.postprocessing.framework.treeReaderArrayTools
import setExtraBranch
2 from array
import array
4 ROOT.PyConfig.IgnoreCommandLineOptions =
True 7 _rootBranchType2PythonArray = {
24 self, tree, name, rootBranchType, n=1,
25 lenVar=None, title=None, limitedPrecision=False
29 _rootBranchType2PythonArray[rootBranchType], n * [0.
if rootBranchType
in 'FD' else 0])
32 self.
precision = ROOT.MiniFloatConverter.ReduceMantissaToNbitsRounding(
33 limitedPrecision)
if limitedPrecision
and rootBranchType ==
'F' else lambda x: x
35 existingBranch = tree.GetBranch(name)
42 name, self.
buff,
"%s[%s]/%s" % (name, lenVar, rootBranchType))
45 name, self.
buff, name +
"/" + rootBranchType)
48 name, self.
buff,
"%s[%d]/%s" % (name, n, rootBranchType))
50 self.
branch.SetTitle(title)
54 if len(self.
buff) < len(val):
56 len(val), 2 * len(self.
buff)) * [0.
if self.
buff.typecode
in 'fd' else 0])
58 for i, v
in enumerate(val):
63 if len(val) != self.
n:
64 raise RuntimeError(
"Mismatch in filling branch %s of fixed length %d with %d values (%s)" % (
65 self.
branch.GetName(), self.
n, len(val), val))
66 for i, v
in enumerate(val):
78 self, name, rootBranchType, n=1, lenVar=None,
79 title=None, limitedPrecision=False
82 if (lenVar !=
None)
and (lenVar
not in self.
_branches):
85 self.
_tree, name, rootBranchType, n=n,
86 lenVar=lenVar, title=title, limitedPrecision=limitedPrecision
92 if br.lenVar
and (br.lenVar
in self.
_branches):
93 self.
_branches[br.lenVar].buff[0] = len(val)
115 branchSelection=None,
116 outputbranchSelection=None,
129 outputTree = inputTree.CopyTree(
130 '1',
"", maxEntries
if maxEntries
else ROOT.TVirtualTreePlayer.kMaxEntries, firstEntry)
132 outputTree = inputTree.CloneTree(0)
136 inputTree.SetBranchStatus(
"*", 1)
138 branchSelection.selectBranches(inputTree)
140 OutputTree.__init__(self, outputFile, outputTree, inputTree)
144 for k
in inputFile.GetListOfKeys():
148 elif kn
in (
"MetaData",
"ParameterSets"):
152 kn).CopyTree(
'1' if firstEntry == 0
else '0')
153 elif kn
in (
"LuminosityBlocks",
"Runs"):
156 kn).CopyTree(
'1' if firstEntry == 0
else '0')
157 elif firstEntry == 0:
158 _isRun = (kn ==
"Runs")
159 _it = inputFile.Get(kn)
160 _ot = _it.CloneTree(0)
162 if (jsonFilter.filterRunOnly(ev.run)
if _isRun
else jsonFilter.filterRunLumi(ev.run, ev.luminosityBlock)):
165 elif k.GetClassName() ==
"TTree":
166 print(
"Not copying unknown tree %s" % kn)
180 OutputTree.write(self)
184 self.
_file.WriteTObject(ov, on)
188 def __init__(self, inputFile, inputTree, outputFile, treeName="Friends"):
190 outputTree = ROOT.TTree(
191 treeName,
"Friend tree for " + inputTree.GetName())
192 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)