Problem with axis labels in TGraphAsymmErrors

Hi,

I an generating a TGraphAsymmErrors with BayesDivide(histo1,histo2). I then write out the TGraph to a TFile. I read in the TFile using a separate program. Read in the TGraph and plot it on a canvas. Everything works fine except that the x and y-axis labels are no longer present. If I instead plot the TGraph on a canvas before writing it out to a TFile it still has the axis labels. Is it possible to keep the axis label information in the TGraph while writing it to a root file? I appreciate any help I can get with this.

Thanks and Best Regards,
Sinéad

Using ROOT 5.26/00
Code to create TGraph and write to rootfile :
TGraphAsymmErrors *eff_g = new TGraphAsymmErrors();
eff_g->SetName((“Eff_”+filt_name).c_str());

eff_g->BayesDivide(filt_h, all_h);

outfile->cd();
outfile->Cd(output_dir_name.c_str());
eff_g->Draw("APz");
eff_g->GetYaxis()->SetTitle("Efficiency");
eff_g->GetXaxis()->SetTitle(filt_h->GetXaxis()->GetTitle());
eff_g->Write();
std::cout << "Xaxis: " << eff_g->GetXaxis()->GetTitle() <<std::endl; //Check to make sure eff_g has the correct Xaxis title. It does.

Code to read in TGraph and draw on TCanvas:
TGraphAsymmErrors graph = new TGraphAsymmErrors(((TGraphAsymmErrors *) file->GetDirectory((directory_name).c_str())->Get((*graph_name).c_str())));

std::cout << "Xaxis: " << graph->GetXaxis()->GetTitle() << std::endl; //Outputs empty string

		 	TCanvas * c1 =new TCanvas("c1","TEST");	
			c1->cd();
			graph->Draw("APz"); //The graph is drawn and looks good. Its just missing the axis labels
			c1->SaveAs("TEST.eps");
			c1->Write();

I cannot reproduce your problem. With the latest ROOT version (on linux) I created a graph with two titles (on x and y axis), I save the graph in a ROOT file, exit ROOT, come back in ROOT, open the previously created file, draw the graph inside this file, the axis titles are there.

Hi,

Thanks for the quick reply. Are you using 5.27/02 ? I tried using the script below in 5.26/00 and Xaxis OUT (the axis label on the tgraph written out) shows the right label while Xaxis IN (label on tgraph read in) shows nothing. It then segfaults but the text output can be seen before that.

Sinéad

#ifndef __CINT__
#include "TGraph.h"
#include "TGraphAsymmErrors.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TH1F.h"
#include "TFile.h"
#include <iostream>
#endif


void test_axis_label()
{
	TFile *outfile = new TFile("TESTING_outfile.root", "RECREATE");


	TH1F all_histo("all_histo", "all entries", 3,0,3);
	TH1F sub_histo("sub_histo", "subset", 3,0,3);

	all_histo.SetBinContent(1,3);
	all_histo.SetBinContent(2,8);
	all_histo.SetBinContent(3,5);

	sub_histo.SetBinContent(1,2);
	sub_histo.SetBinContent(2,3);
	sub_histo.SetBinContent(3,1);


	TGraphAsymmErrors *eff_g = new TGraphAsymmErrors();

	eff_g->SetName("TESTING_axis");

	eff_g->BayesDivide(&sub_histo, &all_histo);

	outfile->cd();
	outfile->mkdir("Dir");
	outfile->Cd("Dir");
	eff_g->Draw("APz");
	eff_g->GetYaxis()->SetTitle("Efficiency");
	eff_g->GetXaxis()->SetTitle("The Xaxis");
	eff_g->Write();

	std::cout << "Xaxis OUT: " << eff_g->GetXaxis()->GetTitle() <<std::endl; 

        outfile->Write();
        outfile->Close();
        delete outfile;
        outfile = NULL;


	TFile *file = new TFile("TESTING_outfile.root","open");


	TGraphAsymmErrors *graph = new TGraphAsymmErrors(*((TGraphAsymmErrors *) file->GetDirectory("Dir")->Get("TESTING_axis")));

	std::cout << "Xaxis IN: " << graph->GetXaxis()->GetTitle() << std::endl; //Outputs empty string

	TCanvas * c1 =new TCanvas("c1","TEST");
	c1->cd();
	graph->Draw("APz"); //The graph is drawn and looks good. Its just missing the axis labels
	c1->SaveAs("TEST_TGraph.eps");

	file->Close();
        delete file;
        file = NULL;


}

You macro crashes. I get:

[quote]Processing test_axis_label.C…
TCanvas::MakeDefCanvas: created default TCanvas with name c1
Xaxis OUT: The Xaxis
Xaxis IN:
Warning in TCanvas::Constructor: Deleting canvas with same name: c1
Info in TCanvas::Print: eps file TEST_TGraph.eps has been created

*** Break *** segmentation violation

===========================================================
There was a crash (kSigSegmentationViolation).
This is the entire stack trace of all threads:

#0 0x00a3b7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x03e86553 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2 0x03e2f819 in do_system () from /lib/tls/libc.so.6
[/quote]

so I need more time to investigate … first I should understand why it crashes…:frowning: