Dear experts.
I would like to make a TF1 function that is the sum of many exponentials, which have all the same variable lambda that I would like to vary in a fit. This is the function I would like to implement:
with lambda > 0 and with H the Heavyside function. So the terms of the sum should be 0 for x<i and exp(-lambda x) for x>=i. For illustration:
Now, after some googling, I based myself on an example of the root forum back in 2008. I attach a sample program at the bottom of this topic that you can run by root -l SumOfNExp.C+
. However I am experiencing some problems / instabilities and I also have some questions.
- Even though an exp(-10x) drops quicker to zero than for instance exp(-1x), I obtain NAN in the calculation of the evaluation of the function f. I tried understand which term lead to the infinity and I found out it was quite random and depends on the value of lambda. For instance for the calculation of f(0) I printed out the the evaluation at 0 for the various components:
f68(0) = 0 cumulative sum = 0
f69(0) = 0 cumulative sum = 0
f70(0) = 0 cumulative sum = 0
f71(0) = nan cumulative sum = nan
f72(0) = nan cumulative sum = nan
f73(0) = nan cumulative sum = nan
- Playing with lambda, I can find values for which I do not have this problem, but I would like to use lambda as a fit variable, so this is looking for some trouble i.m.h.o.
- Will I be able to use this function to fit, and by defining the individual terms in a loop, will they all share the same variable
[3]
or will these parameters be all different? In the latter case, how can I lock them?
std::vector<TF1 *> func_vec;
for(int i=0; i<nbx; ++i) {
std::string fncname = "f";
fncname = fncname+std::to_string(i);
TF1 * f = new TF1(fncname.c_str(),"(x<[0])*[1] + (x>=[0] && x<[0]+10)*[2]*exp(-1*(x-[0])*[3]) + (x>=[0]+10)*[1]",0,nbx-1);
f->FixParameter(0,i);
f->FixParameter(1,0);
f->FixParameter(2,lumivec[i]);
f->SetParameter(3,10); // 10 non funziona
func_vec.push_back(f);
}
- Is this the most efficient way to solve my problem, or are there other tricks to obtain the function I need that are more efficient and computationally effective?
Thanks a lot
Kind regards
Piet Verwilligen
SumOfNExp.C (5.3 KB)
ROOT Version: 6.32.12
Platform: macosx64
Compiler: apple clang version 17.0.0