Segmentation break using Fit Panel

Hi everyone.
I am kinda new to ROOT so this may be a fairly easy problem to deal with.
I have a problem that has happening to me several times. Last time I ended up reinstaling root and the problem disappeared but now has happened again… for some reason I don’t know.
When I use the fit panel in order to fit in a more interactive way, the program simply doesn’t work (gives a segmentation violation) and I don’t understand why.
The code I am using is the follow:

#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <TGraphErrors.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TApplication.h>
#include <TAxis.h>

void FitData()
{
    // Create a TApplication for the ROOT graphics
    TApplication app("app", nullptr, nullptr);

    // Read data from file
    std::ifstream file("/home/diogo/analysis/main/data/beta/bi3.txt");
    if (!file.is_open())
    {
        std::cout << "Failed to open data file." << std::endl;
        return;
    }

    // Arrays to store data
    std::vector<double> xValues;
    std::vector<double> yValues;
    std::vector<double> yErrors;

    std::string line;
    while (std::getline(file, line))
    {
        std::istringstream iss(line);
        double x, y, err;
        if (iss >> x >> y >> err)
        {
            xValues.push_back(x);
            yValues.push_back(y);
            yErrors.push_back(err);
        }
    }

    file.close();

    // Create a TGraphErrors from the data
    int numPoints = xValues.size();
    TGraphErrors *graph = new TGraphErrors(numPoints, &xValues[0], &yValues[0], 0, &yErrors[0]);

    graph->SetTitle("Calibration in Energy");
    graph->GetXaxis()->SetTitle("Energy [keV]");
    graph->GetYaxis()->SetTitle("Channel");

    graph->GetXaxis()->CenterTitle(true);
    graph->GetYaxis()->CenterTitle(true);

    // Create a canvas to display the graph
    TCanvas *canvas = new TCanvas("canvas", "Data Fitting", 800, 600);
    graph->Draw("AP"); // "AP" option to display both markers and error bars

    // Launch the ROOT Fit Panel
    canvas->Update(); // Update the canvas to display the graph
    canvas->cd();
    graph->FitPanel();

    // Wait for the Fit Panel to be closed
    app.Run();
}

int main()
{
    FitData();
    return 0;
}

This only happens when I use the fit panel. If I don’t use it everything works properly.
Does anyone have an idea of what can be causing this segmentation violation?
The error that appears is the following:

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f0766fd9593 in TFitEditor::GetInstance(TVirtualPad*, TObject*) + 0x93 from /home/diogo/root/lib/libFitPanel.so.6.28.04
 0x00007f077fe5d094 in <unknown function>
 0x00007f07836b23eb in TClingCallFunc::exec(void*, void*) + 0x37b from /home/diogo/root/lib/libCling.so
 0x00007f07836b45e1 in TClingCallFunc::exec_with_valref_return(void*, cling::Value*) + 0x1b1 from /home/diogo/root/lib/libCling.so
 0x00007f07836baf67 in TClingCallFunc::ExecInt(void*) + 0x57 from /home/diogo/root/lib/libCling.so
 0x00007f078a494405 in TMethodCall::Execute(void*, long&) + 0x95 from /home/diogo/root/lib/libCore.so.6.28
 0x00007f0789f7efb6 in TGraph::FitPanel() + 0x1e6 from /home/diogo/root/lib/libHist.so.6.28
 0x0000559151e6192c in FitData() + 0x41c from bin/fitPanel.exe
 0x0000559151e61aab in main + 0xd from bin/fitPanel.exe
 0x00007f0789492d90 in <unknown> from /lib/x86_64-linux-gnu/libc.so.6
 0x00007f0789492e40 in __libc_start_main + 0x80 from /lib/x86_64-linux-gnu/libc.so.6
 0x0000559151e60565 in _start + 0x25 from bin/fitPanel.exe

I am having trouble with fit panel for so long. Pls somebody help I am desperate.
If there’s anything else you need to know about this situation to help pls ask, and sorry for my english.

