-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add Particle filter stacking action option #244
Draft
EricMEsch
wants to merge
5
commits into
legend-exp:main
Choose a base branch
from
EricMEsch:main
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.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cdf695e
Add Particle filter stacking action option
EricMEsch ae79f12
Add to DefaultOptionalOutputSchemes
EricMEsch a487041
Remove obsolete includes and add to doc-dump
EricMEsch cd30135
Add option to specify kill/keep volumes
EricMEsch 08017de
update docs
EricMEsch 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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,50 @@ | ||
// Copyright (C) 2022 Luigi Pertoldi <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify it under | ||
// the terms of the GNU Lesser General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) any | ||
// later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
// details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef _RMG_PARTICLE_FILTER_OUTPUT_SCHEME_HH_ | ||
#define _RMG_PARTICLE_FILTER_OUTPUT_SCHEME_HH_ | ||
|
||
#include <optional> | ||
#include <set> | ||
|
||
#include "G4GenericMessenger.hh" | ||
|
||
#include "RMGVOutputScheme.hh" | ||
|
||
class RMGParticleFilterOutputScheme : public RMGVOutputScheme { | ||
|
||
public: | ||
|
||
RMGParticleFilterOutputScheme(); | ||
|
||
std::optional<G4ClassificationOfNewTrack> StackingActionClassify(const G4Track*, int) override; | ||
|
||
inline void AddParticle(int pdg) { fParticles.insert(pdg); } | ||
void AddKeepVolume(std::string name); | ||
void AddKillVolume(std::string name); | ||
|
||
private: | ||
|
||
std::unique_ptr<G4GenericMessenger> fMessenger; | ||
void DefineCommands(); | ||
|
||
std::set<int> fParticles; | ||
std::set<std::string> fKeepVolumes; | ||
std::set<std::string> fKillVolumes; | ||
}; | ||
|
||
#endif | ||
|
||
// vim: tabstop=2 shiftwidth=2 expandtab |
This file contains 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 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 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,95 @@ | ||
// Copyright (C) 2022 Luigi Pertoldi <[email protected]> | ||
// | ||
// This program is free software: you can redistribute it and/or modify it under | ||
// the terms of the GNU Lesser General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) any | ||
// later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
// details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#include "RMGParticleFilterOutputScheme.hh" | ||
|
||
#include <set> | ||
|
||
#include "G4Event.hh" | ||
#include "G4EventManager.hh" | ||
|
||
#include "RMGLog.hh" | ||
|
||
RMGParticleFilterOutputScheme::RMGParticleFilterOutputScheme() { this->DefineCommands(); } | ||
|
||
void RMGParticleFilterOutputScheme::AddKeepVolume(std::string name) { | ||
if (!fKillVolumes.empty()) { | ||
RMGLog::OutDev(RMGLog::error, "Conflicting requests for kill/keep volume in ParticleFilter. " | ||
"Trying to assign keep-volume but a kill-volume already exists."); | ||
} | ||
|
||
fKeepVolumes.insert(name); | ||
} | ||
|
||
void RMGParticleFilterOutputScheme::AddKillVolume(std::string name) { | ||
if (!fKeepVolumes.empty()) { | ||
RMGLog::OutDev(RMGLog::error, "Conflicting requests for kill/keep volume in ParticleFilter. " | ||
"Trying to assign kill-volume but a keep-volume already exists."); | ||
} | ||
|
||
fKillVolumes.insert(name); | ||
} | ||
|
||
std::optional<G4ClassificationOfNewTrack> RMGParticleFilterOutputScheme:: | ||
StackingActionClassify(const G4Track* aTrack, int stage) { | ||
|
||
const int pdg = aTrack->GetDefinition()->GetPDGEncoding(); | ||
// If the particle is not marked to kill, let it go | ||
if (fParticles.find(pdg) == fParticles.end()) return std::nullopt; | ||
|
||
const auto pv = aTrack->GetTouchableHandle()->GetVolume(); | ||
// I am not 100% sure the physical volume will exist at this point. Can remove after some tests | ||
if (!pv) { RMGLog::OutDev(RMGLog::debug, "Physical volume does not exist in ParticleFilter!"); } | ||
const auto pv_name = pv->GetName(); | ||
// If a kill volume is specified only kill if in the kill volume. | ||
if (!fKillVolumes.empty() && fKillVolumes.find(pv_name) == fKillVolumes.end()) | ||
return std::nullopt; | ||
// If a keep volume is specified only keep particle if in that volume. | ||
if (fKeepVolumes.find(pv_name) != fKeepVolumes.end()) return std::nullopt; | ||
|
||
// We land here if | ||
// i) Particle is marked to kill. | ||
// ii) No Kill volume specified or the particle is in the kill volume. | ||
// iii) Particle is not in the keep volume. | ||
RMGLog::OutDev(RMGLog::debug, "Filtering out particle with PDG code ", pdg, | ||
" in RMGParticleFilterOutputScheme"); | ||
return fKill; | ||
} | ||
|
||
void RMGParticleFilterOutputScheme::DefineCommands() { | ||
|
||
fMessenger = std::make_unique<G4GenericMessenger>(this, "/RMG/Output/ParticleFilter/", | ||
"Commands for filtering particles out by PDG encoding."); | ||
|
||
fMessenger->DeclareMethod("AddParticle", &RMGParticleFilterOutputScheme::AddParticle) | ||
.SetGuidance("Add a particle to be filtered out by its PDG code. User is responsible for " | ||
"correct PDG code.") | ||
.SetParameterName(0, "PDGcode", false, false) | ||
.SetStates(G4State_Idle); | ||
|
||
fMessenger->DeclareMethod("AddKeepVolume", &RMGParticleFilterOutputScheme::AddKeepVolume) | ||
.SetGuidance("Add a physical volume by name in which all specified Particles will be kept. " | ||
"They will be killed everywhere else. Can NOT be mixed with KillVolumes.") | ||
.SetParameterName(0, "PhysicalVolumeName", false, false) | ||
.SetStates(G4State_Idle); | ||
|
||
fMessenger->DeclareMethod("AddKillVolume", &RMGParticleFilterOutputScheme::AddKillVolume) | ||
.SetGuidance("Add a physical volume by name in which all specified Particles will be killed. " | ||
"They will only be killed in this volume. Can NOT be mixed with KeepVolumes.") | ||
.SetParameterName(0, "PhysicalVolumeName", false, false) | ||
.SetStates(G4State_Idle); | ||
} | ||
|
||
// vim: tabstop=2 shiftwidth=2 expandtab |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to only stack particles after stage 1, eg. I am thinking about stacking nuclei only after they decay? Probably for nuclei its a bit difficult since you might have additional decays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fairly certain the stages are something that is inherently handled by the user (us) and not G4? So far we run one stage, meaning everything until the Particle-Stack is empty. Then we check if any OutputScheme requests a new stage. If one OutputScheme requests a new stage, all tracks that have been marked with
fWaiting
will be put on the stack again (which right now can only happen toOpticalPhotons
). Otherwise they will be discarded. So i am not sure what exactly you refer to?