I have a bunch of ROOT files, all have same structure. In each file the third histogram has a name “Centroid_run_XXXX”, where “XXXX” is a random number. How can I loop through all the root files and get that histogram for each file?
I propose for this kind of task to take advantage of pyROOT.
import ROOT
import glob
for filename in glob.glob("myDirContainingRootFiles/*.root"):
myFile = ROOT.TFile(filename)
myHisto = myFile.Centroid_run_XXXX
If the number XXXX is something you do not control and changes file by file, you’ll have to create the correct string and use the Get function, e.g. myHisto = myFile.Get(“Centroid_run_1234”).