CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
65 stars 66 forks source link

Inheriting weights from parent particles #396

Closed lukasmerten closed 2 years ago

lukasmerten commented 2 years ago

Issue

Primary candidate weights, e.g. calculated and set by the SourceTargetedEmission feature, have not been properly inherited to their secondaries. The secondaries were always created with a default value of weight=1. This could have led to wrong particle spectra etc., when the targeting method was used in combination with non-electromagnetic interactions.[1]

Solution

Change the behavior of the addSecondary method of the Candidate class, so that secondary particles will inherit their parents weights on default.

Details

Test

The issue was first noticed by Simone Rossoni, who provided us with some test cases. Additional checks and suggestions for the implementation came from @avvliet. To illustrate the test here are some before and after plots: The figure energy-spectrum-targeted-master.pdf shows results for a test simulation defined in targeted-int.txt, where the weights of the output file have been included. For comparison a run without targeting [2] was done, which lead to the following spectra energy-spectrum-not-targeted-int-B.pdf. The last plot shows now a run including targeting done with the fixes proposed in this PR energy-spectrum-targeted-int-B.pdf.

A simpler test can be done based on this jupyter notebook Target.zip. Here, a proxy for a not working weight inheritance are weights = 1. After the fix no weights equal to one are found in the output.

[1] In all EM* and the Synchrotronradiation module the inheritance was manually implemented due to the thinning procedures. [2] Emitting all particles at the source in a cone with the same opening angle as the targeting method, to get similar statistics.

lukasmerten commented 2 years ago

I hope I did not forget any style updates.