codice:
const double c14_energy_spectrum[] = {
0.00000, 0.01047, 0.01071, 0.01098, 0.01122,
/* @ 7.81 keV --> */ 0.01143, 0.01160, 0.01175, 0.01186, 0.01195,
/* @ 15.63 keV --> */ 0.01202, 0.01207, 0.01209, 0.01210, 0.01210,
/* @ 23.44 keV --> */ 0.01207, 0.01204, 0.01199, 0.01193, 0.01185,
/* @ 31.25 keV --> */ 0.01177, 0.01168, 0.01158, 0.01146, 0.01135,
/* @ 39.07 keV --> */ 0.01122, 0.01108, 0.01094, 0.01080, 0.01064,
/* @ 46.88 keV --> */ 0.01049, 0.01032, 0.01016, 0.00998, 0.00981,
/* @ 54.69 keV --> */ 0.00963, 0.00944, 0.00926, 0.00907, 0.00887,
/* @ 62.51 keV --> */ 0.00868, 0.00848, 0.00828, 0.00808, 0.00788,
/* @ 70.32 keV --> */ 0.00768, 0.00747, 0.00727, 0.00707, 0.00686,
/* @ 78.14 keV --> */ 0.00665, 0.00645, 0.00624, 0.00604, 0.00584,
/* @ 85.95 keV --> */ 0.00563, 0.00543, 0.00523, 0.00503, 0.00483,
/* @ 93.76 keV --> */ 0.00464, 0.00444, 0.00425, 0.00406, 0.00387,
/* @ 101.58 keV --> */ 0.00369, 0.00351, 0.00333, 0.00315, 0.00298,
/* @ 109.39 keV --> */ 0.00281, 0.00265, 0.00248, 0.00232, 0.00217,
/* @ 117.20 keV --> */ 0.00202, 0.00187, 0.00173, 0.00160, 0.00146,
/* @ 125.02 keV --> */ 0.00134, 0.00121, 0.00110, 0.00098, 0.00088,
/* @ 132.83 keV --> */ 0.00077, 0.00068, 0.00059, 0.00050, 0.00043,
/* @ 140.64 keV --> */ 0.00035, 0.00029, 0.00023, 0.00018, 0.00013,
/* @ 148.46 keV --> */ 0.00009, 0.00006, 0.00003, 0.00001, 0.00000,
/* @ 156.27 keV --> */ 0.00000};
// Convolution
double* calculate_conv (double* energy_spectrum1, double* energy_spectrum2) {
unsigned n_pts1 = sizeof(energy_spectrum1)/sizeof(double);
unsigned n_pts2 = sizeof(energy_spectrum2)/sizeof(double);
unsigned n_pts = n_pts1 + n_pts2;
double* conv_spectra;
conv_spectra = new double[n_pts];
for (unsigned i = 0; i < n_pts; i++) {
double sum = 0;
for (unsigned j = 0; j <= i; j++) {
if (j > n_pts1 - 1 || (i - j) > n_pts2 - 1)
continue;
sum += energy_spectrum1[j] * energy_spectrum2[i-j];
}
conv_spectra[i] = sum;
}
return conv_spectra;
}
// Call function to convolve spectra
double* conv_energy = calculate_conv (c14_energy_spectrum, c14_energy_spectrum);