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