Skip to content
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

Optionally generate primaries without a HepMC3 input file in the demo loop #463

Merged
merged 2 commits into from
Jul 27, 2022

Conversation

amandalund
Copy link
Contributor

This adds an optional demo loop input argument to generate primaries based on a specified quantity, particle type, energy, position, and direction rather than reading the events from a HepMC3 input file. For example, adding the following to the input JSON would generate the same primaries as in testem3.100k.hepmc3:

"primary_gen_options": {"pdg": 11, "energy": 10000, "position": [-22, 0, 0], "direction": [1, 0, 0], "num_events": 100000, "primaries_per_event": 1}

This should make it easier to run with a range of inputs, e.g. for #460, without needing to create a new HepMC3 input file each time.

@amandalund amandalund requested a review from sethrj July 26, 2022 23:59
@amandalund amandalund added the enhancement New feature or request label Jul 26, 2022
@sethrj
Copy link
Member

sethrj commented Jul 27, 2022

Ooh fancy! Reviewing now!

Copy link
Member

@sethrj sethrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Two minor comments.

app/demo-loop/LDemoIO.cc Show resolved Hide resolved
src/celeritas/phys/PrimaryGenerator.cc Outdated Show resolved Hide resolved
@sethrj sethrj merged commit a8edbb1 into celeritas-project:master Jul 27, 2022
@amandalund amandalund deleted the primary-gen branch July 27, 2022 17:07
Comment on lines +23 to +35
int pdg; //!< Primary PDG number
real_type energy; //!< [MeV]
Real3 position; //!< [cm]
Real3 direction;
size_type num_events;
size_type primaries_per_event;

//! Whether the options are valid
explicit operator bool() const
{
return pdg != 0 && energy >= 0 && num_events > 0
&& primaries_per_event > 0;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without initializers, these scalar types are uninitialized; in particular for the object LDemoArgs::primary_gen_options. If you're unlucky (and on my machine, I seem to be always unlucky), this makes operator bool() return true and it's not possible to load HepMC3 files (unless an explicit primary_gen_options initializes the fields to zero? not tested).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, you're right: and since there's no unit test for this class it doesn't run through valgrind. I'll add a test and push a fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by #472

sethrj added a commit to sethrj/celeritas that referenced this pull request Aug 21, 2022
The unintentional explicit constructor causes problems with nljson on
clang 14. This showed up because of the IO in celeritas-project#463.
sethrj added a commit that referenced this pull request Aug 21, 2022
The unintentional explicit constructor causes problems with nljson on
clang 14. This showed up because of the IO in #463.
@sethrj sethrj added the app Application front ends label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Application front ends enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants