I’d like to do something like in hadd.C, but for the histograms from the current ROOT session. Is there a way of accessing all currently defined TH1 objects - there should be, since ROOT provides tab completion for variable names?
Then, I could do something like:
TIter nextkey( gROOT->GetListOfKeys() );
a colleague from ATLAS (Tayfun Ince incet@uvic.ca) has found a working solution:
TObject* obj = 0;
TIter next(gPad->GetListOfPrimitives());
while ( obj = (TObject*)next() ) {
if ( obj->InheritsFrom(TH1::Class()) ) {
TH1* h1d = (TH1*)obj;
}
}
yes, that works well for all histograms drawn on a given pad; gDirectory->GetList() will iterate over all objects created in all canvases in the current directory.
For completeness: if you want to iterate only over the drawn histograms, you can loop over all pads using gROOT->GetListOfCanvases().