Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement optional logarithmic sampling of the photon energies #476

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ehlertdo
Copy link

@ehlertdo ehlertdo commented Mar 7, 2024

Hey,
this is the follow-up to #474 . With this change it is possible to sample photons from tabulated photon fields where the maximum tabulated energy is much larger than the highest energies where the field density is non-zero.
I have attached a minimal CRPropa 1D simulation script that illustrates a scenario where the current version of CRPropa fails to find photons and stops with error: no photon found in sampleEps, please make sure that photon field provides photons for the interaction by adapting the energy range of the tabulated photon field.
The files for such a tabulated (CMB-like) photon field are also included and must be placed in the share folder of the local CRPropa installation.
Let me know what you think!
supplementary_files.tar.gz

@JulienDoerner
Copy link
Member

Hey @ehlertdo,
changing the prior sampling will change the sampled photons.
This problem is small as long as the photon energy range is small, but for large primary energy the change is significant.

For example you can see in this plot the difference of both sampling techniques. Here I ran the sampleEps function for $10^4$ times on the CMB for a proton with $E = 10^{21} \ eV$.

grafik

I guess this problem can be solved by a diffrent way of evaluating the propability after the sampling. But I do not directly now how to implement this.

@JulienDoerner
Copy link
Member

JulienDoerner commented Mar 11, 2024

I guess an other way of solving the problem could be a change in the maximum photon energy

double TabularPhotonField::getMaximumPhotonEnergy(double z) const{

I would suggest to add a threshold photon density (maybe even 0) to evaluate the maximum energy. In this case the region with $n = 0$ would not be sampled.

@JulienDoerner JulienDoerner self-assigned this Mar 11, 2024
@ehlertdo
Copy link
Author

Good point about the difference in the sampled distribution. I had only checked that sampling from the build-in CMB and my tabulated version yields the same photon distribution after the modification. I will try to think about a solution.
In general, for the rejection sampling one can define an arbitrary proposal function which should ideally be similar to the true distribution of photons. One could consider providing a range of possible proposal distributions to choose from depending on the type of photon field, as opposed to just a flat prior. While this could speed up the sampling it would add a lot of complexity to the code.

@ehlertdo
Copy link
Author

I implemented a photon sampling with a decreasing-power-law proposal function. Now the sampled distribution for interactions with a (I think) $10^{21}~\mathrm{eV}$ proton agrees with the default implementation in CRPropa. However, because each sample requires the evaluation of the inverse and regular CDF of the proposal function the sampling time increases by a factor of 5-10 (tested for 10k photons). Perhaps there is somem room for improvement here. The upside is that it works even in the scenario with extremely large maximum tabulated photon energies where the normal implementation fails.
hist_sampled_eps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants