Problems defining a multifit

EDITED ON JUNE 14 5.50PM

Hello, I wrote this macro to fit multiple peaks (in this example I’ve to peaks, but I could have more).

Here the fit function and the parameters meaning:

(Tr and Td are not defined in the screenshot, by they are the rising and decaying times.)

But the fit does not look like good.

Maybe @moneta knwos what I’m wrong (probably initialization parameters, but I’m trying to vary them without finding good ones).

Thanks

se1fe.txt (11.5 KB)
se2fe.txt (17.1 KB)
se3fe.txt (42.2 KB)
se4fe.txt (10.2 KB)
se5fec.txt (15.2 KB)
se6dtec.txt (17.4 KB)

multiflares.cpp (8.1 KB)
FitResultsS1.txt (1.6 KB)

EDIT Thanks to @yus now I get the total fit

Hi,

I am sorry you are experiencing this issue.
Can you reduce the problem to a simple reproducer? It is a sophisticated program, and it is hard to say whether there is a problem due to ROOT at this point.

Cheers,
Danilo

Hi,

the problem is with the following lines in the multiflares.cpp:

   for (int j = 0; j < nRanges; j++) {
            flareFits[j]->SetRange(subranges[j][0], subranges[j][1]);
            graphs[j]->Fit(flareFits[j], "R+");
            ...
   }

Let’s consider j=1. The first line in the loop sets the range to 55550 - 55650. The second line fits graphs[1], which holds the values in se2fe.txt. But these values are from 55950 to 56300. You have no data in the desired range of the function, ergo
Warning in <Fit>: Fit data is empty

Hi @danilo, thank you.
I solved the problems due to the Empty fit errors.

Now I “only” have the problem that the total fit (red line) is not good (as you can see by the plot and by the results txt file.
I guess it is due to inizialization parameters, but even if I tried some values …I can’t find good ones.

@yus:
yes, in the meanwhile I fixed that bug (we wrote at the same moment).
I fixed by replcing
graphs[j]->Fit(flareFits[j], "R+");

by
mg->Fit(flareFits[j], "R+");

Unfortunately, even if I fixed it, I still don’t get a good total fit (see my first topic, because I updated code and plot)

I am a bit confused by this line:

sum += par[i * nParameters] + par[i * nParameters + 1] * (exp((par[i * nParameters + 2] - x[0]) / par[i * nParameters + 3]) + exp((x[0] - par[i * nParameters + 2]) / par[i * nParameters + 4])) * -1;

What is this * -1 at the end?

Hi @yus,
actually it was a typo. It should be **-1 because, as you can see in the formula (First topic) there is a power with index -1.

I replaced
sum += par[i * nParameters] + par[i * nParameters + 1] * (exp((par[i * nParameters + 2] - x[0]) / par[i * nParameters + 3]) + exp((x[0] - par[i * nParameters + 2]) / par[i * nParameters + 4]))*-1;

by

sum += par[i * nParameters] + par[i * nParameters + 1] * (exp((par[i * nParameters + 2] - x[0]) / par[i * nParameters + 3]) + exp((x[0] - par[i * nParameters + 2]) / par[i * nParameters + 4]))**-1;

but I get

multiflares.cpp:128:206: error: indirection requires pointer operand ('int' invalid)
  ...* nParameters + 2] - x[0]) / par[i * nParameters + 3]) + exp((x[0] - par[i * nParameters + 2]) / par[i * nParameters + 4]))**-1;

PS.

I mean, I fit the subranges with the function written in the first topic, i.e. The number of subranges depends on the data file, then I wrote it dinamically, i.e.

flareFits[i] = new TF1(Form("flareFit%d", i), "[0] + [1] * (exp(([2] - x)/[3]) + exp((x - [2])/ [4]))**-1", subranges[i][0], subranges[i][1]);

lastly, by the totalFit function, I want to sum all the flareFits[i] , i.e.

totalFit= flareFits[0]+ flareFits[1]+ .... flareFits[n]

using as initialization parameters the results of partial fits got by flareFits[i]

Because ** does not exponentiate in C++. You need the pow operator for that.

Thank @yus!
That was the problem!

Now I get the total fit (I updated the files in the first post).

I’ve other question, but it’s better opening a new topic

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.