ATLAS Offline Software
Loading...
Searching...
No Matches
Geant4MSFollowing.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2#==============================================================
3#
4#
5# This job option runs the G4 simulation
6# of the ATLAS detector and the GeantFollower in ID (and MS)
7#
8#==============================================================
9
10from AthenaCommon.Constants import INFO
11
12from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
13from AthenaConfiguration.ComponentFactory import CompFactory
14
15
16# Argument parsing
18 from argparse import ArgumentParser
19 parser = ArgumentParser()
20 parser.add_argument("--inputEVNTFile",
21 default="/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/MuonRecRTT/EVGEN_ParticleGun_FourMuon_Pt10to500.root",
22 type=str,
23 help="The input EVNT file to use")
24 parser.add_argument("--outputHITSFile",
25 default="myHITS.pool.root",
26 type=str,
27 help="The output HITS filename")
28 parser.add_argument("--geometryTag",
29 default="ATLAS-R3S-2021-03-02-00",
30 type=str,
31 help="The geometry tag to use")
32 parser.add_argument("--globalTag",
33 default="OFLCOND-MC21-SDR-RUN3-09",
34 type=str,
35 help="The global tag to use")
36 parser.add_argument("--myPDG",
37 default=998,
38 type=int,
39 help="PDG for particle gun sim. 998 = Charged Geantino 999 = neutral Geantino, 13 = Muon")
40 parser.add_argument("--maxEvents",
41 default=10000,
42 type = int,
43 help="Maximum number of events to run on.")
44 parser.add_argument("--skipEvents", help="Number of events to skip", type = int , default =0)
45
46 return parser
47
48
49def MSCfg(flags):
50 # Setup main services
51 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
52 acc = MainServicesCfg(flags)
53 acc.getService("MessageSvc").debugLimit = 1000000
54
55 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
56 acc.merge(PoolReadCfg(flags))
57
58 from BeamSpotConditions.BeamSpotConditionsConfig import BeamSpotCondAlgCfg
59 acc.merge(BeamSpotCondAlgCfg(flags))
60
61 from BeamEffects.BeamEffectsAlgConfig import BeamEffectsAlgCfg
62 acc.merge(BeamEffectsAlgCfg(flags))
63
64 from BeamPipeGeoModel.BeamPipeGMConfig import BeamPipeGeometryCfg
65 acc.merge(BeamPipeGeometryCfg(flags))
66
67 from TrackingGeometryCondAlg.AtlasTrackingGeometryCondAlgConfig import TrackingGeometryCondAlgCfg
68 acc.merge(TrackingGeometryCondAlgCfg(flags))
69
70 from TrkConfig.AtlasTrackingGeometrySvcConfig import TrackingGeometrySvcCfg
71 acc.merge(TrackingGeometrySvcCfg(flags))
72
73 return acc
74
75def ExtrapolationToolCfg(flags, args):
76
77 acc = ComponentAccumulator()
78
79 # the layer material inspector
80 LayerMaterialInspector = CompFactory.Trk.LayerMaterialInspector("LayerMaterialInspector",
81 OutputLevel=INFO)
82 acc.addPublicTool(LayerMaterialInspector)
83
84 # the tracking volume displayer
85 TrackingVolumeDisplayer = CompFactory.Trk.TrackingVolumeDisplayer("TrackingVolumeDisplayer",
86 TrackingVolumeOutputFile='TrackingVolumes.C',
87 LayerOutputFile='Layers.C',
88 SurfaceOutputFile='Surfaces.C')
89 acc.addPublicTool(TrackingVolumeDisplayer)
90
91 # PROPAGATOR DEFAULTS
92 TestPropagators = []
93 TestPropagator = CompFactory.Trk.RungeKuttaPropagator("TestPropagator")
94 acc.addPublicTool(TestPropagator)
95 TestPropagators += [TestPropagator]
96
97 from TrkConfig.TrkExSTEP_PropagatorConfig import AtlasSTEP_PropagatorCfg
98 TestSTEP_Propagator = acc.popToolsAndMerge(AtlasSTEP_PropagatorCfg(flags, name="TestSTEP_Propagator", DetailedEloss=True))
99 TestPropagators += [TestSTEP_Propagator]
100
101 TestSTEP_Propagator.Straggling = False
102
103 if args.myPDG == 998 :
104 TestSTEP_Propagator.MultipleScattering = False
105 TestSTEP_Propagator.EnergyLoss = False
106
107 # UPDATOR DEFAULTS
108 TestUpdators = []
109
110 TestMaterialEffectsUpdator = CompFactory.Trk.MaterialEffectsUpdator("TestMaterialEffectsUpdator")
111 acc.addPublicTool(TestMaterialEffectsUpdator)
112 if args.myPDG == 998 :
113 TestMaterialEffectsUpdator.EnergyLoss = False
114 TestMaterialEffectsUpdator.MultipleScattering = False
115
116 TestUpdators += [TestMaterialEffectsUpdator]
117
118 TestMaterialEffectsUpdatorLandau = CompFactory.Trk.MaterialEffectsUpdator("TestMaterialEffectsUpdatorLandau",
119 LandauMode=True)
120 acc.addPublicTool(TestMaterialEffectsUpdatorLandau)
121
122 if args.myPDG == 998 :
123 TestMaterialEffectsUpdatorLandau.EnergyLoss = False
124 TestMaterialEffectsUpdatorLandau.MultipleScattering = False
125
126
127
128 # the UNIQUE NAVIGATOR ( === UNIQUE GEOMETRY)
129 TestNavigator = CompFactory.Trk.Navigator("TestNavigator",
130 TrackingGeometrySvc="Trk::TrackingGeometrySvc/AtlasTrackingGeometrySvc")
131 acc.addPublicTool(TestNavigator)
132
133 # CONFIGURE PROPAGATORS/UPDATORS ACCORDING TO GEOMETRY SIGNATURE
134
135 TestSubPropagators = []
136 TestSubUpdators = []
137
138 # -------------------- set it depending on the geometry ----------------------------------------------------
139 # default for Global is (Rk,Mat)
140 TestSubPropagators += [ TestPropagator.name ]
141 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
142
143 # default for ID is (Rk,Mat)
144 TestSubPropagators += [ TestPropagator.name ]
145 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
146
147 # default for Beam pipe is (Rk,Mat) // sometimes the STEP is used
148 TestSubPropagators += [ TestPropagator.name ]
149 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
150
151 # default for Calo is (STEP,Mat) // sometimes MatLandau is used
152 TestSubPropagators += [ TestSTEP_Propagator.name ]
153 #TestSubPropagators += [ TestPropagator.name ] #Switch to RK
154 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
155
156 # default for MS is (STEP,Mat)
157 TestSubPropagators += [ TestSTEP_Propagator.name ]
158 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
159
160 # default for Cavern is (Rk,Mat)
161 TestSubPropagators += [ TestPropagator.name ]
162 TestSubUpdators += [ TestMaterialEffectsUpdator.name ]
163 # ----------------------------------------------------------------------------------------------------------
164
165 AtlasEnergyLossUpdator = CompFactory.Trk.EnergyLossUpdator("AtlasEnergyLossUpdator",
166 DetailedEloss=True)
167 acc.addPublicTool(AtlasEnergyLossUpdator)
168
169 # AtlasELossUpdater = acc.popToolsAndMerge(TC.AtlasEnergyLossUpdatorCfg(flags))
170 # AtlasEnergyLossUpdater = AtlasELossUpdater
171
172 # from TrkConfig.AtlasExtrapolatorToolsConfig as TC
173 # AtlasEnergyLossUpdator = acc.popToolsAndMerge(AtlasEnergyLossUpdatorCfg(flags, name="AtlasEnergyLossUpdator", DetailedEloss=True) )
174
175 # call the base class constructor
176 TestExtrapolator = CompFactory.Trk.Extrapolator("TestExtrapolator",
177 Navigator = TestNavigator,
178 MaterialEffectsUpdators = TestUpdators,
179 STEP_Propagator = TestSTEP_Propagator.name,
180 Propagators = TestPropagators,
181 SubPropagators = TestSubPropagators,
182 SubMEUpdators = TestSubUpdators,
183 EnergyLossUpdater = AtlasEnergyLossUpdator
184 )
185 acc.addPublicTool(TestExtrapolator, primary=True)
186 # acc.setPrivateTools(TestExtrapolator)
187
188 return acc
189
190
191def GeantFollowerMSCfg(flags, args, name="GeantFollowerMSSvc", **kwargs):
192
193 result = ComponentAccumulator()
194# from TrkConfig.AtlasExtrapolatorConfig import MuonExtrapolatorCfg
195# extrapolator = result.getPrimaryAndMerge(MuonExtrapolatorCfg(flags))
196 extrapolator = result.getPrimaryAndMerge(ExtrapolationToolCfg(flags,args))
197 result.addPublicTool(extrapolator)
198
199 #Setup Helper
200 followingHelper = CompFactory.Trk.GeantFollowerMSHelper("GeantFollowerMSHelper",
201 Extrapolator= extrapolator,
202 ExtrapolateDirectly=False,
203 ExtrapolateIncrementally=False,
204 SpeedUp=True,
205 UseCovMatrix=True,
206 OutputLevel=INFO)
207 result.addPublicTool(followingHelper, primary = True)
208
209 #Setting up the CA for the GeantFollowerMS
210 from G4AtlasServices.G4AtlasUserActionConfig import getDefaultActions
211 kwargs.setdefault("UserActionTools", result.popToolsAndMerge(getDefaultActions(flags)))
212 result.addService(CompFactory.G4UA.UserActionSvc(name, **kwargs))
213 return result
214
215
216if __name__ =="__main__":
217 from AthenaConfiguration.AllConfigFlags import initConfigFlags
218
219 args = setupArgParser().parse_args()
220 # Configure
221 flags = initConfigFlags()
222 flags.Input.Files = [args.inputEVNTFile]
223 flags.Output.HITSFileName = args.outputHITSFile
224 flags.GeoModel.AtlasVersion = args.geometryTag
225 flags.IOVDb.GlobalTag = args.globalTag
226 flags.Input.isMC = True
227 flags.GeoModel.Align.Dynamic = False
228 flags.Concurrency.NumThreads =1
229 flags.Concurrency.NumConcurrentEvents = 1
230 flags.Exec.SkipEvents = args.skipEvents
231 from AthenaConfiguration.Enums import ProductionStep
232 flags.Common.ProductionStep = ProductionStep.FastChain
233 flags.LAr.doAlign = True
234 flags.Sim.TightMuonStepping = True
235
236 # Setup detector
237 from AthenaConfiguration.DetectorConfigFlags import setupDetectorsFromList
238 detectors = ["Muon","ID","Bpipe", "Calo"]
239 setupDetectorsFromList(flags, detectors, toggle_geometry=True)
240
241 flags.lock()
242 flags.dump(evaluate = True)
243
244 # Construct component accumulator
245 acc = MSCfg(flags)
246 acc.merge(GeantFollowerMSCfg(flags,args))
247
248 #DEV#
249 #Setting up the CA for the GeantFollowerMS
250 from TrkG4UserActions.TrkG4UserActionsConfig import GeantFollowerMSToolCfg
251 GeantFollowerMSTool = acc.getPrimaryAndMerge(GeantFollowerMSToolCfg(flags))
252 #DEV#
253
254 from G4AtlasAlg.G4AtlasAlgConfig import G4AtlasAlgCfg
255 acc.merge(G4AtlasAlgCfg(flags,UserActionTools=[GeantFollowerMSTool],
256 ExtraInputs={( 'Trk::TrackingGeometry' , 'ConditionStore+AtlasTrackingGeometry'),
257 ( 'AtlasFieldCacheCondObj' , 'ConditionStore+fieldCondObj' )}))
258
259 # Execute
260 acc.printConfig(withDetails=True)
261 if not acc.run(maxEvents=args.maxEvents).isSuccess():
262 exit(1)
GeantFollowerMSCfg(flags, args, name="GeantFollowerMSSvc", **kwargs)