Draw("same") to root file

I have a set of TGraphs which I draw on the same canvas with "same" and which I want to write to a .root file. I’m currently calling Write() on the canvas which works, but when I open the canvas from the TBrowser it opens a new window, which I would prefer it didn’t.

How can I save the superposition of all the "same"s of the TGraphs as a graph itself instead of saving the canvas?

TGraph* MyGraphs[nGraphs];
  for (int i=0; i<nGraphs; i++){
    MyGraphs[i] = new TGraph(4);
    for (int j=0; j<4; j++) { 
      MyGraphs[i]->SetPoint(j,pzx[j][i].X(),pzx[j][i].Y());
    }
  }
  TCanvas* cfingerGraph = new TCanvas("fingerGraph");
  cfingerGraph->SetWindowSize(600,600);
  cfingerGraph->DrawFrame(
			 PVetoCenter.Z()-0.5*PVetoSize.Z(),
			 PVetoCenter.X()-0.5*PVetoSize.X(),
			 PVetoCenter.Z()+0.5*PVetoSize.Z(),
			 PVetoCenter.X()+0.5*PVetoSize.X());

    cfingerGraph->Write();

_ROOT Version: 5
_Platform: centos7

https://root.cern/doc/v608/classTMultiGraph.html

As you are using ROOT version 5 you might want to see the corresponding reference guide.

Complete solution for future reference:

TMultiGraph * myMultiGraph = new TMultiGraph("name","title");
TGraph* MyGraphs[nGraphs];
  for (int i=0; i<nGraphs; i++){
    MyGraphs[i] = new TGraph(4);
    for (int j=0; j<4; j++) { 
      MyGraphs[i]->SetPoint(j,pzx[j][i].X(),pzx[j][i].Y());
      myMultiGraph->Add(MyGraphs[i]);
    }
  }
  myMultiGraph->Draw("AP");
  myMultiGraph->GetXaxis()->SetTitle("X title");
  myMultiGraph->GetYaxis()->SetTitle("Y title");
  myMultiGraph->Write();

You put the line …

myMultiGraph->Add(MyGraphs[i]);

… inside the loop on j. This means you are adding the same graph 4 time in the multigraph. I guess you should put this line after or before the j-loop

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