Problems with TMath::Power

Hello together,

I already searched and found a solution for a linear fit in log scale in this forum and build a makro, which I thought it would work.

c1 = new TCanvas(“c1”,“Title”,200,10,700,500);
TF1 * f1 = new TF1(“f1”,"[0]*x^[1]", 1200, 1340);
Int_t n = 8;
Double_t x[n] = {1200, 1220, 1240, 1260, 1280, 1300, 1320, 1340};
Double_t y[n] = {102.33, 114.26, 128.76, 144.56, 164.64, 188.05, 209.57, 229.65};
Double_t ex[n] = {1,1,1,1,1,1,1,1};
Double_t ey[n] = {0.5, 0.5, 0.75, 0.61, 0.73, 0.71, 0.42, 0.55};
gr = new TGraphErrors(n,x,y,ex,ey);


return c1;

The problem is, that the TMath::Power function gives non-sense values. I tried to set one one each parameters to a fixed value, but the power function will not work. Is there something wrong with my code? Am I missing something?

I hope you can help me

I probably totally misunderstood, but can you please, demonstrate the case when TMath::Power gives you “non-sense value”??? What I can see after executing your macro is :
“Warning in : Abnormal termination of minimization.” so it’s probably a fit-related problem, not TMath::Power.


The problem is that you put wrong initial parameter values. The best is to fit in log scale as a linear fit. Attached is an example doing this and then I eventually use those initial parameter to the fit with TMath::Power. However, you cannot easily work with TMath::Power in a limited precision. In your case, you want to fit a function A ^ (B * X) and the best fit value of A will be very small while B large. So in a limited double precision you might have also numerical problems. It is always better to fit in this case the transformed log data.

So no problem with TMath::Power !

Best Regards

rootForum_17521.C (1.3 KB)