Problem fitting with user defined functions

Dear Root experts,
I am trying to do a fitting using user defined functions.
I have a file (FitFunctions.h) that contains the definition of a crystalball and an exponential function.
It also includes the “FinalFitFunction” which is the sum of these functions.

In my fitting code (CrystalBallFitter.h) a histogram is passed to the code as an input argument and the FinalFittingFunction is called.

I can successfully compile my codes but when I run on data, I receive the following:
Unknown function: FinalFitFunction
Any help is appreciated as always.

Here is my “FitFunctions.h” code:

#include “ResultAnalyzer.h”

double ResultAnalyzer::CryatalBallSignal(double* x, double* Parameters) {
double Alpha = Parameters[0];
double N = Parameters[1];
double Sigma = Parameters[2];
double Mean = Parameters[3];

``````if (Sigma<0.0)
return 0.0;
else {
double Z = (x[0]-Mean)/Sigma;
if (Z>-Alpha)
return exp(-pow(Z,2)/2);
else {
double P = abs(Alpha);
double Q = N/P;
double A = pow(Q,N)*exp(-pow(P,2)/2);
double B = Q-P;
return A*(pow((B-Z),-N));
}
}
``````

}

double ResultAnalyzer::ExponentialBackground(double* x, double* Parameters) {
double Lambda = Parameters[0];
double x0 = Parameters[1];

``````if ((x[0]-x0)<0)
return 0.0;
else
return Lambda*exp(-Lambda*(x[0]-x0));
``````

}

double ResultAnalyzer::FinalFitFunction(double* x, double* Parameters) {
return CryatalBallSignal(x,&Parameters[0])+CryatalBallSignal(x,&Parameters[4])+ExponentialBackground(x,&Parameters[8]);
}

and here is my “CrystalBallfitter.h” :

#include “ResultAnalyzer.h”

void ResultAnalyzer::CrystalBallFitter(TH1D* h_JPsiPsiMass)
{
h_JPsiPsiMass->Fit(“FinalFitFunction”);
}

Thank you in advance for the help.

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

You need to create a `TF1` function.

Hi @Wile_E_Coyote,
Thank you for the quick response.
I included the following:
TF1* Total = new TF1(“Total”,“FinalFitFunction”, 2.6, 4.2, 10);
and changed this: h_JPsiPsiMass->Fit(“FinalFitFunction”);
to this: h_JPsiPsiMass->Fit(“Total”);

You are probably missing the definition of cling::runtime::internal::LifetimeHandler::LifetimeHandler(cling::runtime::internal::DynamicExprInfo*, clang::DeclContext*, char const*, cling::Interpreter*)
Maybe you need to load the corresponding shared library?
Maybe you need to load the corresponding shared library?
Error in TFormula::TFormula: Syntax error in building the lambda expression FinalFitFunction
Error in TFormula::Eval: Formula is invalid and not ready to execute
Error in TFormula::Eval: Formula is invalid and not ready to execute

This error continues (thousands of lines).

The types of functions that can be created are described in the `TF1` class reference.

Thank you very much for your help.
Could you please also let me know in order to use ROOT::Math::crystalball_function which header files should I include in my code?
Thank you

`#include "Math/DistFunc.h"`