Hi all,
how to write a TGraphErrors on a ROOT file?
I write:
TFile *file = new TFile("file.root","RECREATE");
TGraphErrors *gr = new TGraphErrors(n,x,y,error_x,error_y);
file->Write();
but I have not result. Where is my error?
Thanks and best regards
Ciccio
Hi Ciccio,
see page 164 (Saving Objects to Disk) from ftp://root.cern.ch/root/doc/chapter11.pdf file->WriteTObject(gr);
Jan
Hi Jan,
thank you for your answer.
Now I have a root_file with a graph, but this graph is empty.
If I write:
root [0] gr->Draw("AP")
I obtain the graph, but if I open the TBrowser and click on the “gr”, I obtain an empty canvas.
What I must do?
Best regards
Ciccio
P.S.: Sorry for my English
couet
4
That’s weird. Do you have a small macro showing the problem ?
the macro is:
{
gROOT->Reset();
#include "Riostream.h"
Int_t n=3;
Int_t x[n]={1,2,3};
Int_t y[n]={1,2,3};
TFile *f = new TFile("file.root","RECREATE");
TGraph *gr1 = new TGraph(n,x,y);
gr1->SetMarkerStyle(7);
gr1->GetXaxis()->SetTitle("X");
gr1->GetYaxis()->SetTitle("Y");
f->WriteTObject(gr1);
}
but I have noticed that if I write:
root [0] gr->Draw()
I obtain the same risult: an empty canvas. Must I insert an option in “WriteTObject”?
couet
6
It works perfectly for me. I ran:
{
Int_t n=3;
Int_t x[n]={1,2,3};
Int_t y[n]={1,2,3};
TFile *f = new TFile("file.root","RECREATE");
TGraph *gr1 = new TGraph(n,x,y);
gr1->SetMarkerStyle(7);
gr1->GetXaxis()->SetTitle("X");
gr1->GetYaxis()->SetTitle("Y");
gr1->Draw("AC");
f->WriteTObject(gr1);
}
it shows a graph. Then I exist ROOT and do:
root [0] TFile f("file.root");
root [1] Graph->Draw("AC")
and it displays the same graph.
Do you have the graph also from the TBrowser?
couet
8
In the browser, in the “option” menu choice (top right) select “alp”.
YOU ARE BIG!!!
Thank you very much, now I view all graph.
Thank you
Ciccio