How to fill list into branch with python

Dear @dm-leo ,

Thanks for the example, I understand what you mean now.

The reason why in Python you need to go through the extra level of indirection given by the standard array library or numpy.array even just for a branch of simple types like integers and floats is that you need the memory address of the current value in order to properly connect it to the tree branch (i.e. that’s what you do via Branch("name", address) or via SetBranchAddress). Imagine this pseudo-equivalent code to having a float in C++, in Python

tree = ROOT.TTree("tree_name","tree title")
# What's happening here? You can already see that
# this is not like declaring a C++ `float`, you need to
# give this a value just for the variable to exist.
px = 0.
tree.Branch("px",px,"px/F") # Here we're passing the address of the current px variable

for _ in range(N):
    # This is a completely different variable in Python!
    # So it means it will have a different address in memory
    px = 42.f 
    # What will this do? The previous address is not pointing
    # to the current value in the loop
    tree.Fill()

Instead, by using something like array, you can create the array at a certain memory location, and then modify its contents in-place, thus keeping the same variable address for the TTree to properly connect it to the branch. I hope the explanation is clear.

Cheers,
Vincenzo