4 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
5 from AthenaConfiguration.ComponentFactory
import CompFactory
6 from AthenaConfiguration.Enums
import BeamType, LHCPeriod
7 from CaloG4Sim.CaloG4SimConfig
import CalibrationDefaultProcessingToolCfg
8 from SimulationConfig.SimEnums
import CalibrationRun, CavernBackground, SimulationFlavour
9 from G4CosmicFilter.G4CosmicFilterConfig
import CosmicFilterToolCfg, StoppedParticleFilterToolCfg
10 from G4UserActions.G4UserActionsConfig
import (
11 AthenaStackingActionToolCfg, AthenaTrackingActionToolCfg,
12 G4SimTimerToolCfg, G4TrackCounterToolCfg, HitWrapperToolCfg,
13 LooperKillerToolCfg, StoppedParticleActionToolCfg
15 from ISF_Geant4CommonTools.ISF_Geant4CommonToolsConfig
import EntryLayerToolCfg, EntryLayerToolMTCfg
16 from ISF_Services.ISF_ServicesCoreConfig
import ATLFAST_GeoIDSvcCfg, GeoIDSvcCfg
17 from ISF_Services.ISF_ServicesConfig
import (
18 ATLFAST_ParticleBrokerSvcCfg, ParticleBrokerSvcCfg, TruthServiceCfg
20 from MCTruthBase.MCTruthBaseConfig
import MCTruthSteppingActionToolCfg
24 """ flags.Sim.OptionalUserActionList = ['G4UserActions.G4UserActionsConfig.FixG4CreatorProcessToolCfg']"""
26 optionalUserActions = []
27 for userActionString
in flags.Sim.OptionalUserActionList:
28 optionalUserActions += [result.popToolsAndMerge(
getOptionalUACfg(flags, userActionString))]
29 result.setPrivateTools(optionalUserActions)
34 """Execute a function to configure and optional UserAction"""
35 parts = userActionString.split(
'.')
37 raise ValueError(
'OptionalUserAction strings should be of the form Package.Module.Function or Package.Function if defined in __init__.py')
39 module =
'.'.
join(parts[:-1])
40 from importlib
import import_module
41 loaded_module = import_module(module)
42 function_def = getattr(loaded_module, function)
43 return function_def(flags)
49 if flags.Sim.ISF.Simulator
in [SimulationFlavour.FullG4MT, SimulationFlavour.FullG4MT_QS]:
52 tool = result.popToolsAndMerge(EntryLayerToolCfg(flags))
53 kwargs.setdefault(
"EntryLayerTool", result.addPublicTool(tool))
54 kwargs.setdefault(
"GeoIDSvc", result.getPrimaryAndMerge(
GeoIDSvcCfg(flags)).name)
55 if flags.Detector.GeometryCavern:
56 kwargs.setdefault(
"TruthVolumeLevel", 2)
57 kwargs.setdefault(
"IsITkGeometry", flags.GeoModel.Run >= LHCPeriod.Run4)
58 result.setPrivateTools(CompFactory.G4UA.iGeant4.TrackProcessorUserActionFullG4Tool(name, **kwargs))
64 result.setPrivateTools(CompFactory.G4UA.iGeant4.PhysicsValidationUserActionTool(name, **kwargs))
70 kwargs.setdefault(
"TruthRecordSvc", result.getPrimaryAndMerge(
TruthServiceCfg(flags)).name)
71 result.setPrivateTools(CompFactory.G4UA.iGeant4.MCTruthUserActionTool(name, **kwargs))
77 if "ParticleBroker" not in kwargs:
79 kwargs.setdefault(
"GeoIDSvc", result.getPrimaryAndMerge(
GeoIDSvcCfg(flags)).name)
80 result.setPrivateTools(CompFactory.G4UA.iGeant4.TrackProcessorUserActionPassBackTool(name, **kwargs))
85 if flags.Sim.ISF.Simulator
in [SimulationFlavour.PassBackG4MT]:
86 kwargs.setdefault(
"ParticleBroker",
"")
92 if flags.Sim.ISF.Simulator
in [SimulationFlavour.PassBackG4MT, SimulationFlavour.ATLFASTIIMT, SimulationFlavour.ATLFAST3MT, SimulationFlavour.ATLFAST3MT_QS]:
93 kwargs.setdefault(
"ParticleBroker",
"")
94 elif flags.Sim.ISF.Simulator
in [SimulationFlavour.ATLFASTIIF_G4MS, SimulationFlavour.ATLFAST3F_G4MS]:
97 kwargs.setdefault(
"PassBackEkinThreshold", 0.05*MeV)
98 kwargs.setdefault(
"KillBoundaryParticlesBelowThreshold",
True)
100 result.setPrivateTools(tool)
114 if not flags.Sim.ISFRun:
122 if flags.Beam.Type
is BeamType.Cosmics
and flags.Sim.CavernBackground
is CavernBackground.Off:
123 actions += [CompFactory.G4UA.CosmicPerigeeActionTool()]
125 if flags.Beam.Type
is BeamType.Cosmics
and not flags.Sim.ISFRun:
127 if flags.Sim.StoppedParticleFile:
131 if flags.Sim.CavernBackground
is CavernBackground.Read:
134 if flags.Sim.PhysicsList ==
"QGSP_BERT_HP":
135 actions += [CompFactory.G4UA.PhotonKillerTool()]
137 if flags.Sim.CalibrationRun
in [CalibrationRun.LArTile, CalibrationRun.LArTileZDC]:
139 if 'G4UserActions.G4UserActionsConfig.MonopoleLooperKillerToolCfg' not in flags.Sim.OptionalUserActionList:
142 result.setPrivateTools(actions)
148 Get the standard UA svc configurable with all default actions added.
149 This function is normally called by the configured factory, not users.
157 kwargs.setdefault(
"UserActionTools", generalActions)
160 result.addService(CompFactory.G4UA.UserActionSvc(name, **kwargs), primary =
True)
183 kwargs.setdefault(
"UserActionTools", generalActions)
186 result.addService(CompFactory.G4UA.UserActionSvc(name, **kwargs), primary =
True)
192 TrackProcessorUserAction = kwargs.pop("TrackProcessorUserAction",[])
194 PhysicsValidationUserAction = []
195 if flags.Sim.ISF.ValidationMode:
198 MCTruthUserAction = kwargs.pop(
"MCTruthUserAction",
201 generalActions = ( TrackProcessorUserAction + MCTruthUserAction +
204 PhysicsValidationUserAction )
207 kwargs.setdefault(
"UserActionTools", generalActions)
208 result.addService(CompFactory.G4UA.UserActionSvc(name, **kwargs), primary =
True)
216 kwargs.setdefault(
"TrackProcessorUserAction", [tpAcc.popPrivateTools()])
226 kwargs.setdefault(
"TrackProcessorUserAction",
237 kwargs.setdefault(
"TrackProcessorUserAction",