Retrieve the average energy of the spectrum
Virtual X-Ray Imaging Library on GPU
Brought to you by:
zedbluffer
Retrieve the average energy of the spectrum as:
// Compute the average energy of a photon
std::vector<double> energy_bins = getEnergyBins("keV");
std::vector<double> photon_counts = getPhotonCountsPerCm2At1m(true);
double total_energy_polychromatic_beam = 0.0;
double number_of_photons_polychromatic_beam = 0;
// C++ 23
// for (auto [energy, count]: std::views::zip(energy_bins, photon_counts)) {
// total_energy_polychromatic_beam += energy * count;
// number_of_photons_polychromatic_beam += count;
// }
for (size_t i = 0; i < photon_counts.size(); ++i) {
auto count = photon_counts[i];
total_energy_polychromatic_beam += energy_bins[i] * count;
number_of_photons_polychromatic_beam += count;
}
double photon_energy_in_keV = total_energy_polychromatic_beam / number_of_photons_polychromatic_beam;