Compare TGraphs from several ROOT files


I’m a root beginner, and I would like to ask for help with the following. I want to open two or several root files where I have stored TGraphs and compare them by drawing them on the same canvas. Could you please give me some advice or a basic code on how to do this? I appreciate the help.


To plot them together it’s better to use a TMultiGraph; something like:

  // do similarly for all files/graphs:
  TFile *f1 = new TFile("file1.root");
  TGraph *g1 = (TGraph*)f1->Get("graph1");  // supposing file1.root contains graph1
  // ... (f2, g2, etc.)

  // then add all graphs to a multigraph and draw it:
  TMultiGraph *mg = new TMultiGraph();
  // ...

Drawing options here:

Hi, thank you so much for your answer! I just have one more question. Unfortunately, when I try to run a macro I’m getting this error:

error: no matching member function for call to ‘Add’



/usr/local/Cellar/root/6.26.06_1/include/root/TMultiGraph.h:53:22: note: candidate function not viable: no known conversion from ‘const char [4]’ to

‘TGraph *’ for 1st argument

virtual void Add(TGraph *graph, Option_t *chopt=“”);

I tried several solutions including the root suggestion, but none of them seems to work. Can you tell me if you see something? Thanks.

Sorry, there were extra quotes in Add (should be Add(g1) etc.); now it’s corrected.

Thanks again for your answer. I already tried that, but I’m getting:

*** Break *** segmentation violation

every time. I don’t know why.

It looks like your graph was not found in your file.
You can try: if (g...) mg->Add(g...);
Try also: rootls -l yourfile.root