Find the TDirectory for a histogram

Dear Experts,

I have an open TFile and a large map of histogram pointers that were declared using new while cd-ing into different TDirectories of this TFile. I would like to create a new histogram for each member of the map next to the original histogram. (same TDirectory)

Is there a simple way I could get a pinter to the TDirectory a given histogram is in?

Cheers,
Peter

Try GetDirectory(), e.g.

histo->GetDirectory();

You can do histo->GetDirectory()->GetName() to see the actual text.

Unfortunately that doesnt work for me

root [0] auto h = new THnD()
(THnT<double> *) @0x7ffd43c765f0
root [1] h->GetDirectory()
ROOT_prompt_1:1:4: error: no member named 'GetDirectory' in 'THnT<double>'
h->GetDirectory()

(ROOT 6.22/02)

Indeed, GetDirectory() is only implemented in the TH1.

Since you have a THnT, which doesn’t inherit from TH1, you can’t use this method.

I’m afraid the only solution is that you book-keep the correct directories yourself when you open the histograms.

Thank you Jonas, that makes sense as THnDs are not even possible to be written to the root files if I am right. Bookkeeping is what I ended up doing :slight_smile: