obdeect-shower 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- obdeect_shower-0.11.0/CMakeLists.txt +96 -0
- obdeect_shower-0.11.0/PKG-INFO +25 -0
- obdeect_shower-0.11.0/README.md +5 -0
- obdeect_shower-0.11.0/cpp/bindings/core.cpp +137 -0
- obdeect_shower-0.11.0/cpp/include/obdeect/shower/particles.hpp +618 -0
- obdeect_shower-0.11.0/cpp/include/obdeect/shower/run.hpp +126 -0
- obdeect_shower-0.11.0/cpp/include/obdeect/shower/sampling.hpp +575 -0
- obdeect_shower-0.11.0/cpp/tests/test_particles.cpp +237 -0
- obdeect_shower-0.11.0/cpp/tests/test_run.cpp +44 -0
- obdeect_shower-0.11.0/cpp/tests/test_sampling.cpp +238 -0
- obdeect_shower-0.11.0/models/de-naurois-rolland-v1.json +16 -0
- obdeect_shower-0.11.0/propagation-profile/obdeect/propagation/profile.hpp +360 -0
- obdeect_shower-0.11.0/pyproject.toml +54 -0
- obdeect_shower-0.11.0/python/obdeect/shower/__init__.py +1 -0
- obdeect_shower-0.11.0/python/obdeect/shower/cli.py +45 -0
- obdeect_shower-0.11.0/python/obdeect/shower/config.py +202 -0
- obdeect_shower-0.11.0/python/tests/test_cli.py +111 -0
- obdeect_shower-0.11.0/python/tests/test_config.py +16 -0
- obdeect_shower-0.11.0/shared-cmake/ObdeectCommon.cmake +74 -0
- obdeect_shower-0.11.0/shared-cmake/ObdeectTests.cmake +45 -0
- obdeect_shower-0.11.0/stream-src/CMakeLists.txt +203 -0
- obdeect_shower-0.11.0/stream-src/cmake/obdeect_stream-config.cmake.in +3 -0
- obdeect_shower-0.11.0/stream-src/cmake/version.hpp.in +11 -0
- obdeect_shower-0.11.0/stream-src/cpp/bench/bench_stream.cpp +119 -0
- obdeect_shower-0.11.0/stream-src/cpp/bench/gen_corsika.cpp +138 -0
- obdeect_shower-0.11.0/stream-src/cpp/bindings/core.cpp +476 -0
- obdeect_shower-0.11.0/stream-src/cpp/capi/obdeect_stream_c.cpp +713 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/atmprof.hpp +76 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/cli.hpp +116 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/constants.hpp +18 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/corsika.hpp +924 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/eventio.hpp +923 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/format.hpp +62 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/grisu.hpp +591 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/obdeect_stream.h +219 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/parse.hpp +61 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/photons.hpp +288 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/random.hpp +66 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/simtel.hpp +1430 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/stages.hpp +43 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/stdin_buffer.hpp +62 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/stream.hpp +884 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/telpos.hpp +11 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/vec3.hpp +64 -0
- obdeect_shower-0.11.0/stream-src/cpp/include/obdeect/stream/wavelength.hpp +23 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/check.hpp +69 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/consumer/CMakeLists.txt +13 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/consumer/main.cpp +31 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/consumer/main_c.c +6 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/bad_magic.pst +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/expected.json +130 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/make_conformance.py +137 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/too_many_rows.pst +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/truncated_chunk.pst +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/unknown_major.pst +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/conformance/valid.pst +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/make_photons3d_fixture.c +157 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/photons3d.iact +0 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/data/photons3d_provenance.txt +29 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_capi.c +359 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_capi_cpp.cpp +230 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_cli.cpp +81 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_corsika.cpp +1126 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_eventio.cpp +555 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_format.cpp +236 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_grisu.cpp +411 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_parse.cpp +43 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_simtel.cpp +1919 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_stages.cpp +20 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_stream.cpp +1058 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_version.cpp +11 -0
- obdeect_shower-0.11.0/stream-src/cpp/tests/test_wavelength.cpp +69 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/corsika2ps.cpp +50 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/ps2grisu.cpp +74 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/ps2simtel.cpp +133 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/ps_cat.cpp +144 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/ps_tee.cpp +113 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/tool_io.hpp +101 -0
- obdeect_shower-0.11.0/stream-src/cpp/tools/tool_version.hpp +16 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
project(obdeect_shower LANGUAGES CXX)
|
|
3
|
+
|
|
4
|
+
if(NOT DEFINED OBDEECT_SHARED_CMAKE_DIR)
|
|
5
|
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/ObdeectCommon.cmake)
|
|
6
|
+
set(OBDEECT_SHARED_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
|
|
7
|
+
else()
|
|
8
|
+
set(OBDEECT_SHARED_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shared-cmake)
|
|
9
|
+
endif()
|
|
10
|
+
endif()
|
|
11
|
+
include("${OBDEECT_SHARED_CMAKE_DIR}/ObdeectCommon.cmake")
|
|
12
|
+
|
|
13
|
+
option(OBDEECT_SHOWER_BUILD_TESTING "Build the C++ tests" ON)
|
|
14
|
+
if(DEFINED SKBUILD_PLATLIB_DIR)
|
|
15
|
+
set(OBDEECT_SHOWER_BUILD_PYTHON_API_DEFAULT ON)
|
|
16
|
+
else()
|
|
17
|
+
set(OBDEECT_SHOWER_BUILD_PYTHON_API_DEFAULT OFF)
|
|
18
|
+
endif()
|
|
19
|
+
option(OBDEECT_SHOWER_BUILD_PYTHON_API "Build the Python extension" ${OBDEECT_SHOWER_BUILD_PYTHON_API_DEFAULT})
|
|
20
|
+
|
|
21
|
+
# The stream component: the target of the combined build, else the stream sources next to
|
|
22
|
+
# this component (builds from the repository), else the copy bundled into the sdist
|
|
23
|
+
# (stream-src, staged at release time), else an installed package.
|
|
24
|
+
if(NOT TARGET obdeect::stream)
|
|
25
|
+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../stream/CMakeLists.txt)
|
|
26
|
+
set(OBDEECT_STREAM_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../stream)
|
|
27
|
+
elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/stream-src/CMakeLists.txt)
|
|
28
|
+
set(OBDEECT_STREAM_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stream-src)
|
|
29
|
+
endif()
|
|
30
|
+
if(OBDEECT_STREAM_SOURCE_DIR)
|
|
31
|
+
set(OBDEECT_STREAM_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
32
|
+
set(OBDEECT_STREAM_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
|
|
33
|
+
set(OBDEECT_STREAM_BUILD_CAPI OFF CACHE BOOL "" FORCE)
|
|
34
|
+
set(OBDEECT_STREAM_BUILD_PYTHON_API OFF CACHE BOOL "" FORCE)
|
|
35
|
+
set(OBDEECT_STREAM_INSTALL OFF CACHE BOOL "" FORCE)
|
|
36
|
+
add_subdirectory(${OBDEECT_STREAM_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/stream)
|
|
37
|
+
message(STATUS "obdeect shower: using the stream sources in ${OBDEECT_STREAM_SOURCE_DIR}")
|
|
38
|
+
else()
|
|
39
|
+
find_package(Python 3.14 COMPONENTS Interpreter)
|
|
40
|
+
if(Python_Interpreter_FOUND AND NOT obdeect_stream_DIR)
|
|
41
|
+
execute_process(COMMAND "${Python_EXECUTABLE}" -m obdeect.stream --cmake-dir
|
|
42
|
+
OUTPUT_VARIABLE obdeect_stream_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
|
43
|
+
endif()
|
|
44
|
+
find_package(obdeect_stream CONFIG REQUIRED)
|
|
45
|
+
message(STATUS "obdeect shower: using the installed stream package ${obdeect_stream_VERSION} (${obdeect_stream_DIR})")
|
|
46
|
+
endif()
|
|
47
|
+
endif()
|
|
48
|
+
|
|
49
|
+
# Header-only, standard-library-only core. Photon chunks use the obdeect stream headers.
|
|
50
|
+
add_library(obdeect_shower_core INTERFACE)
|
|
51
|
+
target_include_directories(obdeect_shower_core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/cpp/include)
|
|
52
|
+
obdeect_set_core_options(obdeect_shower_core)
|
|
53
|
+
target_link_libraries(obdeect_shower_core INTERFACE obdeect::stream)
|
|
54
|
+
|
|
55
|
+
# Reuse the propagation profile interpolation without linking the propagation stage.
|
|
56
|
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../propagation/cpp/include")
|
|
57
|
+
set(OBDEECT_SHOWER_PROFILE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../propagation/cpp/include")
|
|
58
|
+
else()
|
|
59
|
+
set(OBDEECT_SHOWER_PROFILE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/propagation-profile")
|
|
60
|
+
endif()
|
|
61
|
+
target_include_directories(obdeect_shower_core INTERFACE "${OBDEECT_SHOWER_PROFILE_INCLUDE}")
|
|
62
|
+
|
|
63
|
+
function(obdeect_shower_enable_warnings target)
|
|
64
|
+
obdeect_enable_warnings(${target})
|
|
65
|
+
# GCC 13 reports false maybe-uninitialized warnings inside std::variant at -O3.
|
|
66
|
+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
67
|
+
target_compile_options(${target} PRIVATE -Wno-error=maybe-uninitialized)
|
|
68
|
+
endif()
|
|
69
|
+
endfunction()
|
|
70
|
+
|
|
71
|
+
if(OBDEECT_SHOWER_BUILD_PYTHON_API)
|
|
72
|
+
find_package(Python 3.14 COMPONENTS Interpreter Development.Module REQUIRED)
|
|
73
|
+
execute_process(COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
74
|
+
OUTPUT_VARIABLE nanobind_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
75
|
+
COMMAND_ERROR_IS_FATAL ANY)
|
|
76
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
77
|
+
nanobind_add_module(_shower NB_STATIC cpp/bindings/core.cpp)
|
|
78
|
+
target_link_libraries(_shower PRIVATE obdeect_shower_core)
|
|
79
|
+
obdeect_shower_enable_warnings(_shower)
|
|
80
|
+
install(TARGETS _shower LIBRARY DESTINATION obdeect/shower)
|
|
81
|
+
install(DIRECTORY models/ DESTINATION obdeect/shower/models)
|
|
82
|
+
endif()
|
|
83
|
+
|
|
84
|
+
if(OBDEECT_SHOWER_BUILD_TESTING)
|
|
85
|
+
enable_testing()
|
|
86
|
+
foreach(test_name particles sampling run)
|
|
87
|
+
add_executable(obdeect_shower_test_${test_name} cpp/tests/test_${test_name}.cpp)
|
|
88
|
+
target_link_libraries(obdeect_shower_test_${test_name} PRIVATE obdeect_shower_core)
|
|
89
|
+
# check.hpp lives with the stream tests; tests are built from the repository only, never from an sdist.
|
|
90
|
+
target_include_directories(obdeect_shower_test_${test_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../stream/cpp/tests)
|
|
91
|
+
obdeect_shower_enable_warnings(obdeect_shower_test_${test_name})
|
|
92
|
+
obdeect_add_test(shower_${test_name} shower SOURCE test_${test_name}.cpp
|
|
93
|
+
COMMAND obdeect_shower_test_${test_name})
|
|
94
|
+
endforeach()
|
|
95
|
+
obdeect_check_test_sources(${CMAKE_CURRENT_SOURCE_DIR}/cpp/tests)
|
|
96
|
+
endif()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obdeect-shower
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Summary: Fast simulation of Cherenkov light from gamma-ray air showers
|
|
5
|
+
Author: obdeect contributors
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Requires-Dist: obdeect-stream==0.11.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: nanobind>=3.1; extra == "dev"
|
|
16
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: ruff; extra == "dev"
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# obdeect-shower
|
|
22
|
+
|
|
23
|
+
Fast simulation of Cherenkov photon streams from gamma-ray air showers.
|
|
24
|
+
For a given first-interaction depth, the model describes the average shower;
|
|
25
|
+
it does not simulate the remaining shower-to-shower fluctuations.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#include <nanobind/nanobind.h>
|
|
2
|
+
#include <nanobind/stl/array.h>
|
|
3
|
+
#include <nanobind/stl/string.h>
|
|
4
|
+
#include <nanobind/stl/vector.h>
|
|
5
|
+
|
|
6
|
+
#include "obdeect/shower/run.hpp"
|
|
7
|
+
#include "obdeect/stream/constants.hpp"
|
|
8
|
+
#include "obdeect/stream/random.hpp"
|
|
9
|
+
#include "obdeect/stream/stages.hpp"
|
|
10
|
+
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <array>
|
|
13
|
+
#include <cmath>
|
|
14
|
+
#include <fstream>
|
|
15
|
+
#include <iostream>
|
|
16
|
+
#include <optional>
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
namespace nb = nanobind;
|
|
21
|
+
|
|
22
|
+
namespace {
|
|
23
|
+
|
|
24
|
+
using namespace obdeect::shower;
|
|
25
|
+
using obdeect::propagation::AtmosphereProfile;
|
|
26
|
+
|
|
27
|
+
void write_run_py(const nb::dict &config, const std::string &path) {
|
|
28
|
+
using obdeect::stream::pi;
|
|
29
|
+
const auto wl = nb::cast<std::array<double, 2>>(config["wavelength_nm"]);
|
|
30
|
+
const auto seed = nb::cast<std::uint64_t>(config["seed"]);
|
|
31
|
+
const auto observation_level = nb::cast<double>(config["observation_level_m"]);
|
|
32
|
+
const auto depths = nb::cast<std::vector<double>>(config["first_interaction_values"]);
|
|
33
|
+
const auto sampling = nb::cast<nb::dict>(config["sampling"]);
|
|
34
|
+
const auto model = nb::cast<nb::dict>(config["model"]);
|
|
35
|
+
const auto thresholds = nb::cast<std::vector<double>>(model["energy_thresholds_mev"]);
|
|
36
|
+
std::vector<LateralXCdf::Point> points;
|
|
37
|
+
for (const auto &point : nb::cast<std::vector<std::array<double, 2>>>(model["lateral_x_points"]))
|
|
38
|
+
points.push_back({point[0], point[1]});
|
|
39
|
+
|
|
40
|
+
const auto depth_strata = nb::cast<std::size_t>(sampling["depth_strata"]);
|
|
41
|
+
const auto candidates = nb::cast<std::size_t>(sampling["candidates_per_band_stratum"]);
|
|
42
|
+
const auto margin = nb::cast<double>(sampling["refraction_margin_rad"]);
|
|
43
|
+
const auto minimum_axis_cosine = nb::cast<double>(sampling["minimum_axis_cosine"]);
|
|
44
|
+
const auto angular_cutoff = nb::cast<double>(model["angular_log10_u_min"]);
|
|
45
|
+
const auto atmosphere = nb::cast<std::string>(config["atmosphere"]);
|
|
46
|
+
|
|
47
|
+
std::vector<TelescopeTarget> targets;
|
|
48
|
+
for (const auto &telescope : nb::cast<std::vector<nb::dict>>(config["telescopes"])) {
|
|
49
|
+
const auto centre = nb::cast<std::array<double, 3>>(telescope["centre_m"]);
|
|
50
|
+
TelescopeTarget target{};
|
|
51
|
+
target.centre_m = {centre[0], centre[1], centre[2]};
|
|
52
|
+
target.telescope_id = nb::cast<std::uint32_t>(telescope["id"]);
|
|
53
|
+
target.radius_m = nb::cast<double>(telescope["radius_m"]);
|
|
54
|
+
targets.push_back(target);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
std::vector<ShowerSamplingInput> events;
|
|
58
|
+
for (const auto &event : nb::cast<std::vector<nb::dict>>(config["events"])) {
|
|
59
|
+
ShowerSamplingInput input{};
|
|
60
|
+
input.primary_energy_mev = nb::cast<double>(event["energy_gev"]) * 1000.;
|
|
61
|
+
input.observation_level_m = observation_level;
|
|
62
|
+
const auto core = nb::cast<std::array<double, 2>>(event["core_xy_m"]);
|
|
63
|
+
input.core_x_m = core[0];
|
|
64
|
+
input.core_y_m = core[1];
|
|
65
|
+
const auto theta = nb::cast<double>(event["zenith_deg"]) * pi / 180.;
|
|
66
|
+
const auto phi = nb::cast<double>(event["azimuth_deg"]) * pi / 180.;
|
|
67
|
+
input.shower_axis = {std::sin(theta) * std::cos(phi), std::sin(theta) * std::sin(phi),
|
|
68
|
+
-std::cos(theta)};
|
|
69
|
+
input.event_id = nb::cast<std::uint32_t>(event["id"]);
|
|
70
|
+
input.seed = seed;
|
|
71
|
+
input.wavelength_min_nm = wl[0];
|
|
72
|
+
input.wavelength_max_nm = wl[1];
|
|
73
|
+
input.depth_strata = depth_strata;
|
|
74
|
+
input.candidates_per_band_stratum = candidates;
|
|
75
|
+
input.refraction_margin_rad = margin;
|
|
76
|
+
input.minimum_axis_cosine = minimum_axis_cosine;
|
|
77
|
+
input.angular_min_log10_u = angular_cutoff;
|
|
78
|
+
if (event.contains("first_interaction_g_cm2")) {
|
|
79
|
+
input.first_interaction_g_cm2 = nb::cast<double>(event["first_interaction_g_cm2"]);
|
|
80
|
+
} else {
|
|
81
|
+
if (depths.empty())
|
|
82
|
+
throw std::invalid_argument("missing empirical first-interaction depths");
|
|
83
|
+
const double draw = obdeect::stream::uniform4(
|
|
84
|
+
{seed, obdeect::stream::stage_shower, input.event_id, 0, 0, 65535})[0];
|
|
85
|
+
const auto index = std::min(
|
|
86
|
+
static_cast<std::size_t>(draw * static_cast<double>(depths.size())), depths.size() - 1);
|
|
87
|
+
input.first_interaction_g_cm2 = depths[index];
|
|
88
|
+
}
|
|
89
|
+
events.push_back(input);
|
|
90
|
+
}
|
|
91
|
+
const ShowerStreamMetadata metadata{nb::cast<std::string>(config["model_sha256"]),
|
|
92
|
+
nb::cast<std::string>(config["atmosphere_sha256"]),
|
|
93
|
+
nb::cast<std::string>(config["first_interaction_sha256"])};
|
|
94
|
+
|
|
95
|
+
nb::gil_scoped_release release;
|
|
96
|
+
const AtmosphereProfile profile(atmosphere);
|
|
97
|
+
const LateralXCdf x_cdf(points);
|
|
98
|
+
// Each cached band holds two angular tables of 4097 doubles. Keep large
|
|
99
|
+
// configurations on the one-band-at-a-time path.
|
|
100
|
+
constexpr std::size_t max_cached_bands = 1024;
|
|
101
|
+
const bool reuse = targets.size() > 1 && !thresholds.empty() &&
|
|
102
|
+
depth_strata <= max_cached_bands / thresholds.size();
|
|
103
|
+
const ShowerSamplingInput *cached_event = nullptr;
|
|
104
|
+
std::optional<PreparedTargetedShower> prepared;
|
|
105
|
+
const auto sample = [&](const auto &event, const auto &target, auto emit) {
|
|
106
|
+
if (!reuse) {
|
|
107
|
+
sample_targeted(event, profile, target, emit, thresholds, x_cdf);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// write_run emits all targets of a given event consecutively.
|
|
111
|
+
if (cached_event != &event) {
|
|
112
|
+
prepared.emplace(event, profile, thresholds);
|
|
113
|
+
cached_event = &event;
|
|
114
|
+
}
|
|
115
|
+
prepared->sample(target, emit, x_cdf);
|
|
116
|
+
};
|
|
117
|
+
if (path == "-") {
|
|
118
|
+
write_run(std::cout, events, targets, metadata, sample);
|
|
119
|
+
std::cout.flush();
|
|
120
|
+
if (!std::cout)
|
|
121
|
+
throw std::runtime_error("writing shower stream to stdout failed");
|
|
122
|
+
} else {
|
|
123
|
+
std::ofstream out(path, std::ios::binary);
|
|
124
|
+
if (!out)
|
|
125
|
+
throw std::runtime_error("cannot open shower output " + path);
|
|
126
|
+
write_run(out, events, targets, metadata, sample);
|
|
127
|
+
out.close();
|
|
128
|
+
if (!out)
|
|
129
|
+
throw std::runtime_error("writing shower output " + path + " failed");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
} // namespace
|
|
134
|
+
|
|
135
|
+
NB_MODULE(_shower, module) {
|
|
136
|
+
module.def("write_run", &write_run_py, nb::arg("config"), nb::arg("path"));
|
|
137
|
+
}
|