Hi,
I’m struggling over a certain issue for now more than an hour and I can’t figure it out…
I want to use a polynom fit of a second order for six data points (for four it works perfectly) but in about half of the fits it returns a negative derivate. This seems to be coming from the fact that the “GetX” function does not work properly in this case.
The code:
double m_corresponding_Ubias_fit;
double certain_data_points_M[6];
double certain_data_points_Ubias[6];
(…)
TGraphErrors* raw_err = new TGraphErrors(6, certain_data_points_Ubias, certain_data_points_M);
TF1* fit_raw = new TF1(“Raw data fit”, “pol2”,330,399);
fit_raw->SetLineColor(kRed);
raw_err->SetMarkerStyle(22);
raw_err->SetMarkerColor(kBlue-2);
raw_err->SetMarkerSize(2);
raw_err->GetXaxis()->SetTitle(“U_{bias}”);
raw_err->GetYaxis()->SetTitle(“M”);
raw_err->GetXaxis()->SetRangeUser(330, 399);
raw_err->GetYaxis()->SetRangeUser(1, 210);
raw_err->Fit(fit_raw, “Q”);
double a_Ubias=0;
a_Ubias=fit_raw->GetX(150.0);
cout << "a_Ubias: " << a_Ubias << endl;
m_corresponding_Ubias_fit=a_Ubias;
double a_dUbias=0;
a_dUbias=fit_raw->Derivative(m_corresponding_Ubias_fit);
a_dUbias=a_dUbias/150.0;
a_dUbias=a_dUbias*100.0;
m_fitted_fit_dM=a_dUbias;
(…)
The data points resp. the arrays are:
certain data points Ubias[0]: 383.992 | certain data points M: 114.783
certain data points Ubias[1]: 385.991 | certain data points M: 127.06
certain data points Ubias[2]: 387.992 | certain data points M: 141.75
certain data points Ubias[3]: 389.991 | certain data points M: 159.531
certain data points Ubias[4]: 391.991 | certain data points M: 181.529
certain data points Ubias[5]: 393.992 | certain data points M: 209.467
The fitted values are then:
a_Ubias: 369.503
dM: -6.22787 Ubias: 369.503
So, according to the arrays and the graphics I really can’t figure out what’s going on… at the recquired y-value of 150 the corresponding x-value is not 369! Why does it result this value ?
Thank you very much in advance!
PS: In case of very similar data points:
certain data points Ubias[0]: 383.978 | certain data points M: 114.047
certain data points Ubias[1]: 385.976 | certain data points M: 126.245
certain data points Ubias[2]: 387.978 | certain data points M: 140.813
certain data points Ubias[3]: 389.978 | certain data points M: 158.523
certain data points Ubias[4]: 391.976 | certain data points M: 180.379
certain data points Ubias[5]: 393.979 | certain data points M: 208.212
a_Ubias: 389.072
dM: 6.25921 Ubias: 389.072
which is correct. And in case of the fit with four data points it is always working correctly.