@@ -76,7 +76,7 @@ int fit_detector(const jibal *jibal, const fit_data_det *fdd, const simulation *
76
76
void fit_deriv_prepare_jspaces (const gsl_vector * x , fit_data * fit ) {
77
77
jacobian_space * space = fit -> jspace ;
78
78
for (size_t j = 0 ; j < fit -> fit_params -> n_active ; j ++ ) { /* Make copies of sim (shallow) with deep copies of detector and sample. This way we can parallelize. */
79
- struct jacobian_space * spc = & space [j ];
79
+ jacobian_space * spc = & space [j ];
80
80
spc -> n_spectra_calculated = 0 ;
81
81
fit_variable * var = spc -> var ;
82
82
double xj = gsl_vector_get (x , j );
@@ -105,7 +105,7 @@ void fit_deriv_prepare_jspaces(const gsl_vector *x, fit_data *fit) {
105
105
void fit_deriv_cleanup_jspaces (fit_data * fit ) {
106
106
jacobian_space * space = fit -> jspace ;
107
107
for (size_t j = 0 ; j < fit -> fit_params -> n_active ; j ++ ) {
108
- struct jacobian_space * spc = & space [j ];
108
+ jacobian_space * spc = & space [j ];
109
109
fit_variable * var = spc -> var ;
110
110
fit -> stats .n_spectra_iter += spc -> n_spectra_calculated ;
111
111
switch (var -> type ) {
@@ -122,7 +122,7 @@ void fit_deriv_cleanup_jspaces(fit_data *fit) {
122
122
}
123
123
124
124
int fit_deriv_function (const gsl_vector * x , void * params , gsl_matrix * J ) {
125
- struct fit_data * fit = (struct fit_data * ) params ;
125
+ fit_data * fit = (fit_data * ) params ;
126
126
assert (fit -> stats .iter_call >= 1 ); /* This function relies on data that was computed when iter_call == 1 */
127
127
assert (fit -> fdf -> p == fit -> fit_params -> n_active );
128
128
@@ -138,7 +138,7 @@ int fit_deriv_function(const gsl_vector *x, void *params, gsl_matrix *J) {
138
138
#pragma omp for schedule(dynamic)
139
139
for (j = 0 ; j < n ; j ++ ) {
140
140
//fprintf(stderr, "Thread id %i got %zu.\n", omp_get_thread_num(), j);
141
- struct jacobian_space * spc = & fit -> jspace [j ];
141
+ jacobian_space * spc = & fit -> jspace [j ];
142
142
fit_variable * var = spc -> var ;
143
143
size_t i_start , i_stop ;
144
144
if (var -> type == FIT_VARIABLE_DETECTOR ) {
@@ -178,7 +178,7 @@ int fit_deriv_function(const gsl_vector *x, void *params, gsl_matrix *J) {
178
178
}
179
179
180
180
int fit_function (const gsl_vector * x , void * params , gsl_vector * f ) {
181
- struct fit_data * fit = (struct fit_data * ) params ;
181
+ fit_data * fit = (fit_data * ) params ;
182
182
fit -> stats .iter_call ++ ;
183
183
if (fit -> stats .iter_call == 1 ) { /* Clear stored spectra from previous iteration */
184
184
for (size_t i = 0 ; i < fit -> n_det_spectra ; i ++ ) {
@@ -254,7 +254,7 @@ int fit_sanity_check(const fit_data *fit) {
254
254
return GSL_SUCCESS ;
255
255
}
256
256
257
- int fit_parameters_set_from_vector (struct fit_data * fit , const gsl_vector * x ) {
257
+ int fit_parameters_set_from_vector (fit_data * fit , const gsl_vector * x ) {
258
258
DEBUGMSG ("Fit iteration has %zu active parameters from a total of %zu possible." , fit -> fit_params -> n_active , fit -> fit_params -> n )
259
259
for (size_t i = 0 ; i < fit -> fit_params -> n ; i ++ ) {
260
260
fit_variable * var = & fit -> fit_params -> vars [i ];
@@ -271,7 +271,7 @@ int fit_parameters_set_from_vector(struct fit_data *fit, const gsl_vector *x) {
271
271
return GSL_SUCCESS ;
272
272
}
273
273
274
- void fit_iter_stats_update (struct fit_data * fit_data , const gsl_multifit_nlinear_workspace * w ) {
274
+ void fit_iter_stats_update (fit_data * fit_data , const gsl_multifit_nlinear_workspace * w ) {
275
275
gsl_vector * f = gsl_multifit_nlinear_residual (w );
276
276
/* compute reciprocal condition number of J(x) */
277
277
gsl_multifit_nlinear_rcond (& fit_data -> stats .rcond , w );
@@ -283,20 +283,20 @@ void fit_iter_stats_update(struct fit_data *fit_data, const gsl_multifit_nlinear
283
283
fit_data -> stats .cputime_cumul += fit_data -> stats .cputime_iter ;
284
284
}
285
285
286
- void fit_iter_stats_print (const struct fit_stats * stats ) {
286
+ void fit_iter_stats_print (const fit_stats * stats ) {
287
287
jabs_message (MSG_INFO , "%4zu | %10.2e | %14.7e | %12.7lf | %7zu | %7zu | %10.3lf | %13.1lf |\n" ,
288
288
stats -> iter , 1.0 / stats -> rcond , stats -> norm ,
289
289
stats -> chisq_dof , stats -> n_evals , stats -> n_spectra ,
290
290
stats -> cputime_cumul , 1000.0 * stats -> cputime_iter / stats -> n_spectra_iter );
291
291
}
292
292
293
- void fit_stats_print (const struct fit_stats * stats , jabs_msg_level msg_level ) {
293
+ void fit_stats_print (const fit_stats * stats , jabs_msg_level msg_level ) {
294
294
if (stats -> chisq_dof > 0.0 ) {
295
295
jabs_message (msg_level , "Final chisq/dof = %.7lf\n" , stats -> chisq_dof );
296
296
}
297
297
}
298
298
299
- int fit_data_fit_range_add (struct fit_data * fit_data , const struct roi * range ) { /* Makes a deep copy */
299
+ int fit_data_fit_range_add (fit_data * fit_data , const roi * range ) { /* Makes a deep copy */
300
300
if (range -> low == 0 && range -> high == 0 ) {
301
301
return EXIT_FAILURE ;
302
302
}
@@ -314,7 +314,7 @@ int fit_data_fit_range_add(struct fit_data *fit_data, const struct roi *range) {
314
314
return EXIT_SUCCESS ;
315
315
}
316
316
317
- void fit_data_fit_ranges_free (struct fit_data * fit_data ) {
317
+ void fit_data_fit_ranges_free (fit_data * fit_data ) {
318
318
if (!fit_data )
319
319
return ;
320
320
free (fit_data -> fit_ranges );
@@ -341,7 +341,7 @@ void fit_data_det_residual_vector_set(const fit_data_det *fdd, const jabs_histog
341
341
DEBUGMSG ("Set %zu elements of vector from %zu ranges." , i_vec , fdd -> n_ranges );
342
342
}
343
343
fit_data * fit_data_new (const jibal * jibal , simulation * sim ) {
344
- struct fit_data * fit = calloc (1 , sizeof (struct fit_data ));
344
+ fit_data * fit = calloc (1 , sizeof (fit_data ));
345
345
fit -> jibal = jibal ;
346
346
fit -> sim = sim ;
347
347
fit_data_exp_alloc (fit );
@@ -425,20 +425,20 @@ void fit_data_exp_reset(fit_data *fit) {
425
425
}
426
426
}
427
427
428
- void fit_data_roi_print (const struct fit_data * fit_data , const struct roi * roi ) {
429
- if (!fit_data ) {
428
+ void fit_data_roi_print (const fit_data * fit , const struct roi * roi ) {
429
+ if (!fit ) {
430
430
return ;
431
431
}
432
- jabs_histogram * histo_sim = fit_data_histo_sum (fit_data , roi -> i_det );
433
- jabs_histogram * histo_exp = fit_data_exp (fit_data , roi -> i_det );
434
- jabs_histogram * histo_ref = fit_data -> ref ;
432
+ jabs_histogram * histo_sim = fit_data_histo_sum (fit , roi -> i_det );
433
+ jabs_histogram * histo_exp = fit_data_exp (fit , roi -> i_det );
434
+ jabs_histogram * histo_ref = fit -> ref ;
435
435
size_t n_sim = jabs_histogram_channels_in_range (histo_sim , roi -> low , roi -> high );
436
436
size_t n_exp = jabs_histogram_channels_in_range (histo_exp , roi -> low , roi -> high );
437
437
size_t n_ref = jabs_histogram_channels_in_range (histo_ref , roi -> low , roi -> high );
438
438
double sim_cts = jabs_histogram_roi (histo_sim , roi -> low , roi -> high );
439
439
double exp_cts = jabs_histogram_roi (histo_exp , roi -> low , roi -> high );
440
440
double ref_cts = jabs_histogram_roi (histo_ref , roi -> low , roi -> high );
441
- const detector * det = sim_det (fit_data -> sim , roi -> i_det );
441
+ const detector * det = sim_det (fit -> sim , roi -> i_det );
442
442
443
443
jabs_message (MSG_INFO , " low = %12zu\n" , roi -> low );
444
444
jabs_message (MSG_INFO , " high = %12zu\n" , roi -> high );
@@ -677,7 +677,7 @@ void fit_data_exp_free(fit_data *fit) {
677
677
fit -> n_exp = 0 ;
678
678
}
679
679
680
- int fit_data_load_exp (struct fit_data * fit , size_t i_det , const char * filename ) {
680
+ int fit_data_load_exp (fit_data * fit , size_t i_det , const char * filename ) {
681
681
jabs_histogram * h = spectrum_read_detector (filename , sim_det (fit -> sim , i_det ));
682
682
if (!h ) {
683
683
jabs_message (MSG_ERROR , "Reading spectrum from file \"%s\" was not successful.\n" , filename );
@@ -756,7 +756,7 @@ void fit_data_spectra_free(fit_data *fit) {
756
756
fit -> n_det_spectra = 0 ;
757
757
}
758
758
759
- int fit_data_add_det (struct fit_data * fit , detector * det ) {
759
+ int fit_data_add_det (fit_data * fit , detector * det ) {
760
760
if (!fit || !det )
761
761
return EXIT_FAILURE ;
762
762
if (sim_det_add (fit -> sim , det )) {
@@ -775,11 +775,11 @@ fit_data_det *fit_data_fdd(const fit_data *fit, size_t i_det) {
775
775
}
776
776
777
777
778
- size_t fit_data_ranges_calculate_number_of_channels (const struct fit_data * fit_data ) {
778
+ size_t fit_data_ranges_calculate_number_of_channels (const fit_data * fit ) {
779
779
size_t sum = 0 ;
780
- for (size_t i = 0 ; i < fit_data -> n_fit_ranges ; i ++ ) {
781
- roi * r = & fit_data -> fit_ranges [i ];
782
- detector * det = sim_det (fit_data -> sim , r -> i_det );
780
+ for (size_t i = 0 ; i < fit -> n_fit_ranges ; i ++ ) {
781
+ roi * r = & fit -> fit_ranges [i ];
782
+ detector * det = sim_det (fit -> sim , r -> i_det );
783
783
if (!det ) {
784
784
continue ;
785
785
}
@@ -792,8 +792,8 @@ size_t fit_data_ranges_calculate_number_of_channels(const struct fit_data *fit_d
792
792
return sum ;
793
793
}
794
794
795
- struct fit_stats fit_stats_init (void ) {
796
- struct fit_stats s ;
795
+ fit_stats fit_stats_init (void ) {
796
+ fit_stats s ;
797
797
s .n_evals = 0 ;
798
798
s .n_evals_iter = 0 ;
799
799
s .n_spectra = 0 ;
@@ -869,31 +869,30 @@ int multifit_nlinear_print_jacobian(const gsl_multifit_nlinear_workspace *w, con
869
869
return EXIT_SUCCESS ;
870
870
}
871
871
872
- int jabs_gsl_multifit_nlinear_driver (const size_t maxiter , const double xtol , const double chisq_tol , struct fit_data * fit_data , gsl_multifit_nlinear_workspace * w ) {
872
+ int jabs_gsl_multifit_nlinear_driver (const size_t maxiter , const double xtol , const double chisq_tol , fit_data * fit , gsl_multifit_nlinear_workspace * w ) {
873
873
int status = 0 ;
874
- size_t iter ;
875
874
double chisq_dof_old ;
876
875
jabs_message (MSG_INFO , "iter | cond(J) | |f(x)| | chisq/dof | evals | spectra | time cumul | time/spectrum |\n" );
877
876
jabs_message (MSG_INFO , " | | | | cumul. | cumul. | s | ms |\n" );
878
- for (iter = 0 ; iter <= maxiter ; iter ++ ) {
879
- fit_data -> stats .iter_call = 0 ;
880
- fit_data -> stats .iter = iter ;
877
+ for (size_t iter = 0 ; iter <= maxiter ; iter ++ ) {
878
+ fit -> stats .iter_call = 0 ;
879
+ fit -> stats .iter = iter ;
881
880
if (iter ) {
882
- chisq_dof_old = fit_data -> stats .chisq_dof ;
883
- fit_data -> stats .cputime_iter = 0.0 ;
884
- fit_data -> stats .n_evals_iter = 0 ;
885
- fit_data -> stats .n_spectra_iter = 0 ;
881
+ chisq_dof_old = fit -> stats .chisq_dof ;
882
+ fit -> stats .cputime_iter = 0.0 ;
883
+ fit -> stats .n_evals_iter = 0 ;
884
+ fit -> stats .n_spectra_iter = 0 ;
886
885
status = gsl_multifit_nlinear_iterate (w );
887
886
DEBUGMSG ("Iteration status %i (%s)" , status , gsl_strerror (status ));
888
887
}
889
- if (fit_data -> stats .error ) {
890
- return fit_data -> stats .error ;
888
+ if (fit -> stats .error ) {
889
+ return fit -> stats .error ;
891
890
}
892
891
if (status == GSL_ENOPROG && iter == 1 ) {
893
892
return FIT_ERROR_NO_PROGRESS ;
894
893
}
895
- fit_iter_stats_update (fit_data , w );
896
- fit_iter_stats_print (& fit_data -> stats );
894
+ fit_iter_stats_update (fit , w );
895
+ fit_iter_stats_print (& fit -> stats );
897
896
#ifdef DEBUG
898
897
if (fit_data -> stats .phase > FIT_PHASE_FAST ) {
899
898
char * jacobian_filename ;
@@ -904,8 +903,8 @@ int jabs_gsl_multifit_nlinear_driver(const size_t maxiter, const double xtol, co
904
903
}
905
904
}
906
905
#endif
907
- if (fit_data -> fit_iter_callback ) {
908
- if (fit_data -> fit_iter_callback (fit_data -> stats )) {
906
+ if (fit -> fit_iter_callback ) {
907
+ if (fit -> fit_iter_callback (fit -> stats )) {
909
908
return FIT_ERROR_ABORTED ;
910
909
}
911
910
}
@@ -916,8 +915,8 @@ int jabs_gsl_multifit_nlinear_driver(const size_t maxiter, const double xtol, co
916
915
if (status == GSL_SUCCESS ) {
917
916
return FIT_SUCCESS_DELTA ;
918
917
}
919
- double chisq_change = 1.0 - fit_data -> stats .chisq_dof / chisq_dof_old ;
920
- if (fit_data -> stats .chisq_dof > chisq_dof_old ) {
918
+ double chisq_change = 1.0 - fit -> stats .chisq_dof / chisq_dof_old ;
919
+ if (fit -> stats .chisq_dof > chisq_dof_old ) {
921
920
jabs_message (MSG_WARNING , "Chisq increased, this probably shouldn't happen.\n" );
922
921
}
923
922
if (chisq_change < chisq_tol ) {
@@ -1055,8 +1054,8 @@ int fit_uncertainty_spectra(const fit_data *fit, const gsl_matrix *J, const gsl_
1055
1054
return EXIT_SUCCESS ;
1056
1055
}
1057
1056
1058
- int fit (fit_data * fit ) {
1059
- struct fit_params * fit_params = fit -> fit_params ;
1057
+ int fit_do (fit_data * fit ) {
1058
+ fit_params * fit_params = fit -> fit_params ;
1060
1059
if (!fit_params || fit_params -> n_active == 0 ) {
1061
1060
jabs_message (MSG_ERROR , "No parameters to fit.\n" );
1062
1061
return EXIT_FAILURE ;
@@ -1280,7 +1279,7 @@ int fit_set_roi_from_string(roi *r, const char *str) {
1280
1279
return EXIT_SUCCESS ;
1281
1280
}
1282
1281
1283
- double fit_emin (struct fit_data * fit , size_t i_det ) {
1282
+ double fit_emin (fit_data * fit , size_t i_det ) {
1284
1283
double emin = fit -> sim -> beam_E ;
1285
1284
for (size_t i_range = 0 ; i_range < fit -> n_fit_ranges ; i_range ++ ) {
1286
1285
const roi * r = & (fit -> fit_ranges [i_range ]);
0 commit comments