Segmentation violation with graph


ROOT Version: 6.22
Platform: Linux
Compiler: Not Provided


Hey all,

I’m currently running a program that has two histograms, one of which I draw a fit graph on. The first time I run it, it works fine, but if I try to load the macro again I get a segmentation violation error. When I quit root, I further get an error saying “double free or corruption (!prev)”. This only happens when I add the fit graph; without it, the code runs fine. Here’s the code in charge of graphing:

//create canvas
	auto c = new TCanvas("Z Boson Data", "Z Boson Data", 1200, 600);
	c->Divide(1, 2);

	//graph mass histogram and fit Breit-Wigner to it
	c->cd(1);
	TF1 *func = new TF1("mybw",mybw,mass_bound_low, mass_bound_high, 3);
	func->SetParameter(1, resonance_width); //get gamma/resonance width for parameter 1
	func->SetParameter(2, mass_hist->GetMean()); //get M/Z mass for parameter 2
	auto mass_fit = mass_hist->Fit("mybw", "QR");
	//mass_fit->DrawClone("Same");
	mass_hist->DrawClone("Same");

	//graph momentum histogram
	c->cd(2);
	p_hist->DrawClone("Same");

I’m not double-freeing any of these graphs with a delete statement, so I don’t know why I would be getting such an error.

Any help would be appreciated!

Why DrawClone and not simply Draw ?

I tried with this code:

// t.cxx
double mybw(double *px, double p[3]) {
  double x = *px;
  return x + p[0] + x*p[1] + x*x*p[2];
}

void t() {
  auto mass_hist = new TH1F("mass_hist", "mass_hist", 10, 0., 1.);
  mass_hist->Fill(0.21, 20);
  auto c = new TCanvas("Z Boson Data", "Z Boson Data", 1200, 600);
  c->Divide(1, 2);

  //graph mass histogram and fit Breit-Wigner to it
  c->cd(1);
  TF1 *func = new TF1("mybw",mybw,0.1, 1., 3);
  auto mass_fit = mass_hist->Fit("mybw", "QR");
  mass_hist->DrawClone("Same");

  //graph momentum histogram
  c->cd(2);
  auto p_hist = new TH1F("p_hist", "p_hist", 10, 0., 1.);
  p_hist->DrawClone("Same");
}
$ root
root [0] .x t.cxx
root [1] .x t.cxx
root.exe: /home/axel/build/root/master/src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1519: void cling::Interpreter::unload(cling::Transaction&): Assertion `!T.getTopmostParent()->getNext() && "Can not revert previous transactions"' failed.

So there’s indeed a problem. Is this comparable to what you run in reality?

The code is comparable, but the error message is not. My error message tells me that there was a segmentation violation, that root crashed, and gives me a “stack trace of all threads.”

We will need code that reproduces this issue. Could you share that with us?

I’m using DrawClone because I’ve had problems with the graph where if I don’t use DrawClone, then the p_hist histogram simply won’t display. This is also something that wasn’t a problem before I used the fit graph.

As @Axel requested, can you post the code reproducing your problem ?

Sorry for taking so long to respond, here’s my code!
zboson_pt.C (6.3 KB)