Skip to content

Commit

Permalink
refactor: Rework particles_selected handling in Python Examples (#3423
Browse files Browse the repository at this point in the history
)

Small rework of the `particles_selected` handling in Python. I create dedicated whiteboard entries for the different simulators and then alias them to `particles_selected`. This allows for reassignment of `particles_selected` later and moves the alias also to the post selection after simulation
  • Loading branch information
andiwand authored Jul 22, 2024
1 parent b46d425 commit 1c0b1c5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Examples/Python/python/acts/examples/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,22 @@ def addFatras(

# Selector
if preSelectParticles is not None:
particles_selected = "particles_selected"
particlesSelected = "fatras_particles_preselected"
addParticleSelection(
s,
preSelectParticles,
inputParticles=inputParticles,
outputParticles=particles_selected,
outputParticles=particlesSelected,
)
s.addWhiteboardAlias("particles_selected", particlesSelected)
else:
particles_selected = inputParticles
particlesSelected = inputParticles

# Simulation
alg = acts.examples.FatrasSimulation(
**acts.examples.defaultKWArgs(
level=customLogLevel(),
inputParticles=particles_selected,
inputParticles=particlesSelected,
outputParticlesInitial=outputParticlesInitial,
outputParticlesFinal=outputParticlesFinal,
outputSimHits=outputSimHits,
Expand Down Expand Up @@ -502,6 +503,7 @@ def addFatras(
inputParticles=alg.config.outputParticlesFinal,
outputParticles=particlesFinal,
)
s.addWhiteboardAlias("particles_selected", particlesFinal)
else:
particlesInitial = alg.config.outputParticlesInitial
particlesFinal = alg.config.outputParticlesFinal
Expand Down Expand Up @@ -673,15 +675,16 @@ def addGeant4(

# Selector
if preSelectParticles is not None:
particles_selected = "particles_selected"
particlesSelected = "geant4_particles_preselected"
addParticleSelection(
s,
preSelectParticles,
inputParticles=inputParticles,
outputParticles=particles_selected,
outputParticles=particlesSelected,
)
s.addWhiteboardAlias("particles_selected", particlesSelected)
else:
particles_selected = inputParticles
particlesSelected = inputParticles

if g4DetectorConstructionFactory is None:
if detector is None:
Expand All @@ -705,7 +708,7 @@ def addGeant4(
geant4Handle=__geant4Handle,
detectorConstructionFactory=g4DetectorConstructionFactory,
randomNumbers=rnd,
inputParticles=particles_selected,
inputParticles=particlesSelected,
outputParticlesInitial=outputParticlesInitial,
outputParticlesFinal=outputParticlesFinal,
outputSimHits=outputSimHits,
Expand All @@ -728,21 +731,22 @@ def addGeant4(

# Selector
if postSelectParticles is not None:
particlesInitial = "geant4_particles_initial_selected"
particlesInitial = "geant4_particles_initial_postselected"
addParticleSelection(
s,
postSelectParticles,
inputParticles=alg.config.outputParticlesInitial,
outputParticles=particlesInitial,
)

particlesFinal = "geant4_particles_final_selected"
particlesFinal = "geant4_particles_final_postselected"
addParticleSelection(
s,
postSelectParticles,
inputParticles=alg.config.outputParticlesFinal,
outputParticles=particlesFinal,
)
s.addWhiteboardAlias("particles_selected", particlesFinal)
else:
particlesInitial = alg.config.outputParticlesInitial
particlesFinal = alg.config.outputParticlesFinal
Expand Down

0 comments on commit 1c0b1c5

Please sign in to comment.