CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
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
Fix in the candidate's constructor, which ignored any weight that was given in the constructor.
Fixed the setWeight call in addSecondary to set the secondary's weight to w*w_0, where w_0 is the parent particle's weight at creation of the secondary and w is an optional factor for the secondary weight which defaults to w=1.
In addition to the setWeight method an updateWeight method was introduced. Which changes a candidate's weight by multiplication without the need of a getWeight call. --> Used in the acceleration module.
Including simple tests of the set/update/getWeight methods and weight inheritance.
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.
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 theCandidate
class, so that secondary particles will inherit their parents weights on default.Details
setWeight
method anupdateWeight
method was introduced. Which changes a candidate's weight by multiplication without the need of a getWeight call. --> Used in the acceleration module.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.