Hi,
it’s a lifetime issue, see the self-contained C++ reproducer below, with no RDF involved – the segfault goes away if you change TGraph gr to auto *gr = new TGraph() and then leak the TGraph:
#include <TF1.h>
#include <TGraph.h>
TF1 getFitFunc() {
TGraph *gr = new TGraph();
for (int i = 0; i < 10; ++i)
gr->SetPoint(i + 1, i, i * i);
gr->Fit("pol2");
TF1 fit = *gr->GetFunction("pol2");
delete gr; // comment to make the crash disappear
return fit;
}
int main() {
TF1 f = getFitFunc();
f.GetParameter(0);
return 0;
}
Inspecting the crash with gdb reveals the problem is in TF1’s destructor, where the TF1 object tries to deregister itself from its fParent object (the TGraph in this case, which is already out of scope in your implementation of getFitFunc).
I assume that your real use-case is more complicated so I won’t try to come up with a solution that might not apply to your case
As a suggestion, however: if you don’t need to re-evaluate the fit at every event, just use variables external to the event loop. If you need to evaluate the Fit at every event, maybe rather than returning the TF1 from getFitFunc you can return a struct or a vector with the fit parameters you need in further computations, so the only thing passed around is numbers.