How can I access the object afterword which is appended to another object? Following examle appended TGraph object tg was appended
to testhist object. I would like to access TGraph object afterword when
I open the test.root.
main(){
TFile * rootfile = new TFile(“test.root”,“RECREATE”,“ROOT Histogram file”);
TH2F * testhist = new TH2F(“testhist”,“test histo”,100,-1,1, 100,-10,10);
TGraph * tg = TGraph(N,x,y);
testhist->GetListOfFunctions()->Add(“tg”);
rootfile->Write();
rootfile->Close();
}
root [] TFile * file = TFile::Open(“test.root”);
root [] testhist->GetListOfFunctions() -> FindObject(“tg”);
seems doesn’t work.
brun
December 5, 2006, 8:37pm
2
You should do instead:
TH2F * testhist = new TH2F("testhist","test histo",100,-1,1, 100,-10,10);
TGraph * tg = TGraph(N,x,y);
tg->SetName("tg");
testhist->GetListOfFunctions()->Add(tg);
int
main(){
Float_t x[5]={1,2,3,4,5};
Float_t y[5]={10,20,30,40,50};
TFile * rootfile = new TFile(“test.root”,“RECREATE”,“ROOT Histogram file”);
TH1F * testhist = new TH1F(“testhist”,“test histo”,100,-10,10);
TGraph* tg = new TGraph(5,x,y);
tg->SetName(“tg”);
testhist->GetListOfFunctions()->Add(tg);
rootfile->Write();
rootfile->Close();
return 0;
}
root [] TFile * file = TFile::Open(“test.root”);
root [] TGraph * tmp = (TGraph*) testhist -> GetListOfFunctions()->FindObject(“tg”);
root [] Float_t * y = tmp->GetY();
root [] cout << y[0] << " " << y[1] << " " << y[2] …
0 0.1875 0 2 …
Somehow I still cannot access to the right address to reproduce contents
of arrays.
brun
December 6, 2006, 6:36pm
4
The TGraph constructors accept float* and double* arrays, but internally
they are stored as double only.
So, in your reading session, replace
Float_t *y=tmp->GetY();
by
Rene