How to append a new data into an existing ROOT file


I’m a new member and also new with ROOT. I have a problem that I have tried to google it, but I dont find the solution.

I want to make a C++ program that make plots in time evolution (per day). So everytime you give a new input, it makes one plot. The input file is in ascii format, but for research purpose the output file must be in ROOT.

So, I want my program does like this:

  1. Open a ROOT file,
  2. Load the histograms from the previous data into the memory,
  3. Add new data from a new input file,
  4. Save it.

I use command TFile f(“thefile.root”, “recreate”) and in the end use f.Write() and f.Close(). (I also have tried “update” option.)

But, everytime I give a new input, the program always destroy the previous histogram and only plot the latest one.

I hope I describe my problem clearle and seek help from the comunity. Thank you very much.

Maybe this help (hsimple.root from $ROOTSYS/tutorials/hsimple.C)

void update() { TFile file("hsimple.root","update"); TH1F *histo = (TH1F *)file.Get("hpx"); histo->FillRandom("gaus"); // "Add new data from a new input file" file.Write("",TObject::kOverwrite); file.Close(); }