Storing multiple TMultiGraphs to a root file

I have a macro that produces 7 canvases with TMultiGraphs, I would like to store these graphs to a .root file somehow. I tried the documentation I found online, but somehow it still returns me lots of errors when I try to load the produced .root file. Is it possible to store multiple TMultiGraphs? And if yes, would someone be so kind as to point out what I am doing wrong :wink: The macro works fine and produces the graphs I need.
v2all.C (6.6 KB)

Some stat file are missing to run your macro:

Processing v2all.C...
Error in <TGraphErrors::TGraphErrors>: Cannot open file: ~/macros/v2pions1.txt, TGraphErrors is Zombie
Error in <TGraphErrors::TGraphErrors>: Cannot open file: ~/macros/v2kaons1.txt, TGraphErrors is Zombie
Error in <TGraphErrors::TGraphErrors>: Cannot open file: ~/macros/v2protons1.txt, TGraphErrors is Zombie

That is because I didn’t want to overdose the forum with 21 .txt files. It
works just fine and I thought I’d put the macro up there just to see what
it is I wrote. Should I put an example .txt file up here?

Yes even some reduce form would help. It is better is we can run the macro to understand where the problem is. Now we cannot run it.

Thank you very much for looking into it. I rewrote the macro so it will just give the same graphs 7 times, so it only takes 3 .txt files as an example.
v2red.C (6.6 KB)
v2pions1.txt (1.9 KB)
v2kaons1.txt (1.5 KB)
v2protons1.txt (1.9 KB)

I ran you macro. it generates a root file. which contains:

$ root  v2all.root
  | Welcome to ROOT 6.11/03           |
  |                                   (c) 1995-2017, The ROOT Team |
  | Built for macosx64                                             |
  | From heads/master@v6-11-02-436-ge313df3, Oct 27 2017, 10:15:49 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |

root [0] 
Attaching file v2all.root as _file0...
(TFile *) 0x7fa5310d8f50
root [1] _file0->ls()
TFile**		v2all.root	
 TFile*		v2all.root	
  KEY: TMultiGraph	0To1;1	v2 vs P_{t} for centrality 0-1%
  KEY: TMultiGraph	0To5;1	v2 vs P_{t} for centrality 0-5%
  KEY: TMultiGraph	5To10;1	v2 vs P_{t} for centrality 5-10%
  KEY: TLegend	leg3;1	Legend of markers/lines/boxes to represent obj's
  KEY: TMultiGraph	10To20;1	v2 vs P_{t} for centrality 10-20%
  KEY: TMultiGraph	20To30;1	v2 vs P_{t} for centrality 20-30%
  KEY: TMultiGraph	30To40;1	v2 vs P_{t} for centrality 30-40%
  KEY: TMultiGraph	40To50;1	v2 vs P_{t} for centrality 40-50%

Where ? how ?

The only problem I see is that you named you Mutilgraph wrongly… the names should not start with digits. That’s not legal C++:

root [2] 10To20->Draw()
ROOT_prompt_2:1:3: error: invalid suffix 'To20' on integer constant
root [3] 

Thank you for your time, it was my mistake I tried to read the file the wrong way! It works now after I’ve changed the names.

It does look very awkward, it looks very zoomed in and axes etc are missing. I am (obviously) quite new to ROOT, is there a way to save the axes, graph title etc? Or do I need to save the canvas if that is what I want?

can you post the new macro ?

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