Skip to content

Commit

Permalink
Power Spectrum LogEnergy Distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
Areustle committed Dec 2, 2021
1 parent 84d7a5f commit 9e424d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/nuspacesim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __call__(self) -> dict:

@dataclass
class PowerSpectrum:
index: float = 0.5
index: float = 2.0
"""Power Law Log Energy of the tau neutrinos in GeV."""

lower_bound: float = 6.0
Expand Down
7 changes: 6 additions & 1 deletion src/nuspacesim/simulation/spectra/local_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ def spectra_histogram(inputs, results, *args, **kwargs):
log_e_nu = results

color = "g"
fig, ax = plt.subplots(1, constrained_layout=True)
fig = plt.figure(figsize=(8, 7), constrained_layout=True)
ax = fig.add_subplot(211)
ax.hist(log_e_nu, 100, log=False, facecolor=color)
ax.set_xlabel(f"log(E_nu) of {N} events")

ax = fig.add_subplot(212)
ax.hist(log_e_nu, 100, log=True, facecolor=color)
ax.set_xlabel(f"log(E_nu) of {N} events")

fig.suptitle("Energy Spectra Histogram, Log(E_nu)")
plt.show()
15 changes: 7 additions & 8 deletions src/nuspacesim/simulation/spectra/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ def energy_spectra(
return np.full(shape=(N), fill_value=spectra.log_nu_tau_energy)

if isinstance(spectra, PowerSpectrum):
delta = 10 ** spectra.upper_bound - 10 ** spectra.lower_bound
return 10 ** spectra.lower_bound + delta * np.random.power(
spectra.index, size=N
)
p = spectra.index
a = 10 ** spectra.lower_bound
b = 10 ** spectra.upper_bound
mp = 1 - p
u = np.random.uniform(0.0, 1.0 + np.finfo(np.float64).eps, size=N)
return np.reciprocal(mp) * np.log10(u * (b ** mp - a ** mp) + a ** mp)

if isinstance(spectra, Callable):
return spectra(*args, size=N, **kwargs)
Expand All @@ -74,7 +76,4 @@ def __init__(self, config: NssConfig):
self.config = config

def __call__(self, N, *args, **kwargs):
es = energy_spectra(N, self.config.simulation.spectrum, *args, **kwargs)
print(np.min(es), np.max(es))
print(np.log10(np.min(es)), np.log10(np.max(es)))
return np.log10(es)
return energy_spectra(N, self.config.simulation.spectrum, *args, **kwargs)

0 comments on commit 9e424d5

Please sign in to comment.