How to get a histogram in a ROOT file without knowing its full name

Hi all,

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?

Thank you in advance for any help.



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”).


My problem solved. It was the usage of TList that I was looking for. Thank you all very much!