Skip to content

Commit a9669fb

Browse files
committed
Added a parameter to fit whether to calculate confidence limits at all (fit->cl, default: false, "set cl true" can be used to change). Changed plotting and saving defaults of confidence limits to true, so if they are calculated then by default they are also shown and saved.
1 parent 61ffab2 commit a9669fb

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

qjabs/mainwindow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void MainWindow::readPlotSettings()
132132
ui->widget->setLegendVisible(settings.value("showLegend", QVariant(true)).toBool());
133133
ui->widget->setLegendOutside(settings.value("legendOutside", QVariant(false)).toBool());
134134
ui->widget->setEnergyAxis(settings.value("energyAxis", QVariant(false)).toBool());
135-
confidenceLimits = settings.value("confidenceLimits", QVariant(false)).toBool();
135+
confidenceLimits = settings.value("confidenceLimits", QVariant(true)).toBool();
136136
plotSession();
137137
}
138138

qjabs/plotdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void PlotDialog::readSettings()
4747
}
4848
ui->showlegendCheckBox->setChecked(settings.value("showLegend", QVariant(true)).toBool());
4949
ui->legendOutsideCheckBox->setChecked(settings.value("legendOutside", QVariant(false)).toBool());
50-
ui->confidencelimitsCheckBox->setChecked(settings.value("confidenceLimits", QVariant(false)).toBool());
50+
ui->confidencelimitsCheckBox->setChecked(settings.value("confidenceLimits", QVariant(true)).toBool());
5151
}
5252

5353
void PlotDialog::saveSettings()

qjabs/plotdialog.ui

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>270</width>
9+
<width>316</width>
1010
<height>196</height>
1111
</rect>
1212
</property>
@@ -61,7 +61,10 @@
6161
<item>
6262
<widget class="QCheckBox" name="confidencelimitsCheckBox">
6363
<property name="text">
64-
<string>Show confidence limits (BETA)</string>
64+
<string>Show confidence limits if calculated (BETA)</string>
65+
</property>
66+
<property name="checked">
67+
<bool>true</bool>
6568
</property>
6669
</widget>
6770
</item>

src/fit.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ void fit_data_defaults(fit_data *f) {
356356
f->chisq_fast_tol = FIT_FAST_CHISQ_TOL;
357357
f->phase_start = FIT_PHASE_FAST;
358358
f->phase_stop = FIT_PHASE_SLOW;
359+
f->cl = FALSE;
359360
}
360361

361362
int fit_data_jspace_init(fit_data *fit, size_t n_channels_in_fit) {
@@ -1221,12 +1222,14 @@ int fit(fit_data *fit) {
12211222
fit_params_print_final(fit_params);
12221223
fit_correlation_print(fit->covar, MSG_VERBOSE);
12231224
fit_data_print(fit, MSG_VERBOSE);
1225+
if(fit->cl) { /* Calculate confidence limits */
12241226
#ifdef DEBUG
1225-
const char *f_uncertainty = "errors.dat";
1227+
const char *f_uncertainty = "errors.dat";
12261228
#else
1227-
const char *f_uncertainty = NULL;
1229+
const char *f_uncertainty = NULL;
12281230
#endif
1229-
fit_uncertainty_spectra(fit, J, fit->covar, f, &wts.vector, f_uncertainty);
1231+
fit_uncertainty_spectra(fit, J, fit->covar, f, &wts.vector, f_uncertainty);
1232+
}
12301233
}
12311234
gsl_multifit_nlinear_free(w);
12321235
gsl_vector_free(fit->f_iter);

src/fit.h

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ typedef struct fit_data {
113113
double xtol; /* Tolerance of step size */
114114
double chisq_tol; /* Chi squared relative change tolerance */
115115
double chisq_fast_tol; /* Chi squared relative change tolerance (fast phase) */
116+
int cl; /* Calculate confidence limits */
116117
gsl_multifit_nlinear_fdf *fdf;
117118
size_t dof; /* Degrees of freedom (calculated) */
118119
struct fit_stats stats; /* Fit statistics, updated as we iterate */

src/script_command.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,15 @@ script_command_status script_save_spectra(script_session *s, int argc, char *con
286286
size_t i_det = 0;
287287
struct fit_data *fit = s->fit;
288288
const int argc_orig = argc;
289-
int cl = FALSE;
290-
if(argc && strcmp(argv[0], "cl") == 0) {
291-
cl = TRUE;
292-
argc--;
293-
argv++;
294-
}
295289
if(script_get_detector_number(fit->sim, TRUE, &argc, &argv, &i_det) || argc < 1) {
296-
jabs_message(MSG_ERROR, "Usage: save spectra {cl} {<detector>} <file>\n");
290+
jabs_message(MSG_ERROR, "Usage: save spectra {<detector>} <file>\n");
297291
return SCRIPT_COMMAND_FAILURE;
298292
}
299293
if(argc < 1) {
300294
jabs_message(MSG_ERROR, "Not enough arguments for save spectra.\n");
301295
return SCRIPT_COMMAND_FAILURE;
302296
}
303-
if(sim_workspace_print_spectra(fit->spectra, argv[0], cl)) {
297+
if(sim_workspace_print_spectra(fit->spectra, argv[0], fit->cl)) {
304298
jabs_message(MSG_ERROR,
305299
"Could not save spectra of detector %zu to file \"%s\"! There should be %zu detector(s).\n",
306300
i_det + 1, argv[0], fit->sim->n_det);
@@ -1313,6 +1307,7 @@ script_command *script_commands_create(struct script_session *s) {
13131307
{JIBAL_CONFIG_VAR_DOUBLE, "xtolerance", 0, 0, &fit->xtol, NULL},
13141308
{JIBAL_CONFIG_VAR_DOUBLE, "chisq_tolerance", 0, 0, &fit->chisq_tol, NULL},
13151309
{JIBAL_CONFIG_VAR_DOUBLE, "chisq_fast_tolerance", 0, 0, &fit->chisq_fast_tol, NULL},
1310+
{JIBAL_CONFIG_VAR_BOOL, "cl", 0, 0, &fit->cl, NULL},
13161311
{JIBAL_CONFIG_VAR_SIZE, "n_bricks_max", 0, 0, &sim->params->n_bricks_max, NULL},
13171312
{JIBAL_CONFIG_VAR_BOOL, "ds", 0, 0, &sim->params->ds, NULL},
13181313
{JIBAL_CONFIG_VAR_BOOL, "rk4", 0, 0, &sim->params->rk4, NULL},

0 commit comments

Comments
 (0)