Metadata-Version: 2.2
Name: siren
Version: 0.1.0
Summary: Sampling and Injection for Rare EveNts: A neutrino and rare-process injection toolkit
Keywords: physics,hep,neutrino,bsm,simulation,injection,weighting
Author-Email: Austin Schneider <aschn@mit.edu>, Nicholas Kamp <nkamp@fas.harvard.edu>
Maintainer-Email: Austin Schneider <aschn@mit.edu>, Nicholas Kamp <nkamp@fas.harvard.edu>
License:                    GNU LESSER GENERAL PUBLIC LICENSE
                                Version 3, 29 June 2007
         
          Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
          Everyone is permitted to copy and distribute verbatim copies
          of this license document, but changing it is not allowed.
         
         
           This version of the GNU Lesser General Public License incorporates
         the terms and conditions of version 3 of the GNU General Public
         License, supplemented by the additional permissions listed below.
         
           0. Additional Definitions.
         
           As used herein, "this License" refers to version 3 of the GNU Lesser
         General Public License, and the "GNU GPL" refers to version 3 of the GNU
         General Public License.
         
           "The Library" refers to a covered work governed by this License,
         other than an Application or a Combined Work as defined below.
         
           An "Application" is any work that makes use of an interface provided
         by the Library, but which is not otherwise based on the Library.
         Defining a subclass of a class defined by the Library is deemed a mode
         of using an interface provided by the Library.
         
           A "Combined Work" is a work produced by combining or linking an
         Application with the Library.  The particular version of the Library
         with which the Combined Work was made is also called the "Linked
         Version".
         
           The "Minimal Corresponding Source" for a Combined Work means the
         Corresponding Source for the Combined Work, excluding any source code
         for portions of the Combined Work that, considered in isolation, are
         based on the Application, and not on the Linked Version.
         
           The "Corresponding Application Code" for a Combined Work means the
         object code and/or source code for the Application, including any data
         and utility programs needed for reproducing the Combined Work from the
         Application, but excluding the System Libraries of the Combined Work.
         
           1. Exception to Section 3 of the GNU GPL.
         
           You may convey a covered work under sections 3 and 4 of this License
         without being bound by section 3 of the GNU GPL.
         
           2. Conveying Modified Versions.
         
           If you modify a copy of the Library, and, in your modifications, a
         facility refers to a function or data to be supplied by an Application
         that uses the facility (other than as an argument passed when the
         facility is invoked), then you may convey a copy of the modified
         version:
         
            a) under this License, provided that you make a good faith effort to
            ensure that, in the event an Application does not supply the
            function or data, the facility still operates, and performs
            whatever part of its purpose remains meaningful, or
         
            b) under the GNU GPL, with none of the additional permissions of
            this License applicable to that copy.
         
           3. Object Code Incorporating Material from Library Header Files.
         
           The object code form of an Application may incorporate material from
         a header file that is part of the Library.  You may convey such object
         code under terms of your choice, provided that, if the incorporated
         material is not limited to numerical parameters, data structure
         layouts and accessors, or small macros, inline functions and templates
         (ten or fewer lines in length), you do both of the following:
         
            a) Give prominent notice with each copy of the object code that the
            Library is used in it and that the Library and its use are
            covered by this License.
         
            b) Accompany the object code with a copy of the GNU GPL and this license
            document.
         
           4. Combined Works.
         
           You may convey a Combined Work under terms of your choice that,
         taken together, effectively do not restrict modification of the
         portions of the Library contained in the Combined Work and reverse
         engineering for debugging such modifications, if you also do each of
         the following:
         
            a) Give prominent notice with each copy of the Combined Work that
            the Library is used in it and that the Library and its use are
            covered by this License.
         
            b) Accompany the Combined Work with a copy of the GNU GPL and this license
            document.
         
            c) For a Combined Work that displays copyright notices during
            execution, include the copyright notice for the Library among
            these notices, as well as a reference directing the user to the
            copies of the GNU GPL and this license document.
         
            d) Do one of the following:
         
                0) Convey the Minimal Corresponding Source under the terms of this
                License, and the Corresponding Application Code in a form
                suitable for, and under terms that permit, the user to
                recombine or relink the Application with a modified version of
                the Linked Version to produce a modified Combined Work, in the
                manner specified by section 6 of the GNU GPL for conveying
                Corresponding Source.
         
                1) Use a suitable shared library mechanism for linking with the
                Library.  A suitable mechanism is one that (a) uses at run time
                a copy of the Library already present on the user's computer
                system, and (b) will operate properly with a modified version
                of the Library that is interface-compatible with the Linked
                Version.
         
            e) Provide Installation Information, but only if you would otherwise
            be required to provide such information under section 6 of the
            GNU GPL, and only to the extent that such information is
            necessary to install and execute a modified version of the
            Combined Work produced by recombining or relinking the
            Application with a modified version of the Linked Version. (If
            you use option 4d0, the Installation Information must accompany
            the Minimal Corresponding Source and Corresponding Application
            Code. If you use option 4d1, you must provide the Installation
            Information in the manner specified by section 6 of the GNU GPL
            for conveying Corresponding Source.)
         
           5. Combined Libraries.
         
           You may place library facilities that are a work based on the
         Library side by side in a single library together with other library
         facilities that are not Applications and are not covered by this
         License, and convey such a combined library under terms of your
         choice, if you do both of the following:
         
            a) Accompany the combined library with a copy of the same work based
            on the Library, uncombined with any other library facilities,
            conveyed under the terms of this License.
         
            b) Give prominent notice with the combined library that part of it
            is a work based on the Library, and explaining where to find the
            accompanying uncombined form of the same work.
         
           6. Revised Versions of the GNU Lesser General Public License.
         
           The Free Software Foundation may publish revised and/or new versions
         of the GNU Lesser General Public License from time to time. Such new
         versions will be similar in spirit to the present version, but may
         differ in detail to address new problems or concerns.
         
           Each version is given a distinguishing version number. If the
         Library as you received it specifies that a certain numbered version
         of the GNU Lesser General Public License "or any later version"
         applies to it, you have the option of following the terms and
         conditions either of that published version or of any later version
         published by the Free Software Foundation. If the Library as you
         received it does not specify a version number of the GNU Lesser
         General Public License, you may choose any version of the GNU Lesser
         General Public License ever published by the Free Software Foundation.
         
           If the Library as you received it specifies that a proxy can decide
         whether future versions of the GNU Lesser General Public License shall
         apply, that proxy's public statement of acceptance of any version is
         permanent authorization for you to choose that version for the
         Library.
         
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Classifier: Topic :: Scientific/Engineering :: Physics
Project-URL: Homepage, https://github.com/Harvard-Neutrino/SIREN
Project-URL: Documentation, https://readthedocs.org
Project-URL: Repository, https://github.com/Harvard-Neutrino/SIREN.git
Project-URL: Issues, https://github.com/Harvard-Neutrino/SIREN/issues
Requires-Python: >=3.8
Requires-Dist: numpy<2.0.0
Requires-Dist: scipy
Requires-Dist: awkward
Requires-Dist: pyarrow
Requires-Dist: h5py
Provides-Extra: darknews
Requires-Dist: DarkNews>=0.4.2; extra == "darknews"
Description-Content-Type: text/markdown

