2
2
import ROOT
3
3
ROOT .PyConfig .IgnoreCommandLineOptions = True
4
4
5
+ from PhysicsTools .NanoAODTools .postprocessing .framework .treeReaderArrayTools import setExtraBranch
6
+
5
7
_rootBranchType2PythonArray = { 'b' :'B' , 'B' :'b' , 'i' :'I' , 'I' :'i' , 'F' :'f' , 'D' :'d' , 'l' :'L' , 'L' :'l' , 'O' :'B' }
6
8
7
9
class OutputBranch :
@@ -30,9 +32,10 @@ def fill(self, val):
30
32
for i ,v in enumerate (val ): self .buff [i ] = v
31
33
32
34
class OutputTree :
33
- def __init__ (self , tfile , ttree ):
35
+ def __init__ (self , tfile , ttree , intree ):
34
36
self ._file = tfile
35
37
self ._tree = ttree
38
+ self ._intree = intree
36
39
self ._branches = {}
37
40
def branch (self , name , rootBranchType , n = 1 , lenVar = None , title = None ):
38
41
if (lenVar != None ) and (lenVar not in self ._branches ) and (not self ._tree .GetBranch (lenVar )):
@@ -43,7 +46,9 @@ def fillBranch(self, name, val):
43
46
br = self ._branches [name ]
44
47
if br .lenVar and (br .lenVar in self ._branches ):
45
48
self ._branches [br .lenVar ].buff [0 ] = len (val )
49
+ setExtraBranch (self ._intree ,br .lenVar ,len (val ))
46
50
br .fill (val )
51
+ setExtraBranch (self ._intree ,name ,val )
47
52
def tree (self ):
48
53
return self ._tree
49
54
def fill (self ):
@@ -58,7 +63,7 @@ def __init__(self, inputFile, inputTree, outputFile, branchSelection = None, ful
58
63
if branchSelection :
59
64
branchSelection .selectBranches (inputTree )
60
65
outputTree = inputTree .CopyTree ('1' ) if fullClone else inputTree .CloneTree (0 )
61
- OutputTree .__init__ (self , outputFile , outputTree )
66
+ OutputTree .__init__ (self , outputFile , outputTree , inputTree )
62
67
self ._inputTree = inputTree
63
68
self ._otherTrees = {}
64
69
self ._otherObjects = {}
@@ -95,5 +100,5 @@ class FriendOutput(OutputTree):
95
100
def __init__ (self , inputFile , inputTree , outputFile , treeName = "Friends" ):
96
101
outputFile .cd ()
97
102
outputTree = ROOT .TTree (treeName ,"Friend tree for " + inputTree .GetName ())
98
- OutputTree .__init__ (self , outputFile , outputTree )
103
+ OutputTree .__init__ (self , outputFile , outputTree , inputTree )
99
104
0 commit comments