Get tgraph from tmulltigraph

Hello everyone,

I would appreciate a feedback on the following problem

I have a canvas c_FAD, which has a tmultigraph mg_FAD. Only one tgraph is added to this tmultigraph, with name gr_FAD. I can extract the canvas from the root file as

TCanvas cfr = (TCanvas)fr.Get(“c_FAD”);

now how shall I proceed to extract the tgraph gr_FAD ?

thanks

If you have a canvas (from a file) ask its list of primitives:

canvas->GetListOfPrimitives()

and now

if you know the name, or, if you don’t - iterate through this list searching for your multigraph, as it’s found request a graph from this multigraph

Thanks for replying, I am trying to list the object stored in the Tlist cfr->GetListOfPrimitives()

These are following results

root [17] cfr->GetListOfPrimitives().Last()
(const class TObject*)0x2585440
root [18] cfr->GetListOfPrimitives().First()
(const class TObject*)0x24cf9f0

these are certainly not the object name, I get the following for
cfr->ls()

root [16] cfr->ls()
Canvas Name=c_FAD Title=C_FAD Option=
TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= c_FAD Title= C_FAD Option=
OBJ: TList TList Doubly linked list : 0
TFrame X1= 5.474600 Y1=-0.482048 X2=14.067800 Y2=1.384664
OBJ: TMultiGraph FAD distribution(LHV); #rho; FAD (Mpc^{-3} Myr^{-1}) : 1 at: 0x24dc570
OBJ: TPaveText title X1= 7.319623 Y1=1.466953 X2=11.776962 Y2=1.611028
OBJ: TLegend TPave X1= 11.664891 Y1=0.993296 X2=14.037124 Y2=1.379108

I am little confused, can you please make it a little more accessible

You should use GetListOfGraphs. It returns the list of TGraph (as a TList) in the TMultiGraph.

  1. You obtain a canvas object from your file.
  2. You request a list of primitives from this canvas object.

If you know the name of your tmultigraph, you:
3. Obtain this multigraph from the list of primitives you got on step 2.
or
4. You iterate over this list of primitives, searching for a TMultiGraph object
(you can ask object, if it has the right type: obj->InheritsFrom(“TMultiGraph”))

  1. If you got a TMultiGraph, you ask for a graph.

I am still wondering how to print this list in the first place ?

[7] cfr->GetListOfPrimitives()
(const class TList*)0x277d260

how should I print the object listed in the above tlist ?

cfr->GetListOfPrimitive()->Print()

Thanks. I managed to get my plot done. All thanks to you.

A major source of confusion was that TMultigraph had no name, so I used “”. By the way if you feel inclined can you also suggest how to extract all the Tgraph from TMultiGraphs, Getgraphlist only tells the graph name…

TMultiGraph::GetListOfGraphs returns a list of TGraphs, you can iterate over this list.