[![Build](https://github.com/Harvard-Neutrino/SIREN/actions/workflows/build_wheels.yml/badge.svg)](https://github.com/Harvard-Neutrino/SIREN/actions/workflows/build_wheels.yml)

# SIREN

SIREN (**S**ampling and **I**njection for **R**are **E**ve**N**ts) is a framework for injecting and weighting interaction final states of complex topology, with specific concern for the detector geometry. SIREN is designed to support a wide variety of neutrino experimental setups, including atmospheric neutrinos, accelerator beam decay-in-flight neutrinos, and neutrinos from decay-at-rest sources. SIREN grew out of [LeptonInjector](https://github.com/icecube/LeptonInjector), a neutrino injection code developed within the IceCube collaboration to study atmospheric and astrophysical neutrino interactions in the IceCube detector.

SIREN provides a generic interface for user-defined BSM processes (and includes several pre-defined processes). It also supports generation of any number of secondary processes, e.g. the decay of a BSM particle after it has been created by an initial process.

## Quick start

```bash
pip install siren
```

See [Installation](#installation) for other options, including building from source or as a C++ library.

The following example injects 1e4 muon-neutrino DIS events in IceCube and computes their physical weights:

```python
import siren

# Load detector geometry and interaction cross sections
detector_model = siren.utilities.load_detector("IceCube")
primary_type = siren.dataclasses.Particle.ParticleType.NuMu
primary_processes, _ = siren.utilities.load_processes(
    "CSMSDISSplines",
    primary_types=[primary_type],
    target_types=[siren.dataclasses.Particle.ParticleType.Nucleon],
    isoscalar=True,
    process_types=["CC"],
)

# Configure the injector: energy spectrum, direction, and position
injector = siren.injection.Injector()
injector.number_of_events = int(1e4)
injector.detector_model = detector_model
injector.primary_type = primary_type
injector.primary_interactions = primary_processes[primary_type]
injector.primary_injection_distributions = [
    siren.distributions.PrimaryMass(0),
    siren.distributions.PowerLaw(2, 1e3, 1e6),
    siren.distributions.IsotropicDirection(),
    siren.distributions.ColumnDepthPositionDistribution(
        600, 600.0, siren.distributions.LeptonDepthFunction()
    ),
]

# Generate events
from siren._util import GenerateEvents, SaveEvents
events, gen_times = GenerateEvents(injector)

# Weight events using physical distributions
weighter = siren.injection.Weighter()
weighter.injectors = [injector]
weighter.detector_model = detector_model
weighter.primary_type = primary_type
weighter.primary_interactions = primary_processes[primary_type]
weighter.primary_physical_distributions = [
    siren.distributions.PowerLaw(2, 1e3, 1e6),
    siren.distributions.IsotropicDirection(),
]

weights = [weighter(event) for event in events]

# Save results to HDF5 and Parquet
SaveEvents(events, weighter, gen_times, output_filename="my_output")
```

More examples — including BSM dipole-portal injection and MARLEY low-energy interactions — are in [`resources/examples/`](resources/examples/).

## How it works

A SIREN workflow has two phases: **injection** and **weighting**.

During **injection**, SIREN samples interaction vertices inside a detector geometry according to user-specified distributions (energy spectrum, direction, position). Each call to `injector.generate_event()` produces an interaction tree — a primary interaction and any secondary processes (e.g. the decay of a BSM particle produced in the primary interaction).

During **weighting**, SIREN computes a physical weight for each injected event. The `Weighter` takes the injection configuration and a set of *physical* distributions (the true flux and cross sections) and returns a weight that corrects for the difference between the injection and physical distributions. This importance-sampling approach allows a single injection run to be reweighted against different physical models without regenerating events.

## Supported detectors

SIREN includes detector geometry definitions for the following experiments:

| Experiment | Model name |
|------------|------------|
| [ATLAS](https://atlas.cern/) | `ATLAS` |
| [CCM](https://ccm.mit.edu/) | `CCM` |
| [DUNE Far Detector](https://www.dunescience.org/) | `DUNEFD` |
| [Hyper-Kamiokande](https://www.hyperk.org/) | `HyperK` |
| [IceCube](https://icecube.wisc.edu/) | `IceCube` |
| [KM3NeT/ORCA](https://www.km3net.org/) | `KM3NeTORCA` |
| [MINERvA](https://minerva.fnal.gov/) | `MINERvA` |
| [MiniBooNE](https://www-boone.fnal.gov/) | `MiniBooNE` |
| [ND280](https://t2k-experiment.org/) | `ND280` |
| [ND280 Upgrade](https://t2k-experiment.org/) | `ND280UPGRD` |
| [SINE](https://journals.aps.org/prd/abstract/10.1103/z4f4-wdc3) | `SINE` |
| [UNDINE](https://journals.aps.org/prd/abstract/10.1103/z4f4-wdc3) | `UNDINE` |

Each detector is defined by a materials file and a density profile. To load one:

```python
detector_model = siren.utilities.load_detector("IceCube")
```

Contributions of new detector geometries are welcome.

## Supported process models

| Model | Description |
|-------|-------------|
| `CSMSDISSplines` | Deep inelastic scattering (CC and NC) on nucleons, using photospline cross-section tables |
| `MarleyCrossSection` | Low-energy neutrino interactions via [MARLEY](https://www.marleygen.org/) |
| `DarkNewsTables` | BSM processes (dark photons, dipole portal, HNLs) via [DarkNews](https://github.com/mhostert/DarkNews-generator) — see [example2](resources/examples/example2/) |
| `HNLDISSplines` | Heavy neutral lepton (HNL) production via neutrino neutral current deep inelastic scattering on nucleons, using photospline cross-section tables |
| `DipoleHNLDISSplines` | Heavy neutral lepton (HNL) production via neutrino dipole-portal (i.e., via a transition magnetic moment) deep inelastic scattering on nucleons, using photospline cross-section tables |

## Supported flux models

| Model | Description |
|-------|-------------|
| `BNB` | Booster Neutrino Beam (FHC and RHC modes) |
| `NUMI` | NuMI beamline (low-energy and medium-energy) |
| `T2K_NEAR` | T2K near detector flux |
| `HE_SN` | Supernova neutrino flux |
| `Atmospheric` |  A suite of atmospheric neutrino flux models |

To load a flux model:

```python
flux = siren.utilities.load_flux("BNB", tag="FHC_numu")
```

## Installation

### Python (pip)

```bash
pip install siren
```

Requires Python >= 3.8. Dependencies (`numpy`, `scipy`, `awkward`, `pyarrow`, `h5py`) are installed automatically.

For optional BSM support via DarkNews:

```bash
pip install siren DarkNews>=0.4.2
```

### Python (from source)

```bash
git clone https://github.com/Harvard-Neutrino/SIREN.git
cd SIREN
pip install . --config-settings='build-dir=build'
```

### C++ library

SIREN can also be built and installed as a standalone C++ shared library using CMake. This is useful when integrating SIREN into a larger C++ project.

#### Prerequisites

* A C++ compiler with C++17 support
* CMake >= 3.20
* [CFITSIO](https://heasarc.gsfc.nasa.gov/fitsio/)
* [SuiteSparse](http://faculty.cse.tamu.edu/davis/suitesparse.html)

CFITSIO and SuiteSparse are required by photospline for reading cross-section spline tables.

#### Workspace layout

We recommend keeping source, build, and install directories separate. A typical workspace looks like:

```
workspace/
├── env.sh              # environment setup script
├── local/              # install prefix
│   ├── bin/
│   ├── include/
│   └── lib/
└── sources/
    ├── SIREN/
    │   └── build/      # out-of-source build directory
    └── (other projects that depend on SIREN)
```

#### Environment setup

Create an `env.sh` script that configures your compiler and paths. This script should be sourced before building or running anything in the workspace.

```bash
#!/bin/bash

export WORKSPACE=/path/to/workspace
export PREFIX=$WORKSPACE/local

export CC=gcc
export CXX=g++

export PATH=$PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$PREFIX/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$PREFIX/include:$CPLUS_INCLUDE_PATH
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
PY_SITE_DIR="$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')"
export PYTHONPATH="$PY_SITE_DIR${PYTHONPATH:+:$PYTHONPATH}"
```

On macOS, use `DYLD_FALLBACK_LIBRARY_PATH` instead of `LD_LIBRARY_PATH`.

#### Build and install

```bash
source env.sh

git clone https://github.com/Harvard-Neutrino/SIREN.git $WORKSPACE/sources/SIREN
cd $WORKSPACE/sources/SIREN
git submodule update --init

mkdir -p build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX
cmake --build . --parallel && cmake --install .
```

After the initial build, only the last line (`cmake --build . --parallel && cmake --install .`) needs to be rerun when source files change. Rerun the first `cmake` step if `CMakeLists.txt` files change or new source files are added.

#### CMake options

| Option | Default | Description |
|--------|---------|-------------|
| `CMAKE_INSTALL_PREFIX` | — | Install destination for libraries, headers, and binaries |
| `SIREN_PYTHON_PACKAGE` | `ON` | Build and install the Python package |
| `SIREN_WITH_MARLEY` | `ON` | Enable MARLEY support (used if found) |
| `SIREN_REQUIRE_MARLEY` | `OFF` | Fail the build if MARLEY is not found |

## Dataset download

SIREN uses external datasets that need to be downloaded separately, including neutrino flux models and cross-section tables. To do this, after installing SIREN , run the following commands:

```bash
siren-download --processes
siren-download --flux
```

These commands will download the necessary datasets to the `resources/processes` and `resources/fluxes` directories in the SIREN installation.

## Project structure

```
SIREN/
├── projects/              # C++ source modules
│   ├── utilities/         # Interpolation, random numbers, string utilities
│   ├── serialization/     # Serialization support
│   ├── math/              # Vector3D, Matrix3D, Quaternion, interpolation
│   ├── dataclasses/       # Particle, InteractionRecord, InteractionTree
│   ├── geometry/          # Geometric primitives and operations
│   ├── detector/          # Detector geometry and density profiles
│   ├── interactions/      # Cross section and decay implementations
│   ├── distributions/     # Probability distributions for sampling
│   └── injection/         # Injector and Weighter
├── python/                # Python API (Injector, Weighter, utilities)
├── vendor/                # Vendored dependencies (git submodules)
│   ├── cereal             # Serialization
│   ├── delabella          # Delaunay triangulation
│   ├── googletest         # Unit testing
│   ├── pybind11           # Python bindings
│   ├── rk                 # Relativistic kinematics
│   ├── photospline        # B-spline cross-section tables
│   └── NamedType          # Type-safe wrappers
├── resources/
│   ├── detectors/         # Detector geometry definitions
│   ├── fluxes/            # Neutrino flux models
│   ├── processes/         # Cross-section and decay data
│   └── examples/          # Example scripts and notebooks
└── cmake/Packages/        # CMake find-modules for dependencies
```

## Contributing

Create a branch off of `main` named `$GitHubUsername/$YourSubProject`. When your changes are stable, pull from main and open a pull request.

## Citing SIREN

If you use SIREN in your research, please cite the repository:

```
https://github.com/Harvard-Neutrino/SIREN
```

## License

SIREN is licensed under the [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.html).
