Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 22, 2024
1 parent ca39a7d commit b3e1c4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions appletree/components/er.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, *args, **kwargs):
self.register_all(apt.plugins.reconstruction)
self.register_all(apt.plugins.efficiency)


class ERPeak(ComponentSim):
norm_type = "on_pdf"
add_eps_to_hist = False
Expand Down
35 changes: 23 additions & 12 deletions appletree/plugins/er_sr_microphys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from jax import scipy as jsp
from jax import jit
from functools import partial
import scipy
import scipy

from appletree import randgen
from appletree.plugin import Plugin
Expand All @@ -11,14 +11,21 @@

export, __all__ = exporter(export_self=False)


def atanh_clip(x):
return jnp.arctanh((x + 1)%2 - 1)
return jnp.arctanh((x + 1) % 2 - 1)


def n_photon_mean_model0(num_quanta, p_mu_0):
return jnp.sin(jsp.special.erf(atanh_clip(jnp.sqrt(jnp.arcsinh(num_quanta))))) * num_quanta / p_mu_0
return (
jnp.sin(jsp.special.erf(atanh_clip(jnp.sqrt(jnp.arcsinh(num_quanta)))))
* num_quanta
/ p_mu_0
)


def n_photon_std_model0(num_quanta, p_sigma_0):
return (num_quanta * p_sigma_0) + jnp.log2((jnp.log2(jnp.log2(jnp.arcsinh(num_quanta))))**6)
return (num_quanta * p_sigma_0) + jnp.log2((jnp.log2(jnp.log2(jnp.arcsinh(num_quanta)))) ** 6)


@export
Expand All @@ -40,21 +47,25 @@ def simulate(self, key, parameters, energy):

@export
class Emission(Plugin):
"""A symbolic-regression-based empirical simulation for microphysics aiming at parameter number
reduction.
Wrapped up IonizationER + mTI + RecombFluct + TrueRecombER + RecombinationER in traditional ER
microphysics.
"""
A symbolic-regression-based empirical simulation for microphysics aiming at parameter number reduction.
Wrapped up IonizationER + mTI + RecombFluct + TrueRecombER + RecombinationER in traditional ER microphysics.
"""

depends_on = ["num_quanta"]
provides = ["num_photon", "num_electron"]
parameters = ("p_mu_0", "p_sigma_0")

@partial(jit, static_argnums=(0,))
def simulate(self, key, parameters, num_quanta):
n_photon_mean = n_photon_mean_model0(num_quanta, parameters['p_mu_0'])
n_photon_std = n_photon_std_model0(num_quanta, parameters['p_sigma_0'])
key, _num_photon = randgen.truncate_normal(key, n_photon_mean, n_photon_std,
vmin=0, vmax=num_quanta)
n_photon_mean = n_photon_mean_model0(num_quanta, parameters["p_mu_0"])
n_photon_std = n_photon_std_model0(num_quanta, parameters["p_sigma_0"])
key, _num_photon = randgen.truncate_normal(
key, n_photon_mean, n_photon_std, vmin=0, vmax=num_quanta
)
num_photon = _num_photon.round().astype(int)
num_electron = num_quanta - num_photon
return key, num_photon, num_electron

0 comments on commit b3e1c4e

Please sign in to comment.