Fit according to a function combines both .c file and some terms

Heyy :slight_smile:

I tried doing something like this:
given some function named VavilovAdapter() that exists on a ‘fit_functions.c’ file I tried to fit this way

va = R.VavilovAdapter() 
ff = R.TF1 ('ff', va, 0, 100, 5)
turnon = R.TF1('to', ".5*(1+erf((x-[1])/(sqrt(2)*[2])))", 10,1000) 

# SettingParameters of both functions... 

vavilov_to = R.TF1('vav_to', "ff*to")

and it won’t allow me because ff is a C-file-imported function. Is there any way that helps me do that??

Appendix (might be relevant) - fit_functions.c file:

#include "fit_functions.h"

double VavilovAdapter::operator()(double *x, double *p)
  params_t param( p[0], p[1], p[2], p[3], p[4] ); // Norm, x0, xi, kappa, beta2
  ROOT::Math::VavilovAccuratePdf* pdf;
  if( _objects.count( param ) ) {
    pdf = _objects[ param ];
  } else {
    _objects[ param ] = pdf = new ROOT::Math::VavilovAccuratePdf( p );
  return pdf->DoEval( *x );


Perhaps @moneta can give some advice.

Looks to me a problem with using a C++ user defined function in Python. It should work, at least it should in C++ code.
Which errors are you getting ?


1 Like

Yes, this was the problem. It didn’t allow me to multiply these functions since ‘va’ was c++ user defined.

The multiplication seems to simply take the titles of those functions, multiply those and recompile the new title as the new function and since ‘va’ is user-defined, it has no simple title to be multiplied.

I solved my problem defining the complete function in C++ because it seemed impossible to create a function combining both a c++ user-defined and some python term.

Added code to my ‘fit_functions.c’ file:

VavilovAdapter va_for_VavErf;
const double sqrt2 = TMath::Sqrt(2.);
Double_t VavErf( Double_t *x, Double_t *par )
  Double_t x_val = x[0];
  Double_t Vavilov_val = va_for_VavErf( x, par );
  Double_t efficiency = 0.5*(1+TMath::Erf( ( x_val - par[5] ) / ( sqrt2 * par[6] ) ) );
  return Vavilov_val * efficiency;