Repository navigation
fix: make time offsets generate in order #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mesmith75
wants to merge
27
commits into
main
Choose a base branch
from
sorted_times
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a4f3a00
fix: make time offsets generate in order
f48cfbe
fix: make time offsets generate in order
7460079
feat: add ordered times
983f272
feat: add ordered times
9aad1fe
Merge branch 'main' into sorted_times
mesmith75 97b9bbc
fix: generate time in order
22e9fb5
Merge branch 'sorted_times' of github.com-shipsoft-shannon:ShipSoft/S…
33ac8e2
fix: generate time in order
d977125
fix: generate time in order
694cf43
feat: sort times
8659c1a
feat: time spread
75924e6
feat: time spread
91febae
feat: order times
8d475e3
fix: sort field cases
f2736f1
Merge branch 'fix_names' into sorted_times
9aef24b
feat: time ordering
b4800b5
feat: sorted times
11a68e1
feat: ordered random times
301b085
feat: ordered random times
e6681c4
feat: time ordered events
5241c60
feat: sorted times
d45b2ea
feat: sorted times
3e0535f
feat: sort times
2b218ca
feat: time order
fa5406d
feat: sorted times
196f62a
feat: sorted times
d0ecdc6
feat: time ordering
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
mesmith75 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #pragma once | ||
| // SPDX-FileCopyrightText: 2026 CERN for the benefit of the SHiP Collaboration | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| // read_sim_file.cpp — Phlex source plugin | ||
| // | ||
| // This is a tool to generate random numbers approximately in order. | ||
| // It does so by sampling from an approximate beta distribution. | ||
| // The kth ordered statistic of a uniform distribution with n total | ||
| // draws is distributed as a beta function beta(k, n-k+1) | ||
|
|
||
| #include <SHiP/random/philox_rng.hpp> | ||
| #include <cmath> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| class approx_sorted_random { | ||
| public: | ||
| approx_sorted_random(std::uint32_t seed, std::uint32_t stream = 0xBEEFCAFE, | ||
|
Check warning on line 23 in src/utilities/approx_sorted_random.hpp
|
||
| const double maxTime = 1., const std::uint64_t nPoT = 10000) | ||
| : m_maxTime(maxTime), m_n(nPoT), m_seed(seed), m_stream(stream) { | ||
| // Negated so that a NaN maxTime is rejected too. | ||
| if (!(m_maxTime > 0.0)) | ||
| throw std::invalid_argument( | ||
| "The maximum time of the spill fraction must be positive. Check your options."); | ||
| if (m_n == 0) | ||
| throw std::invalid_argument("The number of events to run over must be positive."); | ||
| }; | ||
| [[nodiscard]] | ||
| double next(const std::uint64_t evtNumber) { | ||
| // k = evtNumber + 1 must satisfy k <= m_n, otherwise Beta(k, m_n - k + 1) | ||
| // has a non-positive shape parameter. | ||
| if (evtNumber >= m_n) | ||
| throw std::invalid_argument( | ||
| "Trying to generate a time for an event beyond the number generated. Check your " | ||
| "PoT."); | ||
| const std::uint64_t k = evtNumber + 1; | ||
| SHiP::random::PhiloxRng rng{m_seed, m_stream, k}; | ||
| return rng.beta_dist_approx(static_cast<double>(k), static_cast<double>(m_n - k + 1), | ||
| SHiP::random::Precision::Bits53) * | ||
| m_maxTime; | ||
|
mesmith75 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private: | ||
| double m_maxTime = 0.; | ||
| std::uint64_t m_n = 0; | ||
| std::uint32_t m_seed = 0; | ||
| std::uint32_t m_stream = 0; | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.