I've changed the code to range(len(tree.genPdgId)); that seems to work. I will look into the pass function.