How to save a branch of vector of vectors in an existing tree in pyroot

Hello,
I am trying to add a branch of (vector of vectors) in an existing tree. I am using PyROOT. While the code runs fine, I do not see the branch properly saved in my updated tree. All values are 0 on the branch. This is the code snippet that I am trying to run:

import os, sys, time
from ROOT import *

def main():
    inputFile = TFile("simpleFile.root","UPDATE")
    inTree = inputFile.Get("clusters")
    residualsX  = std.vector(std.vector("float"))([0][0])
    residualsX_Br  = inTree.Branch("residualsX", residualsX, "std.vector(std.vector('double'))([0][0)")


    for ev in inTree:
       residualsX.clear()
       for clus in range(ev.pixelIndex.size()):
           residualsX_Indiv             = std.vector("double")([])
           for partIdx in range(ev.particle_local_pos_x_mm[clus].size()):
            
                ### calculate residuals for each cluster
                resXCOG             = ev.residual_x_um[clus][partIdx]
                residualsX_Indiv.push_back(resXCOG)

           residualsX.push_back(residualsX_Indiv)
       residualsX_Br.Fill()

    inTree.Write("", TObject.kOverwrite)
    inputFile.Write()


if __name__ == "__main__":
    main()

Any lead on what I am doing wrong will be much appreciated.

Thank you very much,
Arka


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.26/10
_Platform: macosx64
_Compiler: Apple clang version 14.0.0


I think @pcanal can help you.

Hi @couet,
Thank you very much. Looking forward to suggestions from @pcanal.
Best,
Arka

Try

residualsX  = std.vector(std.vector("double"))([0][0])

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.