Here is another example with the same problem:

/*
Fitar dados com incertezas nos eixos que quisermos a um modelo à escolha
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <TGraphErrors.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TApplication.h>
#include <TAxis.h>

void FitData()
{
    // Create a TApplication for the ROOT graphics
    TApplication app("app", nullptr, nullptr);

    // Read data from file
    std::ifstream file("/home/diogo/analysis/main/data/fit.txt");
    if (!file.is_open())
    {
        std::cout << "Failed to open data file." << std::endl;
        return;
    }

    // Arrays to store data
    std::vector<double> xValues;
    std::vector<double> yValues;
    std::vector<double> xErrors;
    std::vector<double> yErrors;


    double x, y, xErr, yErr;
    while (file >> x >> xErr >> y >> yErr)
    {
        xValues.push_back(x);
        yValues.push_back(y);
        xErrors.push_back(xErr);
        yErrors.push_back(yErr);
    }
    file.close();

    // Create a TGraphErrors from the data
    int numPoints = xValues.size();
    TGraphErrors *graph = new TGraphErrors(numPoints, &xValues[0], &yValues[0], &xErrors[0], &yErrors[0]);

    graph->SetTitle("Intensidade em funcao da distancia");
    graph->GetXaxis()->SetTitle("Distancia (cm)");
    graph->GetYaxis()->SetTitle("Intensidade (Counts)");

    graph->GetXaxis()->CenterTitle(true);
    graph->GetYaxis()->CenterTitle(true);

    // Create a canvas to display the graph
    TCanvas *canvas = new TCanvas("canvas", "Data Fitting", 800, 600);
    graph->Draw("AP"); // "AP" option to display both markers and error bars

    // Define a custom TF1 function
    TF1 *fitFunc = new TF1("fitFunc", "[0]/(x-[1])^2+[2]");


    // Set initial parameter values and names
    fitFunc->SetParameters(0.001, 5000, 1);
    fitFunc->SetParNames("a", "b", "c");


    // Fit the graph to the custom function
    graph->Fit(fitFunc, "R"); // "R" option for fit range using the graph's x-axis range

    // Wait for the Fit Panel to be closed
    app.Run();
}

int main()
{
    FitData();
    return 0;
}

Hi @Diogo_Franco,

I was unable to reproduce this locally on an ArchLinux x86_64 system (and I guess @couet has not seen this before, right?).

Could you please provide more information on your environment, i.e. ROOT version that you using, how did you install it, OS, etc.?

Cheers,
J.

Hi @jalopezg ,
Thank you very much for the (quick) reply.
I’ve just checked and I am using version 6.28/04 of ROOT, which I believe is the most recent one.
It wasn’t me who installed ROOT last time in my computer but I believe the guy just downloaded it from the ROOT CERN official site…
I have ROOT installed in the WSL Ubunto, since I have a Windows computer.
Among my colleagues, I’m the only one with this random error. I’ve tried literally copy paste their code in my VS Code but doesn’t work for me…
Maybe all this info isn’t enough and I know it seems a random problem. If you need any more info just ask pls.
Thank you a lot again for helping :slight_smile:

Can you also do this:
1 - attach a sample input file that reproduces the problem, and
2 - describe when/how do you see the seg fault?
I tried your first code (also in WSL Ubuntu) with a small made-up graph and I did not see a segmentation fault; however, when I closed the canvas and the fit panel, the Ubuntu command prompt was unresponsive and I had to kill (close) the Ubuntu window.

@jalopezg you are right, but I am not using the fit panel a lot and specially on windows. As @dastudillo suggested, a more complete reproducer might help.

Hi guys.
Thank you very much for all your replies and help.
I finally managed to solve the problem. I had forgotten to write the command line to set my IP adress in Ubuntu. (I don’t understand why I have to give this command all the time but it turns out I have…)
Once again, thanks a lot.
Diogo Franco.

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