Skip to main content

Generates neutrino events for large volume Cherenkov telescopes

Project description

LeptonInjector

LeptonInjector is a group of modules used to create events in IceCube. This code represents a standalone version of the original LeptonInjector which has been trimmed of the proprietary Icetray dependencies. It is currently fully functional and compatible with LeptonWeighter.

To use it, you will

1. Prepare a Injector object (or list of Injector objects).

2. Use one injector object, along with several generation parameters, to create a Controller object. These were called MultiLeptonInjector in the original code. 

3. Add more injectors to the controller object using the add injector function. Verify that the controller is properly configured.

4. Specify the full paths and names of the destination output file and LeptonInjector Configuration (LIC) file.

5. Call Controller.Execute(). This will run the simulation. 

For an example of this in action, see $root/resources/example/inject_muons.py

To learn about the LIC files and weighting, see https://github.com/IceCubeOpenSource/LeptonWeighter

Installation

Quick Start: pip install (Recommended)

The easiest way to install LeptonInjector is via pip:

pip install .

This will automatically:

  • Build the C++ library with pybind11 bindings
  • Install all Python dependencies
  • Set up the package for immediate use

Requirements for pip install

On macOS with Homebrew:

brew install hdf5 boost cmake
# Install photospline separately following its documentation

On Ubuntu/Debian:

sudo apt-get install libhdf5-dev libboost-all-dev cmake
# Install photospline separately following its documentation

Optional dependencies

For HDF5 file handling in Python:

pip install ".[hdf5]"

Python Usage

Once installed, you can import and use LeptonInjector directly:

import LeptonInjector as LI

# Create an injector for muon neutrino charged-current interactions
injector = LI.Injector(
    NEvents=1000,
    FinalType1=LI.Particle.ParticleType.MuMinus,
    FinalType2=LI.Particle.ParticleType.Hadrons,
    DoublyDifferentialCrossSectionFile="path/to/differential_xs.fits",
    TotalCrossSectionFile="path/to/total_xs.fits",
    Ranged=True
)

# Create a controller to manage the simulation
controller = LI.Controller(
    injectors=injector,
    minimum_energy=1e2,  # GeV
    maximum_energy=1e6,  # GeV
    spectral_index=2.0,
    minimum_azimuth=0,
    maximum_azimuth=2*LI.Constants.pi,
    minimum_zenith=0,
    maximum_zenith=LI.Constants.pi
)

# Configure output files
controller.NameOutfile("output.h5")
controller.NameLicFile("config.lic")

# Run the simulation
controller.Execute()

Earth Model Services

LeptonInjector includes Earth model services for density calculations:

import LeptonInjector as LI

# Create an Earth model service with PREM
ems = LI.EarthModelService(
    "mymodel",
    tablepath="/path/to/earthparams/",
    earthmodels=["PREM_mmc.dat"],
    materialmodels=["Standard.dat"],
    icecapname="SimpleIceCap",
    icecapangle=20.0 * LI.Constants.degrees,
    detectordepth=1948.0 * LI.Constants.m
)

# Get density at a position (detector-centered coordinates)
pos = LI.LI_Position(0, 0, -1000)  # 1km below detector center
density = ems.GetDensityInCGS(pos)
print(f"Density: {density} g/cm^3")

# Convert to Earth-centered coordinates
earth_pos = ems.GetEarthCoordPosFromDetCoordPos(pos)

# Get the medium type at that position
medium = ems.GetMedium(earth_pos)
print(f"Medium: {LI.EarthModelService.GetMediumTypeString(medium)}")

# Calculate column depth between two points
pos1 = LI.LI_Position(0, 0, 0)
pos2 = LI.LI_Position(0, 0, -10000)
column_depth = ems.GetColumnDepthInCGS(pos1, pos2)
print(f"Column depth: {column_depth} g/cm^2")

# Get lepton range
direction = LI.LI_Direction(LI.Constants.pi, 0)  # straight down
energy = 1e5  # 100 TeV
muon_range = ems.GetLeptonRangeInMeterFrom(pos, direction, energy, isTau=False)
print(f"Muon range: {muon_range} m")

Available Earth Model Enums

# Medium types
LI.MediumType.INNERCORE
LI.MediumType.OUTERCORE
LI.MediumType.MANTLE
LI.MediumType.ROCK
LI.MediumType.ICE
LI.MediumType.WATER
LI.MediumType.AIR
LI.MediumType.VACUUM

# Ice cap types
LI.IceCapType.NOICE
LI.IceCapType.ICESHEET
LI.IceCapType.SIMPLEICECAP

# Integration types for density integration
LI.IntegType.PATH    # Along a path
LI.IntegType.RADIUS  # Projected on radial direction
LI.IntegType.CIRCLE  # 2*pi*r weighted
LI.IntegType.SPHERE  # 4*pi*r^2 weighted (volume mass)

