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

Add Particle filter stacking action option #244

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

EricMEsch
Copy link
Collaborator

@EricMEsch EricMEsch commented Jan 27, 2025

Adresses #218.

Not tested so far. I did try the make remage-doc-dump as i add new macro commands here, but it did not update the rmg-commands file.

@tdixon97 I made a new PR instead of re-opening the old one, as i force pushed the changes back then into non-existence.

  • Compile tested
  • Write actual tests
  • Doxygen documentation

@tdixon97
Copy link
Collaborator

@EricMEsch one thing I don't understand is why this would be a separate output scheme?



std::optional<G4ClassificationOfNewTrack> RMGParticleFilterOutputScheme::
StackingActionClassify(const G4Track* aTrack, int stage) {
Copy link
Collaborator

@tdixon97 tdixon97 Jan 28, 2025

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.

Copy link
Collaborator Author

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 to OpticalPhotons). Otherwise they will be discarded. So i am not sure what exactly you refer to?

@tdixon97
Copy link
Collaborator

I guess a simple test would be to run this with eg. alphas for some alpha decay and check that all the events are removed, and also a beta decay (checking nothing changes)?

@EricMEsch
Copy link
Collaborator Author

one thing I don't understand is why this would be a separate output scheme?

I mean it does not have to be. It is only utilizing the hook into the StackingAction for OutputSchemes. This could also be part of the StackingAction. I just thought it would be a better way of organizing to use this structure. If we are going to add multiple things to the StackingAction later on, we would be happy if they were not all hard coded into it. Also, this means that in case the OptionalOutputScheme is not activated by macro, this code will never be executed, which is a little bit faster i would assume.

I guess a simple test would be to run this with eg. alphas for some alpha decay and check that all the events are removed, and also a beta decay (checking nothing changes)?

Could be worth a try, although i am not sure how Geant4 will react if you immediately kill the primary generated particle from the stack. In theory it should be fine i guess.

@gipert gipert marked this pull request as draft January 29, 2025 16:18
src/RMGParticleFilterOutputScheme.cc Outdated Show resolved Hide resolved
include/RMGParticleFilterOutputScheme.hh Outdated Show resolved Hide resolved
include/RMGParticleFilterOutputScheme.hh Outdated Show resolved Hide resolved
@EricMEsch EricMEsch added the enhancement New feature or request label Jan 29, 2025
@ManuelHu
Copy link
Collaborator

ManuelHu commented Feb 3, 2025

please also add to remage-doc-dump.cc, i.e. here:

// output schemes
new RMGGermaniumOutputScheme();
new RMGOpticalOutputScheme();
new RMGVertexOutputScheme();
new RMGScintillatorOutputScheme();
new RMGIsotopeFilterOutputScheme();
new RMGTrackOutputScheme();

also, please rebase on main (on include #252) and run make remage-doc-dump

@tdixon97
Copy link
Collaborator

tdixon97 commented Feb 7, 2025

@EricMEsch I wonder if it is possible to make this volume dependent or maybe G4Region dependent.
The reason is we are running some remage simulations for our detector at UCL, a screening like setup, but they are quite slow and I want to kill betas (only in the source not the detector of course).
I think this could be a rather common useful feature for screening setups?

@EricMEsch
Copy link
Collaborator Author

EricMEsch commented Feb 7, 2025

It should certainly both be possible. For the volume dependence i guess a user would just have to specify the name of the physical volume.

I think a reasonable way to implement is:

  • Delete the specified particle everywhere if no volume is specified
  • As soon as at least one volume is specified only delete the particle in said volume.

The important thing to remember is, that this deletes on creation, so there is no way of knowing if the particle might have reached another volume.

The G4Region thing should certainly also be possible, but i have not looked into G4Region yet (but i dont think its complicated). The question is do we even want both? I think specifying the volume would be totally enough

@tdixon97
Copy link
Collaborator

tdixon97 commented Feb 7, 2025

What about having either volumes to keep or volumes to kill ? I think the most common use case is kill everywhere apart from in a sensitive detector?

@EricMEsch
Copy link
Collaborator Author

Should also be possible

The logic would then be

  • Kill everywhere if nothing is specified
  • If volume to keep is specified kill everywhere but said volume
  • If volume to kill is specified kill only in that volume (ignore volumes to keep)

I guess i could add a warning if a volume to keep is specified in the same simulation with a volume to kill (as those are conflicting requests)

@tdixon97
Copy link
Collaborator

tdixon97 commented Feb 7, 2025

Yeah alternatively we just have an option for the default and sensitive regions, these are already defined and I think then you can easily check which region a volume belongs to ? ie. G4Region::BelongsTo

I am not sure using the Regions is the right approach since its less easy to modify though..

@EricMEsch
Copy link
Collaborator Author

I personally would prefer the volume by name option, but maybe that is just because i have not looked at the regions yet.
If that is easy i could also add that option. Although then the options might start to become overwhelming and confusing for the user.

@EricMEsch
Copy link
Collaborator Author

@tdixon97 The option to add kill/keep volumes is now implemented. I am not 100% sure if the information about the physical volume actually exists at this point (as we catch the track before the tracking started), but i am pretty sure it does and we will quickly find out in testing.

The only "issue" now is that you can not specify a volume per particle. You specify volumes and particles and the filter is applied to all specified particles in all specified volumes.

It would be possible to use std::map<int, std::vector<std::string>> instead, but this would probably mean that i would have to add a custom messenger to allow the user to specify pdg codes togheter with a volume name.

@tdixon97
Copy link
Collaborator

tdixon97 commented Feb 8, 2025 via email

@EricMEsch
Copy link
Collaborator Author

EricMEsch commented Feb 8, 2025

I have just done some tests (still need to add pipeline tests)

  • Seems to work like expected, the only issue is if you filter the same particle as your primary. This results in an immediate segmentation fault (was kinda expecting G4 not to be happy with that). I might add an exception to that.
  • If you specfiy a volume as both a keeper and a killer, an error will be shown but the application will not end. If you continue anyways the volume will be treated as keeper. (Which is not equivalent to specifying the volume as keeper only, as the existence of a killer volume means that only particles in killer volumes will be deleted).
  • The TrackID will still increase. E.g: An electron has 4 secondaries: e-,gamma,e-,gamma: If you run with tracking verbosity 2 it will still show you all 4 particles as being secondaries of the main particle. However the tracking then only shows TrackID 1 (e-) and TrackID 3 (e-). TrackID 2 and 4 is skipped (as the gammas are immediately killed before tracking).

@tdixon97
Copy link
Collaborator

tdixon97 commented Feb 9, 2025

I think an exception for killing the primary is a very nice idea.
Overall this looks very nice. We could consider adding something to the validation suite about the effect of this.

If you specfiy a volume as both a keeper and a killer, an error will be shown but the application will not end. If you continue anyways the volume will be treated as keeper. (Which is not equivalent to specifying the volume as keeper only, as the existence of a killer volume means that only particles in killer volumes will be deleted).

Is it better just to stop the application?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants