Skip to content

Commit

Permalink
scintillate: implement particle types as constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu committed Sep 17, 2024
1 parent 901ea39 commit 3973710
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/legendoptics/scintillate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ def get_particle(self, name: str) -> Optional[ScintParticle]: # noqa: UP007
ComputedScintParams = NewType(
"ComputedScintParams", tuple[float, float, np.ndarray, np.ndarray]
)
PARTICLE_INDICES = {"electron": 0, "alpha": 1, "ion": 2, "deuteron": 3, "triton": 4}
PARTICLE_INDEX_ELECTRON = 0
PARTICLE_INDEX_ALPHA = 1
PARTICLE_INDEX_ION = 2
PARTICLE_INDEX_DEUTERON = 3
PARTICLE_INDEX_TRITON = 4
PARTICLE_INDICES = {
"electron": PARTICLE_INDEX_ELECTRON,
"alpha": PARTICLE_INDEX_ALPHA,
"ion": PARTICLE_INDEX_ION,
"deuteron": PARTICLE_INDEX_DEUTERON,
"triton": PARTICLE_INDEX_TRITON,
}


def particle_to_index(particle: str) -> ParticleIndex:
"""Converts the given G4 scintillation particle name to a module-internal index."""
return PARTICLE_INDICES[particle.lower()]


def precompute_scintillation_params(
Expand All @@ -60,7 +76,8 @@ def precompute_scintillation_params(

electron = scint_config.get_particle("electron")
if electron is None:
raise ValueError()
msg = "missing electron scintillation particle component (used as fallback for all other)"
raise ValueError(msg)
for k, v in PARTICLE_INDICES.items():
p = scint_config.get_particle(k)
p = electron if p is None else p
Expand All @@ -75,11 +92,6 @@ def precompute_scintillation_params(
return scint_config.flat_top.to("1/keV").m, fano, time_components, particles


def particle_to_index(particle: str) -> ParticleIndex:
"""Converts the given G4 scintillation particle name to a module-internal index."""
return PARTICLE_INDICES[particle.lower()]


@njit
def scintillate_local(
params: ComputedScintParams,
Expand Down

0 comments on commit 3973710

Please sign in to comment.