# Lepton range calculation options
LI.LeptonRangeOption.DEFAULT  # Dima's fitting function
LI.LeptonRangeOption.LEGACY   # Legacy NuGen equation
LI.LeptonRangeOption.NUSIM    # Gary's fitting function

Utility Functions

# Geometry calculations
impact, t, closest_pos = LI.GetImpactParameter(position, direction)
n_intersections, start_pos, end_pos = LI.GetIntersectionsWithSphere(pos, dir, radius)
n_intersections, enter_dist, exit_dist = LI.GetDistsToIntersectionsWithSphere(pos, dir, radius)

# Lepton range in meter-water-equivalent
range_mwe = LI.GetLeptonRange(energy, isTau=False)

# Unit conversions
mwe = LI.ColumnDepthCGStoMWE(column_depth_cgs)
cgs = LI.MWEtoColumnDepthCGS(range_mwe)

Dependencies (for manual installation)

All of the dependencies are already installed on the CVMFS environments on the IceCube Cobalt testbeds.

For local installations, you need the following:

For building py-bindings:

  • Python >= 3.8

  • pybind11 (used for the pip-installable Python bindings)

  • BOOST headers (for some internal functionality)

Included Dependencies

These are not ostensibly a part of LeptonInjector, but are included for its functionality. They were developed by the IceCube Collaboration and modified slightly to use the LeptonInjector datatypes instead of the IceCube proprietary ones.

  • I3CrossSections: provies the tools for sampling DIS and GR cross sections.

  • Earthmodel Services: provides the PREM for column depth calculations.

Manual Compilation with CMake (Alternative)

If you prefer to build manually or need more control over the build process, you can use CMake directly.

First, clone the repository:

git clone git@github.com:IceCubeOpenSource/LeptonInjector.git
cd LeptonInjector

Create build and install directories:

mkdir build install
cd build

Configure with CMake:

cmake -DCMAKE_INSTALL_PREFIX=../install ..

Build and install:

make -j4 && make install

Set up environment variables (add to your .bashrc or .bash_profile):

# Allow Python to find the installed library
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/install/path/

# Allow the EarthModel to find Earth parameter files
export EARTH_PARAMS=/path/to/LeptonInjector/resources/earthparams/

Note: When using pip install, these environment variables are not needed as the package is installed into your Python environment and resources are bundled with the package.

Structure

The code base is divided into several files.

  • Constants: a header defining various constants.
  • Controller: implements a class for managing the simulation
  • DataWriter: writes event properties and MCTrees to an HDF5 file
  • EventProps: implements a few structures used to write events in the hdf5 file.
  • h5write: may be renamed soon. This will be used to write the configurations onto a file
  • LeptonInjector (the file): defines the Injector objects described above in addition to several configuration objects and event generators
  • Particle: simple implementation of particles. Includes a big enum.
  • Random: object for random number sampling.

Cross Sections

For generating events you will need fits files of splines specifying the cross sections (total and differential cross sections). These should be made with photospline.

Making Contributions

If you would like to make contributions to this project, please create a branch off of the master branch and name it something following the template: $YourLastName/$YourSubProject. Work on this branch until you have made the changes you wished to see and your branch is stable. Then, pull from master, and create a pull request to merge your branch back into master.

Detailed Author Contributions and Citation

The LeptonInjector and LeptonWeighter modules were motivated by the high-energy light sterile neutrino search performed by B. Jones and C. Argüelles. C. Weaver wrote the first implementation of LeptonInjector using the IceCube internal software framework, icetray, and wrote the specifications for LeptonWeighter. In doing so, he also significantly enhanced the functionality of IceCube's Earth-model service. These weighting specifications were turned into code by C. Argüelles in LeptonWeighter. B. Jones performed the first detailed Monte Carlo comparisons that showed that this code had similar performance to the standard IceCube neutrino generator at the time for throughgoing muon neutrinos.

It was realized that these codes could have use beyond IceCube and could benefit the broader neutrino community. The codes were copied from IceCube internal subversion repositories to this GitHub repository; unfortunately, the code commit history was not preserved in this process. Thus the current commits do not represent the contributions from the original authors, particularly from the initial work by C. Weaver and C. Argüelles.

The transition to this public version of the code has been spearheaded by A. Schneider and B. Smithers, with significant input and contributions from C. Weaver and C. Argüelles. B. Smithers isolated the components of the code needed to make the code public, edited the examples, and improved the interface of the code. A. Schneider contributed to improving the weighting algorithm, particularly to making it work for volume mode cascades, as well as in writing the general weighting formalism that enables joint weighting of volume and range mode.

This project also received contributions and suggestions from internal IceCube reviewers and the collaboration as a whole. Please cite this work as:

LeptonInjector and LeptonWeighter: A neutrino event generator and weighter for neutrino observatories IceCube Collaboration https://arxiv.org/abs/2012.10449

