Displaying and Saving Histograms

Hello,

I’m very confused by the behaviour of my root macro.

The relevant piece of code is below:

		length = x_values.size();
		TCanvas *canvas_1 = new TCanvas("canvas_1","Canvas One",1);
		canvas_1->Divide(2,1);
		canvas_1->cd(1);
		canvas_1->SetFillColor(kWhite);
		TH1F *histo1 = new TH1F("histo1","To Be Changed",length,lower_x_limit,upper_x_limit);
		histo1->SetLineColor(kBlack);
		gStyle->SetEndErrorSize(np=3);
		gStyle->SetOptStat("");
		histo1->SetMarkerStyle(1);
		histo1->SetMarkerColor(kBlack);
		x_axis_title_s = x_axis_title_s.substr(1, (x_axis_title_s.length() - 2));
		y_axis_title_s = y_axis_title_s.substr(1, (y_axis_title_s.length() - 2));
		cout << x_axis_title_s << endl;
		const char* x_axis_title_c = x_axis_title_s.c_str();
		const char* y_axis_title_c = y_axis_title_s.c_str();
		histo1->GetXaxis()->SetTitle(x_axis_title_c);
		histo1->GetYaxis()->SetTitle(y_axis_title_c);
		histo1->GetXaxis()->SetTitleOffset(1);
		histo1->GetYaxis()->SetTitleOffset(1.2);
		histo1->SetTitle("");
//		histo1->Draw("hist, E1");
		histo_title = TPaveText(0.34, 0.9, 0.65, 0.99, "NDC");
		histo_title.SetFillColor(0);
		top_title_s = top_title_s.substr(1, (top_title_s.length() - 2));
		const char* top_title_c = top_title_s.c_str();
		line_one = histo_title.AddText(top_title_c);
//		histo_title.Draw("same");
		canvas_1->cd(2);
		histo_info = TPaveLabel(0.34, 0.9, 0.65, 0.99);
		histo_info.SetFillColor(0);
		title_a = title_a.substr(1, (title_a.length() - 2));
		const char* title_a_c = title_a.c_str();
		title_b = title_b.substr(1, (title_b.length() - 2));
		const char* title_b_c = title_b.c_str();
		title_c = title_c.substr(1, (title_c.length() - 2));
		const char* title_c_c = title_c.c_str();
		line_a = histo_info.AddText(title_a_c);
		line_b = histo_info.AddText(title_b_c);
		line_c = histo_info.AddText(title_c_c);
//		histo_info.Draw();
		cout << "here9" << endl;
		if (scale == "LOG")
			{
			canvas_1->SetLogy(1);
			}
		while (index_count < length)
			{
			histo1->Fill(x_values[index_count],y_values[index_count]);
			histo1->SetBinError(index_count, dy_values[index_count]);
			index_count++;
			}
		index_count = 0;
		TFile *new_root_file = new TFile("new_root_file2.root","RECREATE");
//		canvas_1.Update();
		canvas_1->Write();
		new_root_file->Close();
		cout << "here10" << endl;

I’ve not included all of the code because its just data processing and fairly long and irrelevant to my problem.
Full code is attached and does run. Nb wjjb1.txt needs to be renamed as wbbj1.top and final2.txt needs to be renamed as final2.C

Each time I run the macro it displays the histogram, which I dont want it to do. I just want it to save them to a file. I also want the canvas to be split into 2 with a text box detailing information in the lower segment. Currently this isnt happening and I dont know why. Ive looked at the tutorials concerning this topic and think that the way that I’m doing it should be fine.

Any help would be greatly appreciated.

Many Thanks,

Geoff Herbert
wbbj1.txt (5.15 KB)
final2.txt (6.41 KB)

With your macro I get:

Warning: Automatic variable np is allocated final2.C:192:
ALPGEN, Mon Jun 21 10:58:57 2010
Warning: Automatic variable histo_info is allocated final2.C:214:
Error: Undeclared variable histo_info final2.C:214:
*** Interpreter error recovered ***

 *** Break *** segmentation violation

start root with the option -b (batch mode).