Creating an array with the name of the histograms inside a .root file

Dear experts,

I need to do some operations with the histograms in a file that has almost 300k histograms in it. doing it in pure python takes a very long time, so I would want to create a NumPy array that stores the names of the histograms so I can make the operations that I wish to.

But the only thing I could come up with is an np array of keys:

test = np.array( (file.GetListOfKeys()) )

there is some function like .GetNames() or something that I could use? I tried something like

test = np.array( (file.GetListOfKeys()).GetName() )

but I guess it does not work in an element by element inside the array. I need to get a string array with the name of the histograms to separate and cluster the histograms the way i need to. Any tips on that?

Best regards,
Caio.

I am not sure how to do that in Python. May be @etejedor knows.

1 Like

Hello,

To get all those names in Python you would still need to loop over the TList, which would be slow anyway. If you need to loop over 300k keys of a TFile, it is probably better that you do it in C++.

1 Like

ok, got it! I will write a c++ script then.