GetHistogram inside user defined function -> error

Hi,
What’s wrong with this code?

I get a " *** Break *** segmentation violation" error message at the GetHistogram() line.

testfunc.cxx:

double func(double * x, double * par){
TF1 * gaus = new TF1(“gaus”,"(1/[0])(exp(-0.5((x-[1])/[0])**2))", -5, 5);
gaus->SetParameter(0, par[0]);//sigma
gaus->SetParameter(1, par[1]);//mean
TH1D * gaus_histo = gaus->GetHistogram();
TAxis * xaxis = gaus_histo->GetXaxis();
double value = gaus_histo->GetBinContent(xaxis->FindBin(x[0]));
return value;
}

int main(){
TF1 * totalfunc = new TF1(“totalfunc”, func, -5, 5, 2);
totalfunc->SetParameter(0, 1);
totalfunc->SetParameter(1, 0);
TFile * file = new TFile(“testfunc.root”, “recreate”);
totalfunc->Write();
file->Close();
return 0;
}

Thanx,

Balint

I cannot reproduce the problem with your example.
Unfortunately you do not indicate which version you are using.
In case you use an old version, test your example with a more recent version
such as 4.04/02 or newer.

Rene

I am using ROOT 4.00/06 with gcc (GCC) 3.2.2.

Here is a more simple code for this problem:

test.cxx:

#include <TF1.h>
#include <TH1D.h>
#include <TFile.h>

int main(){
TF1 * gaus = new TF1(“gaus”,"(1/[0])(exp(-0.5((x-[1])/[0])**2))", -5, 5);
gaus->SetParameter(0, 1);
gaus->SetParameter(1, 0);
TH1 * gaus_h = gaus->GetHistogram();
TFile * f = new TFile(“testgethisto.root”, “recreate”);
gaus_h->Write();
f->Close();
return 0;
}

My previous comment remains valid:

[quote]In case you use an old version, test your example with a more recent version
such as 4.04/02 or newer.
[/quote]
Rene

[quote=“brun”]My previous comment remains valid:
In case you use an old version, test your example with a more recent version
such as 4.04/02 or newer.
Rene[/quote]

You win! It works now with 4.04/02b. Thanx,

Balint