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

Improvemente of Directed Emission Module #438

Closed simonerossoni1996 closed 9 months ago

simonerossoni1996 commented 10 months ago

This PR introduces changes to the SourceDirectedEmission() module.

The SourceDirectedEmission() module samples a random vector from the von Mises-Fischer distribution defined by a mean direction and a concentration parameter. This vector is then used for the injection of the candidate. The sampling was done as in http://people.csail.mit.edu/jstraub/download/straub2017vonMisesFisherInference.pdf .

Given the presence of a function for random sampling from a von Mises-Fischer distribution (in Random.cpp), the sampling procedure was modified. Some functions in the module are no longer needed.

Thanks to @avvliet for help with the changes and with the PR.

simonerossoni1996 commented 9 months ago

Here I describe a test of the new module implementation. A simulation is performed with the von Mises-Fischer injection module. The geometrical setting of the simulation can be found in the simulation script. The von Mises-Fischer parameters are kappa=10 and injection along the z-axis.

------ SIMULATION SCRIPT ------ from crpropa import * import numpy as np

sim = ModuleList()

sim.add(SimplePropagation()) sim.add(MaximumTrajectoryLength(1.1 * Mpc))

obs = Observer() obs.add(ObserverSurface(Sphere(Vector3d(0.0,0.0,0.0) Mpc, 1.0 Mpc))) output = TextOutput("output.txt",Output.Event3D) obs.onDetection(output) sim.add(obs)

source = Source() source.add(SourcePosition(Vector3d(0.0,0.0,0.0) Mpc)) source.add(SourceDirectedEmission(Vector3d(0.0,0.0,1.0), 10.0)) source.add(SourceEnergy(1.0 EeV)) source.add(SourceParticleType(nucleusId(1,1)))

sim.setShowProgress(True) sim.run(source,100000) output.close() ------------

The simulation output is used to compute the reduced probability distribution functions of the von Mises-Fischer function at the injection. In particular, the reduced probability distribution functions of the two injection angles are obtained and compared with the analytic expression, obtained by integrating the von Mises-Fischer distribution.

It can be seen that the new implementation continues to reproduce the required injection distribution.

JulienDoerner commented 9 months ago

hey @simonerossoni1996, I tested the PR with your script and I could not found any difference. Also the unit tests are still runing so everything seems to be okay from my point.