Saving TMultiGraph as TH1


The title says it all

How can I save a multigraph as TH1 in order to combine several TH1 at a later stage ? I see something like

but I could not get it work… Can you plz provide an example ?

Thanks and sorry for the naive question!

TMuligraph is only a collection of TGraph you can plot together in order to have a common coordinate system to all of them. I am not sure what you mean by “Saving a TMultiGraph as a TH1”. Would that mean getting the individual points of each graphs in the TMultiGraph and fill a TH1 with the data you get ? In that case it is just a matter of looping over all the TGpahs in the TMultigraph. Can you clarify a bit ? do you have some prototype macro showing what you are aiming for ?

(note that SavePrimitive() is not for that purpose.)

After filling several TGraphs like

So, how could I save the multigraph as an TH1 ? Also, saving each gr[k] ONCE it is filled would do just fine as well

Thanks a lot!

Why don’t you save the TMultigraph directly ?
Why do you want to save it “As a TH1” ?


So, if I just


will it be possible to just after having saving 2 different multigraphs (each one consisting of several TGraph) to put them in the same canvas ?

Can you give an example ? (I guess with the SavePrimitive, but how to use it ? )

If you have several multigraphs (e.g. “mg1”, “mg2”. “mg3”, for each of them you needed to call “mg…->Write()” in order to save them in a file), you can create another multigraph (e.g. “mall”) to which you can “Add” all your existing multigraphs (e.g. “mall->Add(mg1); mall->Add(mg2); mall->Add(mg3);”, note that the order matters) and then “Draw” your new multigraph (e.g. “mall->Draw();”).
See for details.
Unless what you wanted was just: mg1->Draw(); mg2->Draw(“SAME”); mg3->Draw(“SAME”);
See and/or and/or for details.