CRediT

Austin Schneider: Software, Validation, Writing - Original Draft, Writing - Review & Editing; Benjamin Jones: Conceptualization, Validation; Benjamin Smithers: Software, Validation, Writing - Original Draft, Visualization, Writing - Review & Editing; Carlos Argüelles: Conceptualization, Software, Writing - Original Draft, Writing - Review & Editing, Supervision; Chris Weaver: Methodology, Software, Writing - Review & Editing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leptoninjector-1.1.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

leptoninjector-1.1.0-cp312-cp312-macosx_14_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

leptoninjector-1.1.0-cp311-cp311-macosx_14_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

leptoninjector-1.1.0-cp310-cp310-macosx_14_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ ARM64

File details

Details for the file leptoninjector-1.1.0.tar.gz.

File metadata

  • Download URL: leptoninjector-1.1.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for leptoninjector-1.1.0.tar.gz
Algorithm Hash digest
SHA256 69365eaee51ddaf4e05399c1ea7b00416d8fad05676e155138ecddbc9a46a7c7
MD5 905847f2b1be094dbcf71468e7a38904
BLAKE2b-256 1f781e40f306e2622738989ac30bf3703eb1c8fbb008a7c24462f23e3087ccd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0.tar.gz:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5e394dca6a1ba13276afe893bac66fe0d957d2c897922d28c86a2b88dcd849fb
MD5 970b21bd8b91c8050b24d69ac7a88c3e
BLAKE2b-256 4577682bffe5cac788d1fa7a7396cb1c9bd79b5848180b250ff223a0a0b94a8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9152de961fd0c17f3bc0957e4d4b274400fe14aa8ccea7615dd907baf2f1e5ec
MD5 497d27a48d7a6b6fc8ec83faedb62f23
BLAKE2b-256 f7dbbd04389201b98c16c7792229d12dcb79c820c0b1ba14b830c7e8a7a363ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e8b5b18cb4534e9e355956d8b88b462919e3db20c033caf20c09b861b6ea0741
MD5 46355381c4e33d39f53e0982fbd163d6
BLAKE2b-256 b5bf5d177e771609477be2904412740fb317f8dd49d69a5f20ecc9c9ee444c0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad29091dbc8863f0058a63b287e3b145db074036345610b753ef5cd19cc06227
MD5 df3a7caaa2e891bd36637a4dcce9637b
BLAKE2b-256 e8e1b45ac08bfa073d636838c45bc7cdc1523771f3cac5fa2091700aba17ec53

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 21cd6986e8750d22b0c5a5b538210fe60536f81022beaff834d5e27ede85b412
MD5 481ca55ed0e9b77254384ada4c83d5ff
BLAKE2b-256 f7ef83353d8cc118bc6c50364d03ecb30bee6b6649b66abf652f125d9be97e1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 689ec0b08fd7de638ae396f5b71c53501411623ff5001dc97cc72f6f2c333d0f
MD5 bef73d6c48c146dc334dc1d7884a6a33
BLAKE2b-256 ed42cce33bc7d29c64ea307dd02ff1af444fb62494c07e642d71d20b017e2a2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9fa6c6b9b59a00b5202af139f63adc79a46af1a36e488343993168e9226ac672
MD5 5cd6942e37072782f7b6f85fa107c34e
BLAKE2b-256 933171d008b8ed07e51598631eb8deb5e9a72cd773491414197c04ec49b4535a

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bc9970d58f0002a5315ac4ba14543e046a7bf7501587e1d132e8b778089a2afe
MD5 3fc93fc52bcbb5988854ce7b66b9d88c
BLAKE2b-256 f7fabadf5c51658e6f9c9d4262513694fbb72b9ca073748bffb1d824680a001a

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5ff36312df6e3e83613a8a8d883268adc47daa90fb3fd2b409cafbb66b33b2a0
MD5 31903b09ae3c7ab08f5a98c9165bd9b0
BLAKE2b-256 c7a4ab482a717b0b51c6564b3bf257981672c40f1ac73db1b8a91b4fb0ca038f

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf0c87a936943e5968bff43320d0eced0d3affa5fe745bb23d8a9df389995ed3
MD5 39d641749191370bef374180be2fe6d5
BLAKE2b-256 4853e4846112a59914475c4098e4f8e170b55ffe3ec3bba649d7f380b03333e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b14a9bed083f59a6464c285e6b3b9cf77dbde399a92f08d57b66383408467952
MD5 7ab4f5a9ea4d100d4c296f329cbd8f05
BLAKE2b-256 6a5a4ada79d53b31b2fe82261702abf4403a27f61245ffc34bb1583738c2bb11

See more details on using hashes here.

Provenance

The following attestation bundles were made for leptoninjector-1.1.0-cp39-cp39-manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on icecube/LeptonInjector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page