ATLAS Offline Software
Loading...
Searching...
No Matches
G4AtlasAlgConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2from G4AtlasServices.G4AtlasServicesConfig import PhysicsListSvcCfg
3from ISF_Services.ISF_ServicesConfig import TruthServiceCfg, InputConverterCfg
4from G4AtlasTools.G4GeometryToolConfig import G4AtlasDetectorConstructionToolCfg
5from G4AtlasTools.G4AtlasToolsConfig import G4ThreadPoolSvcCfg, SensitiveDetectorMasterToolCfg, FastSimulationMasterToolCfg
6from G4AtlasServices.G4AtlasUserActionConfig import UserActionSvcCfg
7from SimulationConfig.SimulationMetadata import writeSimulationParametersMetadata, readSimulationParameters
8from AthenaConfiguration.ComponentFactory import CompFactory
9from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
10
11
12def G4AtlasAlgCfg(flags, name="G4AtlasAlg", **kwargs):
13 """Return ComponentAccumulator configured for Atlas G4 simulation, without output"""
14 # wihout output
15 result = ComponentAccumulator()
16 from SimulationConfig.SimEnums import LArParameterization
17 if flags.Sim.LArParameterization is LArParameterization.FastCaloSim:
18 # Add a dummy version of the SimKernel to the CA before adding the properly configured version
19 # Presently necessary for FastCaloSim to ensure the proper order of ISF_CollectionMerger
20 result.addEventAlgo(CompFactory.G4AtlasAlg(name, **kwargs))
21 kwargs.setdefault("UseShadowEvent", flags.Sim.UseShadowEvent)
22 if flags.Sim.UseShadowEvent and "TruthPreselectionTool" not in kwargs:
23 from ISF_HepMC_Tools.ISF_HepMC_ToolsConfig import TruthPreselectionToolCfg
24 kwargs.setdefault( "TruthPreselectionTool", result.popToolsAndMerge(TruthPreselectionToolCfg(flags)) )
25
26 kwargs.setdefault("DetectorConstruction", result.addPublicTool(result.popToolsAndMerge(G4AtlasDetectorConstructionToolCfg(flags))))
27
28 kwargs.setdefault("InputTruthCollection", "BeamTruthEvent") #tocheck -are these string inputs?
29 kwargs.setdefault("OutputTruthCollection", "TruthEvent")
30
31
32
33 kwargs.setdefault("ReleaseGeoModel", flags.Sim.ReleaseGeoModel)
34
35 from G4AtlasTools.G4AtlasToolsConfig import SimHitContainerListCfg, InputContainerListCfg
36 kwargs.setdefault("ExtraOutputs", SimHitContainerListCfg(flags) )
37 kwargs.setdefault("ExtraInputs" , InputContainerListCfg(flags))
38
39 from SimulationConfig.SimEnums import LArParameterization, InDetParameterization
40 # Configure fast simulation
41 if flags.Sim.LArParameterization is LArParameterization.FastCaloSim:
42 from G4AtlasTools.G4AtlasToolsConfig import PunchThroughG4ToolCfg
43 physics_initialization_tools = kwargs.setdefault("PhysicsInitializationTools", [])
44 physics_initialization_tools.append(result.addPublicTool(result.popToolsAndMerge(PunchThroughG4ToolCfg(flags))))
45 # Set the path to the simplified calorimeter geometry for particle transport if provided
46 if flags.Sim.SimplifiedGeoPath:
47 kwargs.setdefault('SimplifiedGeoPath', flags.Sim.SimplifiedGeoPath)
48
49 if flags.Sim.InDetParameterization is InDetParameterization.FatrasG4:
50 from G4AtlasTools.G4AtlasToolsConfig import ActsFatrasG4ToolCfg
51
52 # Add to physics initialization
53 physics_initialization_tools = kwargs.setdefault("PhysicsInitializationTools", [])
54 physics_initialization_tools.append(result.addPublicTool(result.popToolsAndMerge(ActsFatrasG4ToolCfg(flags))))
55
56 if flags.Sim.InDetParameterization is InDetParameterization.AFatrasG4:
57 from G4AtlasTools.G4AtlasToolsConfig import ActsFatrasG4ToolCfg
58
59 # Add to physics initialization
60 physics_initialization_tools = kwargs.setdefault("PhysicsInitializationTools", [])
61 physics_initialization_tools.append(result.addPublicTool(result.popToolsAndMerge(ActsFatrasG4ToolCfg(flags))))
62
63 # Set the path to the simplified calorimeter geometry for particle transport if provided
64 if flags.Sim.LArParameterization is LArParameterization.FastCaloSim and flags.Sim.SimplifiedGeoPath:
65 kwargs.setdefault("SimplifiedGeoPath", flags.Sim.SimplifiedGeoPath)
66
67
68 kwargs.setdefault("RecordFlux", flags.Sim.RecordFlux)
69
70 if flags.Sim.FlagAbortedEvents:
71
72 kwargs.setdefault("FlagAbortedEvents", flags.Sim.FlagAbortedEvents)
73 if flags.Sim.FlagAbortedEvents and flags.Sim.KillAbortedEvents:
74 print("WARNING When G4AtlasAlg.FlagAbortedEvents is True G4AtlasAlg.KillAbortedEvents should be False. Setting G4AtlasAlg.KillAbortedEvents = False now.")
75 kwargs.setdefault("KillAbortedEvents", False)
76
77
78 kwargs.setdefault("KillAbortedEvents", flags.Sim.KillAbortedEvents)
79
80 from RngComps.RngCompsConfig import AthRNGSvcCfg
81 kwargs.setdefault("AtRndmGenSvc",
82 result.getPrimaryAndMerge(AthRNGSvcCfg(flags)))
83
84 kwargs.setdefault("RandomGenerator", "athena")
85
86 # Multi-threading settinggs
87 is_hive = flags.Concurrency.NumThreads > 0
88 kwargs.setdefault("MultiThreading", is_hive)
89 if is_hive:
90 result.merge(G4ThreadPoolSvcCfg(flags))
91 kwargs.setdefault("Cardinality", flags.Concurrency.NumThreads)
92
93 kwargs.setdefault("TruthRecordService", result.getPrimaryAndMerge(TruthServiceCfg(flags)))
94
95 #input converter
96 kwargs.setdefault("InputConverter", result.getPrimaryAndMerge(InputConverterCfg(flags)))
97 if flags.Sim.ISF.Simulator.isQuasiStable():
98 from BeamEffects.BeamEffectsAlgConfig import ZeroLifetimePositionerCfg
99 kwargs.setdefault("QuasiStablePatcher", result.getPrimaryAndMerge(ZeroLifetimePositionerCfg(flags)) )
100
101 #sensitive detector master tool
102 kwargs.setdefault("SenDetMasterTool", result.addPublicTool(result.popToolsAndMerge(SensitiveDetectorMasterToolCfg(flags))))
103
104 #fast simulation master tool
105 kwargs.setdefault("FastSimMasterTool", result.addPublicTool(result.popToolsAndMerge(FastSimulationMasterToolCfg(flags))))
106
107 #Write MetaData container and make it available to the job
108 result.merge(writeSimulationParametersMetadata(flags))
109 result.merge(readSimulationParameters(flags)) # for FileMetaData creation
110
111 #User action services (Slow...)
112 kwargs.setdefault("UserActionSvc", result.getPrimaryAndMerge(UserActionSvcCfg(flags)))
113
114 #PhysicsListSvc
115 kwargs.setdefault("PhysicsListSvc", result.getPrimaryAndMerge(PhysicsListSvcCfg(flags)))
116
117
121 verbosities=dict(foo="bar")
122 kwargs.setdefault("Verbosities", verbosities)
123 kwargs.setdefault("QuietMode", flags.Exec.QuietMode)
124
125 # Set commands for the G4AtlasAlg
126 kwargs.setdefault("G4Commands", flags.Sim.G4Commands)
127 result.addEventAlgo(CompFactory.G4AtlasAlg(name, **kwargs))
128
129 return result
void print(char *figname, TCanvas *c1)
G4AtlasAlgCfg(flags, name="G4AtlasAlg", **kwargs)