Ok, I jumped on the chatGPT train... Er, this is disturbingly OK at the lowest bits of being a particle physicist... i.e. basic ROOT file manipulation. It's not wrong, this code would probably work perfectly fine...