# About TF1 interface and the fitting function for the ROOT::Fit::Fitter

**URL:** <https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816>\
**Category:** Newbie\
**Created:** [April 23, 2026, 11:51am UTC](https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816 "2026-04-23T11:51:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EdwinYZ](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edwinyz/32/36503_2.png) [@EdwinYZ](https://root-forum.cern.ch/u/EdwinYZ)\
**Post date:** [April 23, 2026, 11:51am UTC](https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816/1 "2026-04-23T11:51:27Z")

</div>

Hi,

### Problems

I’m trying to fit a dataset using `ROOT::Fit::Fitter` interface in a C++ project. So far, I have been using TF1 class to setup the fitting function.

In general, TF1 has two kinds of interfaces:

1. Using string to define the function.

2. Using lambda.

Thus, I would like to know whether there is any fast and safe API for setting up the fitting function of the Fitter class.

### Suggestions on TF1 constructor interface

#### Adding size information during the runtime

It would be nice if the TF1 allows the lambda to have sizes as its input arguments:

```cpp
auto [](const double* variables, std::size_t variable_size, 
        const double* parameters, std::size_t parameter_size) -> double;

```

Or even better using `std::span`

```cpp
auto [](std::span<const double> variables, std::span<const double> parameters) -> double;

```

#### Using std::array

Most of the time, the fitting function is fixed already during the compile time, so it makes sense to have something like:

```cpp
auto [](const std::array<double, 2>& variables, 
        const std::array<double, 3>& parameters) -> double
{
   const auto& [x, y] = variables;
   const auto& [a, b, c] = parameters;
   return a * x + b * y + c;
};

```

This looks very nice and clear, but it requires a redesign of TF1, as TF1 would have to be a class template, with the template arguments to be the number of variables and parameters. Or it at least needs two template specialization, one for dynamic sizes (old API, sizes are determined at the runtime) and another for fixed compile-time sizes.

Thanks for your attention

* * *

_ROOT Version:_ 6.36.04  
_Platform:_ Fedora 42  
_Compiler:_ Clang 21

* * *

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [April 23, 2026, 8:24pm UTC](https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816/2 "2026-04-23T20:24:31Z")

</div>

@jonas Is this something you can comment on?

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [April 26, 2026, 9:05pm UTC](https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816/3 "2026-04-26T21:05:29Z")

</div>

Hi @EdwinYZ, I think this a very reasonable API change! The fact that the number of parameters can’t be validated has also bitten me a few times. I think the suggestion with the `std::span` is pretty good and goes in the direction that ROOT is going also in other areas. Since this is not really a question but a concrete improvement suggestion, would you mind opening a GitHub issue about this?

> **[Issues · root-project/root](https://github.com/root-project/root/issues)**
>
> The official repository for ROOT: analyzing, storing and visualizing big data, scientifically - Issues · root-project/root

Thanks,  
Jonas

---

<div class="post-metadata">

**Author:** ![EdwinYZ](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/edwinyz/32/36503_2.png) [@EdwinYZ](https://root-forum.cern.ch/u/EdwinYZ)\
**Post date:** [April 27, 2026, 8:32am UTC](https://root-forum.cern.ch/t/about-tf1-interface-and-the-fitting-function-for-the-root-fitter/64816/4 "2026-04-27T08:32:16Z")

</div>

Hi

Thanks for the response.

Yes, I will open up a Github issue.
