What can cause a segmentation fault in TH1::Fit?

I am trying to use ROOT to fit curves on a cluster. When I run my program on the interactive node, everything works correctly. However, when I run my program on the computation nodes, I get a segmentation fault when I call :

As I said, the parameters are all correct, since it works well on the interactive node.

The error I’m getting is this :
*** Break *** segmentation violation
Generating stack trace…
0x40e132db in TH1::Fit(char const*, char const*, char const*, double, double) + 0x1a7 from /opt/root40402/lib/libHist.so
0x0804c6d2 in from ./JJSimulator.out
0x0804bd9c in from ./JJSimulator.out
0x415a1748 in __libc_start_main + 0xf8 from /lib/tls/libc.so.6
0x08049ba1 in operator new(unsigned int) + 0x41 from ./JJSimulator.out
/var/spool/torque/mom_priv/jobs/7343.ss1.ms.SC: line 10: 18182 Aborted ./JJSimulator.out

Is there something in the ROOT installation on the cluster that can produce such fault ? For example, the fact that they are computation nodes, they don’t have UI interface…

Thank you,

Maxime Boissonneault

-indicate which version of ROOT
-send the shortest possible running script showing the problem


double computeFWHM(TH1D * histo) {
//on trouve le maximum
Double_t max = histo->GetMaximum();
Int_t maxbin = histo->GetMaximumBin();
Double_t xmax = histo->GetBinCenter(maxbin);

    //on trouve le point milieu du cote gauche
    Double_t max_2_L = histo->GetMaximum(max/2.0);
    Int_t maxbin_2_L;
    Double_t xmax_2_L;
    for (int i=0; i<histo->GetNbinsX() && i<maxbin; i++) {
            if (histo->GetBinContent(i) == max_2_L)
                    {       maxbin_2_L = i;         break;          }
    xmax_2_L = histo->GetBinCenter(maxbin_2_L);

    Double_t a,b,c;
    //on fait un fit quadratique du cote gauche
    TF1 * poly2L = new TF1("Poly2L",poly2,0,histo->GetBinCenter(histo->GetNbinsX()),3);
    Double_t penteL = (histo->GetBinContent(maxbin_2_L)-histo->GetBinContent(maxbin_2_L+1)) / (xmax_2_L - histo->GetBinCenter(maxbin_2_L+1));

    cout << histo->GetBinCenter(maxbin_2_L-2) << endl;
    cout << histo->GetBinCenter(maxbin_2_L+2) << endl;

    //on calcule le xmax_2_L reel
    a = poly2L->GetParameter(0);
    b = poly2L->GetParameter(1);
    c = poly2L->GetParameter(2) - max/2.0;
    Double_t xmax_2_LR = (-b + sqrt(b*b-4*a*c))/(2*a);
    delete poly2L;

    ..... //here is the same algorithm, but for the right side instead of the left one

Double_t poly2(Double_t *x, Double_t *p) {
Double_t a = p[0];
Double_t b = p[1];
Double_t c = p[2];

    return a*x[0]*x[0] + b*(x[0]) + c;


I know there already are polynomial functions, but I wanted to be as independent as I could, to reduce the number of problems to the minimum.

The function computeFWHM computes the Full Width at Half Maximum. The algorithm is this one : I find the bin with the maximum height (max), then, on both sides of it, I find the bin which’s height is the closest to max/2. Finaly, I perform a 2nd order polynomial fit with the bins around them to get the “true” position of the half maximum.

The program give me a segmentation fault when the Fit function is executed.

My system admin installed ROOT Version 4.04/02 30 May 2005

Thank you

Maxime Boissonneault


Please send teh shortest possible RUNNING script showing your problem


I joined the code to this message.
Here is the lined I used to compile it :
g++ -O2 testError.cpp -o testError.out -I/opt/root40402/include/ -L/opt/root40402/lib/ -lCore -lCint -lGui -lGpad -lHist -lGraf -lMatrix

Here is the output I get when I run it on the cluster :

Histogram filled
Histogram scaled

*** Break *** segmentation violation
Generating stack trace…
0x40e132db in TH1::Fit(char const*, char const*, char const*, double, double) + 0x1a7 from /opt/root40402/lib/libHist.so
0x08048d1f in __gxx_personality_v0 + 0x42f from ./testError.out
0x08048af0 in __gxx_personality_v0 + 0x200 from ./testError.out
0x41420748 in __libc_start_main + 0xf8 from /lib/tls/libc.so.6
0x08048991 in std::ios_base::Init::~Init() + 0x31 from ./testError.out
/var/spool/torque/mom_priv/jobs/7505.ss1.ms.SC: line 10: 4013 Aborted ./testError.out

When I run it on the interactive node, it works well. ROOT was installed the same way on the cluster nodes than on the interactive node. So, my question is : what may cause that problem ?

Thank you
testError.cpp (4.09 KB)

see the new version of testError.cpp in the attachement.
To execute, do
root > .x testError.cpp

The main point: Do not delete teh histogram you are fitting and the functions too.

testError.cpp (4.14 KB)

I still get the segmentation fault.
I don’t (and I won’t unless you give me good arguments to do it) run it with
root > .x testError.cpp

I want to compile it as a stand-alone application. I remind you I am running this program on a cluster, which implies no GUI, so I don’t want windows to popup at all. My application must be a completely console application. And I want this program to be as efficient as possible… I don’t want it to be interpreted, I want it to be executed.

And why the hell must we not delete the pointers we allocate ? This is usually considered as memory leaks…

Thank you

I forgot to tell you that I didn’t run it with root > .x testError.cpp, but I compiled it without deleting the histograms and functions.


Ok, in the meanwhile, my sysadmin noticed that the ROOTSYS wasn’t set correctly when we submitted jobs on the cluster, this was the cause of all the problems.

Thank you for your help Rene.

However, I am still curious about why we shouldn’t deallocate the memory we allocated for the histograms and functions once we are done with them, by deleting their pointers ?

Thank you