Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I am Héctor Sanchis Pérez, and I am developing a supernova neutrino code that uses sntools as a dependency.
During my development, I have noticed a problem with the cross section in sntools' c12eb channel (anti-nu_e + 12C -> X + e+) becoming negative. I have solved this problem in my sntools fork, and I think the solution could also be helpful for other people using sntools, so I am sending this pull request with my solution.
I describe the problem and my proposed solution below. If you think this is a suitable solution, I would be happy to have it merged into sntools. Conversely, if you notice any issues or things that could be improved, please let me know.
Best regards,
Héctor Sanchis Pérez
The problem
In nuclear channels, sntools currently uses a polynomial fit of order 3 to calculate the cross section. Since these channels are typically very subdominant and thus have large statistical errors, this level of precision is generally fine for them.
However, please take a look at the polynomial fit used in the c12eb channel and its parameters:
Note that a1, the coefficient of the linear term, is negative. As a consequence, for small values of (eNu - e_thr) (That is, for energies slightly above the channel's threshold), the cross section becomes negative. More specifically, taking into account that e_thr = 14.39 MeV, the cross section is negative until approximately E_nu = 18.3 MeV (almost 4 MeV above the threshold). This is unphysical, and could lead to unexpected incorrect behaviour for the generation of events at these (perfectly valid) energies.
Proposed solution
Instead of the polynomial fit, my solution employs interpolation, using data from table V in arXiv:nucl-th/9903022 (This is the same reference that is already mentioned in the code, the current polynomial fit is a fit to the data in this same table). Apart from the data in the table, I added a single additional point at the threshold, stating that sigma=0 at e_thr (by definition of the threshold), so the interpolator is well-defined until the threshold and no extrapolation is needed. (Note that, below e_thr,
dSigma_dEdirectly returns zero without calling the interpolator.)Specifically, I used Pchip interpolation, using scipy's
PchipInterpolator(You can read more about it here.). The reason why I chose it is that Pchip interpolation preserves monotonicity in the interpolation data, so, since the values in the table are positive and increasing, it guarantees that the interpolation will always return a positive cross section. It is also continuous and differentiable, so it is smoother than linear interpolation.The interpolator is only constructed once, when importing the module. This makes the solution efficient: Each call to the cross section function does not need to reconstruct the interpolator, it only needs to call the interpolator that is already loaded in memory.
In conclusion, this solution guarantees positivity of the cross section and, as a side effect, also improves its agreement with the data from arXiv:nucl-th/9903022.
Testing
I updated the tests corresponding to this channel (
test_c12eb.py). To make it easier to verify them independently,test_dSigma_dE_valuesnow directly uses values from Table V in arXiv:nucl-th/9903022 multiplied by the appropriate conversion factor, so the test checks that the returned cross section coincides with the values in that table, for selected example values.In addition, since the change in the cross section alters the sample output file obtained when running
sntools.setup(), I ransntools.setup()and used the output to replacetests/sample_outfile.kinand to replace the hash in the setup function insrc/sntools/__init__.py. After updating the sample output file and its hash, I have verified thatsntools.setup()runs without errors, both locally and via the GitHub workflows integration test. (I also addedworkflow_dispatchto.github/workflows/test-and-lint.ymlso that the GitHub workflow tests can be run manually, which makes it easier to test the code without having to work on the main branch.)