ROOT Macro to dump all TH1F to gif/jpg/eps?

I feel like this should be a commonly needed code that many people have already written, was wondering if somebody was willing to share.

Sometimes, I just need to quickly check a number of kinematic variables. For these, I usually store them in TH1F stored inside a ROOT file. This is a fairly common practice.

I would like a macro where I can just pass it a ROOT filename, then it opens the TH1F and dumps each one into a gif/jpg/eps file in some directory, where the filename is the name of the histogram in the ROOT file.

Then, all plots are available in latex. Does somebody have a code that does something like this and would be willing to share?

I have less automated versions of this (where I have to provide the name of the histograms hardcoded in the macro). An automated version would be awesome :smiley:

see $ROOTSYS/tutorials/io/loopdir.C