Access histograms saved in folders in a root file

I have a root file containing many pulses in histogram format.
What I am trying to do is calculate the average pulse of those histograms.
In some root files I can access the histograms using the following code

[code]//Load File.
TFile *f = new TFile(“FIMG5.root”);

//Loop over each histogram and store pointer in vector.
std::vector<TH1F*> hists;
for (int i=0;i<305;i++) {
TH1F hIndv = (TH1F)f->Get(Form(“FIMG5_EV_%d;1”,i));
if (hIndv)
hists.push_back(hIndv);
}[/code]

In some root files the histograms are stored into folders, as you can see in the following shot from a TBrowser

How can I access those histograms?

root.cern.ch/root/htmldoc/TDire … oryFile:cd

The problem is that I there are 3 directories inside the root file and I have a for loop, so haw am I going to change directory inside a for loop?

I do not see the problem. Outside or inside a for loop you can use "cd’ to enter a directory.