Writing a same set of histos to different folders of a TFile

Hello,

I would like to understand a bit about folder handling by ROOT.

I am doing a cut-based analysis where I would like to fill a set of histograms h1, h2, h23… from a TTree under different selection criteria (cuts).
Further, I would like to store the set of filled histograms in different folders in a ROOT file depending on the selection criteria.

Is there a way in which I can simultaneously (within a single event loop) fill the same set of histograms in different folders, depending on the cuts passed by the event?

I hope I have been able to convey my point. If not can try with a simple pseudo-code to demonstrate what I want to do.

Best regards,

Devdatta.

Yes this is possible.
-create your directory structure and your histograms inside these directories.
-store the pointers to histograms as class members or global vars
-fill your selected histograms in the event loop

Rene

Hi Rene,

That means if I have N cuts and M histograms,
I need to include N*M histogram pointers in my class?

Or perhaps is it better to have a separate class containing the histograms and method to initialize the class for each subdirectory I create?

In that case, I suppose the subdirectory will own the class object and the histograms will exist until the program exits and I can have only one
outfile_->Write()
kind of statement n the base class’s destructor?

Thanks and best regards,

Devdatta.

[quote]In that case, I suppose the subdirectory will own the class object and the histograms will exist until the program exits and I can have only one
outfile_->Write()
kind of statement n the base class’s destructor? [/quote]That is correct.

[quote]That means if I have N cuts and M histograms,
I need to include N*M histogram pointers in my class? [/quote]You might be better of having a collection of pointer (for example a TObjArray pointing to the histograms).

Cheers,
Philippe.