ATLAS Offline Software
ISF_Geant4ToolsConfig.py
Go to the documentation of this file.
1 """Geant4 tools config for ISF with ComponentAccumulator
2 
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 """
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory import CompFactory
7 from RngComps.RngCompsConfig import AthRNGSvcCfg
8 from G4AtlasServices.G4AtlasServicesConfig import (
9  DetectorGeometrySvcCfg, PhysicsListSvcCfg
10 )
11 from G4AtlasServices.G4AtlasUserActionConfig import (
12  ISFUserActionSvcCfg, ISFFullUserActionSvcCfg,
13  ISFPassBackUserActionSvcCfg, ISF_ATLFAST_UserActionSvcCfg,
14 )
15 from G4AtlasTools.G4AtlasToolsConfig import (
16  SensitiveDetectorMasterToolCfg, FastSimulationMasterToolCfg
17 )
18 from ISF_Services.ISF_ServicesConfig import (
19  InputConverterCfg
20 )
21 
22 
23 def G4RunManagerHelperCfg(flags, name="G4RunManagerHelper", **kwargs):
24  acc = ComponentAccumulator()
25  acc.setPrivateTools(CompFactory.iGeant4.G4RunManagerHelper(name, **kwargs))
26  return acc
27 
28 
29 def Geant4ToolCfg(flags, name="ISF_Geant4Tool", **kwargs):
30  acc = ComponentAccumulator()
31  kwargs.setdefault("DetGeoSvc", acc.getPrimaryAndMerge(DetectorGeometrySvcCfg(flags)).name)
32 
33  kwargs.setdefault("RandomNumberService", acc.getPrimaryAndMerge(AthRNGSvcCfg(flags)).name)
34 
35  # Only add it if it's not added already
36  if "InputConverter" not in kwargs.keys():
37  kwargs.setdefault("InputConverter", acc.getPrimaryAndMerge(InputConverterCfg(flags)).name)
38 
39  if "UserActionSvc" not in kwargs.keys():
40  kwargs.setdefault("UserActionSvc", acc.getPrimaryAndMerge(ISFUserActionSvcCfg(flags)).name)
41 
42  kwargs.setdefault("RecordFlux", flags.Sim.RecordFlux)
43 
44  kwargs.setdefault("QuietMode", flags.Exec.QuietMode)
45 
46  kwargs.setdefault("MultiThreading", flags.Concurrency.NumThreads > 0)
47  # Set commands for the G4AtlasAlg
48  kwargs.setdefault("G4Commands", flags.Sim.G4Commands)
49  kwargs.setdefault("PrintTimingInfo", flags.Sim.ISF.DoTimeMonitoring)
50  if "SenDetMasterTool" not in kwargs:
51  kwargs.setdefault("SenDetMasterTool", acc.addPublicTool(acc.popToolsAndMerge(SensitiveDetectorMasterToolCfg(flags))))
52  if "FastSimMasterTool" not in kwargs:
53  kwargs.setdefault("FastSimMasterTool", acc.addPublicTool(acc.popToolsAndMerge(FastSimulationMasterToolCfg(flags))))
54 
55  # PhysicsListSvc
56  kwargs.setdefault("PhysicsListSvc", acc.getPrimaryAndMerge(PhysicsListSvcCfg(flags)).name)
57 
58  # Workaround to keep other simulation flavours working while we migrate everything to be AthenaMT-compatible.
59  from SimulationConfig.SimEnums import SimulationFlavour
60  if flags.Sim.ISF.Simulator in [SimulationFlavour.ATLFAST3F_ACTSMT, SimulationFlavour.FullG4MT, SimulationFlavour.FullG4MT_QS, SimulationFlavour.PassBackG4MT, SimulationFlavour.ATLFAST3MT, SimulationFlavour.ATLFAST3MT_QS]:
61  acc.setPrivateTools(CompFactory.iGeant4.G4TransportTool(name, **kwargs))
62  else:
63  kwargs.setdefault("G4RunManagerHelper", acc.addPublicTool(acc.popToolsAndMerge(G4RunManagerHelperCfg(flags))))
64  acc.setPrivateTools(CompFactory.iGeant4.G4LegacyTransportTool(name, **kwargs))
65  return acc
66 
67 
68 def FullGeant4ToolCfg(flags, name="ISF_FullGeant4Tool", **kwargs):
69  acc = ComponentAccumulator()
70  kwargs.setdefault("UserActionSvc", acc.getPrimaryAndMerge(ISFFullUserActionSvcCfg(flags)).name)
71  FullGeant4Tool = acc.popToolsAndMerge(Geant4ToolCfg(flags, name, **kwargs))
72  acc.setPrivateTools(FullGeant4Tool)
73  return acc
74 
75 
76 def PassBackGeant4ToolCfg(flags, name="ISF_PassBackGeant4Tool", **kwargs):
77  acc = ComponentAccumulator()
78  kwargs.setdefault("UserActionSvc", acc.getPrimaryAndMerge(ISFPassBackUserActionSvcCfg(flags)).name)
79  PassBackGeant4Tool = acc.popToolsAndMerge(Geant4ToolCfg(flags, name, **kwargs))
80  acc.setPrivateTools(PassBackGeant4Tool)
81  return acc
82 
83 
84 def ATLFAST_Geant4ToolCfg(flags, name="ISF_ATLFAST_Geant4Tool", **kwargs): # TODO Rename
85  acc = ComponentAccumulator()
86  kwargs.setdefault("UserActionSvc", acc.getPrimaryAndMerge(ISF_ATLFAST_UserActionSvcCfg(flags)).name)
87  PassBackGeant4Tool = acc.popToolsAndMerge(Geant4ToolCfg(flags, name, **kwargs))
88  acc.setPrivateTools(PassBackGeant4Tool)
89  return acc
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
G4AtlasUserActionConfig.ISFFullUserActionSvcCfg
def ISFFullUserActionSvcCfg(flags, name="G4UA::ISFFullUserActionSvc", **kwargs)
Definition: G4AtlasUserActionConfig.py:212
python.ISF_Geant4ToolsConfig.FullGeant4ToolCfg
def FullGeant4ToolCfg(flags, name="ISF_FullGeant4Tool", **kwargs)
Definition: ISF_Geant4ToolsConfig.py:68
G4AtlasServicesConfig.DetectorGeometrySvcCfg
def DetectorGeometrySvcCfg(flags, name="DetectorGeometrySvc", **kwargs)
Definition: G4AtlasServicesConfig.py:14
G4AtlasToolsConfig.FastSimulationMasterToolCfg
def FastSimulationMasterToolCfg(flags, **kwargs)
Definition: G4AtlasToolsConfig.py:53
python.ISF_Geant4ToolsConfig.G4RunManagerHelperCfg
def G4RunManagerHelperCfg(flags, name="G4RunManagerHelper", **kwargs)
Definition: ISF_Geant4ToolsConfig.py:23
G4AtlasUserActionConfig.ISFPassBackUserActionSvcCfg
def ISFPassBackUserActionSvcCfg(flags, name="G4UA::ISFPassBackUserActionSvc", **kwargs)
Definition: G4AtlasUserActionConfig.py:222
G4AtlasUserActionConfig.ISF_ATLFAST_UserActionSvcCfg
def ISF_ATLFAST_UserActionSvcCfg(flags, name="G4UA::ISF_ATLFAST_UserActionSvc", **kwargs)
Definition: G4AtlasUserActionConfig.py:233
G4AtlasServicesConfig.PhysicsListSvcCfg
def PhysicsListSvcCfg(flags, name="PhysicsListSvc", **kwargs)
Definition: G4AtlasServicesConfig.py:22
python.ISF_Geant4ToolsConfig.Geant4ToolCfg
def Geant4ToolCfg(flags, name="ISF_Geant4Tool", **kwargs)
Definition: ISF_Geant4ToolsConfig.py:29
python.ISF_Geant4ToolsConfig.ATLFAST_Geant4ToolCfg
def ATLFAST_Geant4ToolCfg(flags, name="ISF_ATLFAST_Geant4Tool", **kwargs)
Definition: ISF_Geant4ToolsConfig.py:84
python.ISF_Geant4ToolsConfig.PassBackGeant4ToolCfg
def PassBackGeant4ToolCfg(flags, name="ISF_PassBackGeant4Tool", **kwargs)
Definition: ISF_Geant4ToolsConfig.py:76
ISF_ServicesConfig.InputConverterCfg
def InputConverterCfg(flags, name="ISF_InputConverter", **kwargs)
Definition: ISF_ServicesConfig.py:33
G4AtlasToolsConfig.SensitiveDetectorMasterToolCfg
def SensitiveDetectorMasterToolCfg(flags, name="SensitiveDetectorMasterTool", **kwargs)
Definition: G4AtlasToolsConfig.py:372
G4AtlasUserActionConfig.ISFUserActionSvcCfg
def ISFUserActionSvcCfg(flags, name="G4UA::ISFUserActionSvc", **kwargs)
Definition: G4AtlasUserActionConfig.py:190
RngCompsConfig.AthRNGSvcCfg
def AthRNGSvcCfg(flags, name="AthRNGSvc")
Definition: RngCompsConfig.py:51