Home | News | Documentation | Download

How to prevent new histograms from being written to an opened ROOT file?

In an analysis, I am creating a set of intermediate histograms that I don’t intend to save, and from them a smaller set of histograms that are the result I that would like to save in a ROOT file.

When I open a ROOT file for writing (e.g. as “RECREATE”), all new histograms are written to it whether or not I would like to save them. How do I prevent all new histograms from being saved?

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.20/04
Platform: CentOS 7
Compiler: Not Provided

histograms are automatically associated with the “current file” (i.e. gDirectory) when they are constructed.
Calling histo->SetDirectory(nullptr) “disassociates” the histogram from its TFile.
To change the behavior for all histograms, you can call TH1::AddDirectory(false) (see docs).

Hope this helps!

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