Skip to content

Commit

Permalink
Second try of fixing #14 started from a clean branch
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasplum committed Oct 23, 2023
1 parent e892e8c commit 0b5b481
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/simweights/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"CircleInjector",
"CorsikaWeighter",
"NaturalRateCylinder",
"IceTopNaturalRateCylinder",
"UniformSolidAngleCylinder",
"TIG1996",
"FixedFractionFlux",
Expand Down Expand Up @@ -63,6 +64,11 @@
from ._nugen_weighter import NuGenWeighter
from ._pdgcode import PDGCode
from ._powerlaw import PowerLaw
from ._spatial import CircleInjector, NaturalRateCylinder, UniformSolidAngleCylinder
from ._spatial import (
CircleInjector,
IceTopNaturalRateCylinder,
NaturalRateCylinder,
UniformSolidAngleCylinder,
)
from ._utils import corsika_to_pdg
from ._weighter import Weighter
5 changes: 3 additions & 2 deletions src/simweights/_icetop_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ._generation_surface import GenerationSurface, generation_surface
from ._powerlaw import PowerLaw
from ._spatial import CircleInjector
from ._spatial import IceTopNaturalRateCylinder
from ._utils import get_column, get_table
from ._weighter import Weighter

Expand All @@ -25,7 +25,8 @@ def sframe_icetop_surface(table: Any) -> GenerationSurface:
get_column(table, "min_energy")[i],
get_column(table, "max_energy")[i],
)
spatial = CircleInjector(
spatial = IceTopNaturalRateCylinder(
0, # set cylinder height to 0 to get simple surface plane
get_column(table, "sampling_radius")[i],
np.cos(get_column(table, "max_zenith")[i]),
np.cos(get_column(table, "min_zenith")[i]),
Expand Down
23 changes: 23 additions & 0 deletions src/simweights/_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ def pdf(self, cos_zen: ArrayLike) -> NDArray[np.float64]:
)


class IceTopNaturalRateCylinder(CylinderBase):
r"""Angular distribution when zenith distribution matched the natural rate of an isotropic source.
For a given zenith angle the intensity of particles thrown was proportional to the cross-sectional area
perpendicular to the direction of the particle.
"""

def __init__(self, length: float, radius: float, cos_zen_min: float, cos_zen_max: float) -> None:
super().__init__(length, radius, cos_zen_min, cos_zen_max)
self.etendue = (
2 * np.pi * (self.cos_zen_max - self.cos_zen_min) * self._cap
) # This is needed to make the tests work
self._normalization = 1 / self.etendue

def pdf(self, cos_zen: ArrayLike) -> NDArray[np.float64]:
cosz = np.asfarray(cos_zen)
return np.piecewise(
cosz,
[(cosz >= self.cos_zen_min) & (cosz <= self.cos_zen_max)],
[self._normalization],
)


class CircleInjector:
"""Particles are generated on a circle perpendicular to the direction of the particle.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_icetop_weighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestIceTopWeighter(unittest.TestCase):
def test_icetop_corsika(self):
nevents = 10000
pdgid = 12
c1 = simweights.CircleInjector(300, 0, 1)
c1 = simweights.IceTopNaturalRateCylinder(0, 300, 0, 1)
p1 = simweights.PowerLaw(0, 1e3, 1e4)

weight = np.zeros(nevents, dtype=particle_dtype)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import unittest

import numpy as np
from simweights import CircleInjector, NaturalRateCylinder, UniformSolidAngleCylinder
from simweights import (
CircleInjector,
NaturalRateCylinder,
UniformSolidAngleCylinder,
)
from simweights._spatial import CylinderBase


Expand Down

0 comments on commit 0b5b481

Please sign in to comment.