Skip to content

Commit 009c9a0

Browse files
author
vetlewi
committed
Fixed a bug in coefficients given in the fit.
The coefficients used in the fit had some erroneous factors. This has now been fixed. A chi-square test is also been introduced to give an idea of how good the fit is. This is the chi2/degrees of freedom value.
1 parent e5f931b commit 009c9a0

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

source/support/src/tablemakerhtml.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "tablemakerhtml.h"
22

3+
#include <cmath>
4+
35
TableMakerHTML::TableMakerHTML()
46
{
57

@@ -82,6 +84,7 @@ QString TableMakerHTML::makeTable(Result_t data)
8284
output += "<td><b>Excitation energy (keV):</b></td>\n";
8385
output += "<td>Energy dE-detector (keV):</td>\n";
8486
output += "<td>Energy E-detector (keV):</td>\n";
87+
output += "<td>Total particle energy (keV):</td>\n";
8588
output += "</tr>\n";
8689
for (int i = 0 ; i < data.Ex.size() ; ++i){
8790
output += "<tr>\n";
@@ -98,6 +101,11 @@ QString TableMakerHTML::makeTable(Result_t data)
98101
output += " ± ";
99102
output += std::to_string(data.d_E[i]*1000).c_str();
100103
output += "</td>\n";
104+
output += "<td>";
105+
output += std::to_string((data.dE[i]+data.E[i])*1000).c_str();
106+
output += " ± ";
107+
output += std::to_string(sqrt(data.d_dE[i]*data.d_dE[i] + data.d_E[i]*data.d_E[i])*1000).c_str();
108+
output += "</td>\n";
101109
output += "</tr>\n";
102110
}
103111
output += "</table>\n";
@@ -108,12 +116,14 @@ QString TableMakerHTML::makeCoeff(QVector<double> coeff)
108116
{
109117
QString output = "";
110118
output += "<b>Ex(e+de) = a0 + a1(e+de) + a2(e+de)^2</b>\n";
111-
output += "<p>a0 = ";
112-
output += std::to_string(coeff[0]*1000).c_str();
113-
output += " keV, a1 = ";
114-
output += std::to_string(coeff[1]*1000).c_str();
119+
output += "<p>chi-squared: ";
120+
output += std::to_string(coeff[3]).c_str();
121+
output += ", a0 = ";
122+
output += std::to_string(coeff[0]).c_str();
123+
output += " MeV, a1 = ";
124+
output += std::to_string(coeff[1]).c_str();
115125
output += ", a2 = ";
116-
output += std::to_string(coeff[2]*1000).c_str();
117-
output += " keV^-1</p>\n";
126+
output += std::to_string(coeff[2]).c_str();
127+
output += " MeV^-1</p>\n";
118128
return output;
119129
}

source/support/src/worker.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const double PI = acos(-1);
2525
const double ANG_FWD = 47*PI/180.;
2626

27+
2728
Worker::Worker(Beam_t *beam, Target_t *target, Telescope_t *telescope)
2829
: theBeam( beam )
2930
, theTarget( target )
@@ -136,6 +137,7 @@ bool Worker::Curve(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
136137
}
137138

138139
double Ehalf = stopTargetB->Loss(theBeam->E, target->GetWidth(tUnit)/2., INTPOINTS);
140+
double Ewhole = stopTargetB->Loss(theBeam->E, INTPOINTS);
139141

140142
double dEx = (Ehalf + get_Q_keV(theBeam->A, theBeam->Z, theTarget->A, theTarget->Z, fA, fZ)/1000.)/double(POINTS - 1);
141143

@@ -164,23 +166,33 @@ bool Worker::Curve(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
164166
return false; // Reaction not possible. Not enough energy :(
165167
}
166168

167-
QVector<double> Ex_tmp(POINTS), dE_tmp(POINTS), E_tmp(POINTS), is_punch(POINTS);
169+
QVector<double> Ex_tmp(POINTS), dE_tmp(POINTS), E_tmp(POINTS), E_err_tmp(POINTS), is_punch(POINTS);
168170

169171
Ex.clear();
170172
dE.clear();
171173
E.clear();
172174

173-
175+
double l;
174176
double m, dm, em;
177+
double n;
175178

176179
for (int i = 0 ; i < POINTS ; ++i){
177180
Ex_tmp[i] = i*dEx;
178181

182+
l = scat->EvaluateY(theBeam->E, Angle, Ex_tmp[i]);
179183
m = scat->EvaluateY(Ehalf, Angle, Ex_tmp[i]);
184+
n = scat->EvaluateY(Ewhole, Angle, Ex_tmp[i]);
180185

186+
l = stopTargetF->Loss(l, target->GetWidth(tUnit)/fabs(2*cos(Angle)), INTPOINTS);
181187
m = stopTargetF->Loss(m, target->GetWidth(tUnit)/fabs(2*cos(Angle)), INTPOINTS);
182188

189+
l = stopAbsor->Loss(l, INTPOINTS);
183190
m = stopAbsor->Loss(m, INTPOINTS);
191+
n = stopAbsor->Loss(n, INTPOINTS);
192+
193+
E_err_tmp[i] = sqrt(3*l*l + 3*n*n + 4*m*m - 2*n*l -4*m*(l + n))/4.;
194+
195+
m = (l + 2*m + n)/4.;
184196

185197
dm = stopDE->Loss(m, INTPOINTS);
186198

@@ -192,14 +204,15 @@ bool Worker::Curve(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
192204
if (em != em)
193205
is_punch[i] = 1000;
194206
}
195-
QVector<double> is_punch2;
207+
QVector<double> is_punch2, E_err;
196208
int not_punch = 0;
197209
for (int i = 0 ; i < Ex_tmp.size() ; ++i){
198210
if (E_tmp[i] >= 0.35){
199211
Ex.push_back(Ex_tmp[i]);
200212
dE.push_back(dE_tmp[i]);
201213
E.push_back(E_tmp[i]);
202214
is_punch2.push_back(is_punch[i]);
215+
E_err.push_back(E_err_tmp[i]);
203216
if (is_punch[i] <= 0.05)
204217
not_punch += 1;
205218
}
@@ -208,18 +221,25 @@ bool Worker::Curve(QVector<double> &Ex, QVector<double> &dE, QVector<double> &E,
208221
if (not_punch >= 3){
209222
double *x = new double[not_punch];
210223
double *y = new double[not_punch];
224+
double *dx = new double[not_punch];
211225
int j = 0;
212226
for (int i = 0 ; i < is_punch2.size() ; ++i){
213227
if (is_punch2[i] <= 0.05 && j < not_punch){
214228
x[j] = dE[i] + E[i];
215229
y[j] = Ex[i];
230+
dx[j] = E_err[i];
216231
++j;
217232
}
218233
}
219234
Polyfit fitting(x, y, not_punch);
220235
Vector fit = fitting(3);
221-
coeff = QVector<double>(3);
222-
coeff[0] = fit[0]; coeff[1] = fit[1]; coeff[2] = fit[2];
236+
coeff = QVector<double>(4);
237+
coeff[0] = fit[0]; coeff[1] = fit[1]; coeff[2] = fit[2], coeff[3] = 0;
238+
239+
for (int i = 0 ; i < not_punch ; ++i){
240+
coeff[3] += (y[i] - coeff[0] - coeff[1]*x[i] - coeff[2]*x[i]*x[i])*(y[i] - coeff[0] - coeff[1]*x[i] - coeff[2]*x[i]*x[i])/(dx[i]*dx[i]);
241+
}
242+
coeff[3] /= double(not_punch - 3);
223243

224244
delete[] x;
225245
delete[] y;

0 commit comments

Comments
 (0)