Misplaced TH1D errors

Hi!

Can you please help me understand what I am doing wrong here?

If I run this macro

void test (string input) {

	Double_t xf, yf, dyf(0);
	vector<Double_t> x, y, dy;
	string line;
	Int_t point = 0;
		
	TCanvas *c = new TCanvas("a", "b", 600, 400);
	gStyle->SetOptStat(false);
	
	TH1D *hist;
	gPad->SetLogx();
	gPad->SetLogy();
	
	ifstream fileInput (input.c_str());
	while (getline(fileInput, line)) {
		if (line[0] == '#' || line[0] == '\0') continue;
		
		stringstream(line) >> xf >> yf >> dyf;

		x.push_back(xf);
		y.push_back(yf);
		dy.push_back(dyf);
	}
	
	x.insert(x.begin(), 0);
	
	hist = new TH1D("h1", "", y.size(), (Double_t * ) &x[0]);
	
	for (size_t l = 0; l < y.size(); l++) {
		hist->SetBinContent(l + 1, y[l]);
		hist->SetBinError(l + 1, dy[l]);
	}
	
	hist->Draw("HIST E0");
	
	x.clear();
	y.clear();
	dy.clear();
	
	return;
}

using this input file a.txt (7.6 KB)

I get this result:

a

Why are the error bars completely misplaced?

I updated my root version to:

ROOT Version: 6.20/04
Built for linuxx8664gcc on Apr 01 2020, 08:28:48
From tags/v6-20-04@v6-20-04

I’ve been using the very same macro and similar input files for months and have never had this weird behaviour before.

What am I doing wrong?

Oh, ok.

Thank you!

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