How to increment/update existing hitstograms in a ROOT File

ROOT Version: 6.24/00
Platform: 5.12.13-300.fc34.x86_64
Compiler: gcc version 11.1.1 20210531 (Red Hat 11.1.1-3) (GCC)


Hello,

I have a ROOT File (say, “test.root”) which contains several histograms. I open it in UPDATE mode as follows:

TFile *f = new TFile("test.root", "UPDATE");

Then I process some events from the second data file and try to update/increment contents of the existing histograms.
Finally, I do the following:
f->cd(); f->Write("",TObject::kOverwrite); f->Close(); delete f;
With this method, I am unable update the histograms. They always show events only from the second data file.

What am I missing? Can you please help?

Ajay

Did you load the histograms from the file before adding new date to them (and then over-writing the content)?

I just open a file, which has histograms (around 100) in it.
I am not sure whether I understood when you say “load the histogram”.

What is the best way to load 100 histograms (with names not-so-easy to generate in a for loop ), if I have to?

@pcanal Can you please guide further?

How do you create the histograms? (reading the existing histograms is simply type_of_histo *hist = file->Get<type_of_histo>(name_of_histo); )

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