Skip to content

Ensure positivity of the nu_eb + 12C cross section - #73

Open
hecsanper wants to merge 3 commits into
SNEWS2:mainfrom
hecsanper:c12eb-xsec-fix
Open

hecsanper wants to merge 3 commits into
SNEWS2:mainfrom
hecsanper:c12eb-xsec-fix

Conversation

@hecsanper

Copy link
Copy Markdown

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:

a1, a2, a3 = -106.3, 25.15, 0.3697
sigma = 9.55e-46 * (a1 * (eNu - e_thr) + a2 * (eNu - e_thr)**2 + a3 * (eNu - e_thr)**3)

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_dE directly 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_values now 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 ran sntools.setup() and used the output to replace tests/sample_outfile.kin and to replace the hash in the setup function in src/sntools/__init__.py. After updating the sample output file and its hash, I have verified that sntools.setup() runs without errors, both locally and via the GitHub workflows integration test. (I also added workflow_dispatch to .github/workflows/test-and-lint.yml so 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.)

Copilot AI balanced review requested due to automatic review settings October 30, 2026 20:27

This comment was marked as spam.

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