Access histograms inside a TFolder in a root file

Hi,

I am attempting to grab some histograms from a root file produced by our analyzer. The structure of the file appears to be “histos” folder in the top level with folders inside of it, and histograms inside each folder. I have tried this:

TFile f = new TFile(inFile);
f->cd("/histos/armMap");
mass = (TH1
) gDirectory->Get(“mass_Arm0”);
mass->Draw();

However I can’t get past:
Error in TFile::cd: Unknown directory histos

From the TBrowser if I choose Dump from the “histos” folder I get:
root [8] ==> Dumping object at: 0x0000000004eee9d0, name=histos, class=TFolder

*fFolders ->4ef7280 pointer to the list of folders
fIsOwner false true if folder own its contained objects
fName histos object identifier
fTitle MIDAS Analyzer Histoobject title
fUniqueID 0 object unique identifier
fBits 0x03008008 bit field status word

And if I dump the folder with the histograms in it that I want to access I get:
==> Dumping object at: 0x0000000003b5d030, name=armMap, class=TFolder

*fFolders ->3b5d090 pointer to the list of folders
fIsOwner false true if folder own its contained objects
fName armMap object identifier
fTitle Histos for module arobject title
fUniqueID 0 object unique identifier
fBits 0x03008008 bit field status word

I can access everything in the TBrowser fine including plotting histograms.

In summary, the folder histos is in the top level of the root file, it has several folders inside of it, and each of those folders have histograms inside of them. How do I access the histograms when the cd() command will not allow me to navigate to them? Thanks,

I think you first need to retrieve the TFolder object.

TFolder *folder = nullptr;
f->GetObject("histos",folder);

and then retrieve the histrogram from the TFolder itself.

Cheers,
Philippe.

Perfect, thanks Philippe!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.