Closed mskarl closed 1 year ago
This is a numerical issue. It happens because the neutrino energy probability per bin has very small values for high energies when the spectral index is extremely soft:
[7.91065093e-02 2.67555284e-01 3.08171310e-01 1.96467446e-01
8.34041164e-02 3.94795480e-02 1.58398740e-02 6.26667326e-03
2.44449702e-03 8.30095346e-04 2.95695299e-04 9.89295692e-05
2.91193705e-05 8.03339192e-06 2.14109336e-06 5.54931404e-07
1.31573344e-07 3.20391743e-08 7.66283566e-09 1.58228759e-09
3.29396317e-10 6.53738558e-11 1.32045069e-11 2.64000713e-12
5.01224077e-13 9.91672101e-14 1.81044808e-14 2.97017111e-15
5.47836854e-16 8.85532170e-17 1.45610807e-17 2.36148615e-18
3.09097602e-19 4.49721198e-20 6.23703166e-21]
On the other hand, we need the cumsum_per_bin
to be monotonically increasing to build the spline for the inverse sampling.
To fix this behaviour we cut the prob_per_bin
array so that all its items are >1e-15. This should be safe enough since the probability to sample those energies is so low.
Simulating a source at the direction of TXS with gamma = 5, I get the following error:
File ~/ice-cube/skyllh/skyllh/analyses/i3/publicdata_ps/signal_generator.py:91, in PDDatasetSignalGenerator._generate_inv_cdf_spline(self, flux_model, log_e_min, log_e_max) 89 cum_per_bin = np.concatenate(([0], cum_per_bin)) 90 if np.any(np.diff(cum_per_bin) == 0): ---> 91 raise ValueError( 92 'The cumulative sum of the true energy probability is not ' 93 'monotonically increasing! Values of the cumsum are ' 94 f'{cum_per_bin}.') 96 bin_centers = np.concatenate(([low_bin_edges[0]], bin_centers)) 98 # Build a spline for the inverse CDF.
ValueError: The cumulative sum of the true energy probability is not monotonically increasing! Values of the cumsum are [0. 0.04514964 0.23739487 0.51615731 0.73989165 0.85946367 0.93071848 0.96670947 0.98463529 0.99343831 0.99720162 0.99888929 0.99960012 0.99986353 0.99995501 0.99998571 0.99999572 0.99999871 0.99999963 0.9999999 0.99999997 0.99999999 1. 1.