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.