ATLAS Offline Software
Loading...
Searching...
No Matches
ActsGeantFollowing_jobOptions_ITk.py
Go to the documentation of this file.
1# Copyright (C) 2002-2023 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# It can be run using athena.py
8#
9#==============================================================
10
11
12import sys
13from argparse import ArgumentParser
14
15from AthenaCommon.Constants import INFO
16from AthenaConfiguration.AllConfigFlags import initConfigFlags
17from AthenaConfiguration.MainServicesConfig import MainServicesCfg
18from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
19from AthenaConfiguration.ComponentFactory import CompFactory
20
21def defaultTestFlags(flags, args):
22
23
24
25 flags.Input.isMC = True
26 flags.ITk.Geometry.AllLocal = True
27 detectors = [
28 "ITkPixel",
29 "ITkStrip",
30 "Bpipe"
31 ]
32
33 from AthenaConfiguration.DetectorConfigFlags import setupDetectorFlags
34 setupDetectorFlags(flags, detectors, toggle_geometry=True)
35
36 from AthenaConfiguration.TestDefaults import defaultGeometryTags
37 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
38 flags.IOVDb.GlobalTag = "OFLCOND-SIM-00-00-00"
39 flags.GeoModel.Align.Dynamic = False
40 # flags.Acts.TrackingGeometry.MaterialSource = "Input"
41 # flags.Acts.TrackingGeometry.MaterialSource = "material-maps.json"
42
43 flags.Detector.GeometryCalo = False
44 flags.Detector.GeometryMuon = False
45
46 # # This should run serially for the moment.
47 # flags.Concurrency.NumThreads = 1
48 flags.Concurrency.NumConcurrentEvents = 1
49
50 flags.Input.Files = [args.inputevntfile]
51
52 flags.Output.HITSFileName = args.outputhitsfile
53
54 from SimulationConfig.SimEnums import BeamPipeSimMode, CalibrationRun, CavernBackground
55 flags.Sim.CalibrationRun = CalibrationRun.Off
56 flags.Sim.RecordStepInfo = False
57 flags.Sim.CavernBackground = CavernBackground.Signal
58 flags.Sim.ISFRun = False
59 flags.Sim.BeamPipeSimMode = BeamPipeSimMode.FastSim
60
61 flags.Input.RunNumbers = [284500]
62 flags.Input.OverrideRunNumber = True
63 flags.Input.LumiBlockNumbers = [1]
64
65def printAndRun(accessor, flags, args):
66 """debugging and execution"""
67 # Dump config
68 if args.verboseAccumulators:
69 accessor.printConfig(withDetails=True)
70 if args.verboseStoreGate:
71 accessor.getService("StoreGateSvc").Dump = True
72 flags.dump()
73
74 # Execute and finish
75 sc = accessor.run(maxEvents=args.maxEvents)
76
77 # Dump config summary
78 accessor.printConfig(withDetails=False)
79
80 # Success should be 0
81 return not sc.isSuccess()
82
83
84def ITkCfg(flags):
85 acc = MainServicesCfg(flags)
86 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
87 acc.merge(PoolReadCfg(flags))
88
89 # add BeamEffectsAlg
90 from BeamEffects.BeamEffectsAlgConfig import BeamEffectsAlgCfg
91 acc.merge(BeamEffectsAlgCfg(flags))
92
93 from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
94 itkPixel = ITkPixelReadoutGeometryCfg(flags)
95 acc.merge(itkPixel)
96
97 from StripGeoModelXml.ITkStripGeoModelConfig import ITkStripReadoutGeometryCfg
98 itkStrip = ITkStripReadoutGeometryCfg(flags)
99 acc.merge(itkStrip)
100
101 from BeamPipeGeoModel.BeamPipeGMConfig import BeamPipeGeometryCfg
102 acc.merge(BeamPipeGeometryCfg(flags))
103
104 from AtlasGeoModel.GeoModelConfig import GeoModelCfg
105 gmsAcc = GeoModelCfg(flags)
106 acc.merge(gmsAcc)
107
108 return acc
109
110def ActsGeantFollowerCfg(flags, name="ActsGeantFollowerTool", **kwargs):
111
112 result = ComponentAccumulator()
113
114 from TrkConfig.AtlasTrackingGeometrySvcConfig import TrackingGeometrySvcCfg
115 result.merge(TrackingGeometrySvcCfg(flags))
116
117 from ActsConfig.ActsGeometryConfig import NominalAlignmentCondAlgCfg
118 nomAli = NominalAlignmentCondAlgCfg(flags, OutputLevel=INFO)
119 result.merge(nomAli)
120
121 from ActsConfig.ActsGeometryConfig import ActsTrackingGeometrySvcCfg
122 tgSvc = ActsTrackingGeometrySvcCfg(flags, OutputLevel=INFO)
123 result.merge(tgSvc)
124
125 print('DEF WRITER : ')
126 from ActsConfig.ActsGeometryConfig import ActsExtrapolationToolCfg
127 Actsextrapol = result.popToolsAndMerge(ActsExtrapolationToolCfg(flags,
128 InteractionMultiScatering = True,
129 InteractionEloss = True,
130 InteractionRecord=True,
131 OutputLevel=INFO))
132 result.addPublicTool(Actsextrapol)
133
134 from TrkConfig.AtlasExtrapolationEngineConfig import AtlasExtrapolationEngineCfg
135 AtlasExtrapolationEngine = result.getPrimaryAndMerge(AtlasExtrapolationEngineCfg(flags))
136
137
138 #Setup Helper
139 followingHelper = CompFactory.ActsGeantFollowerHelper("ActsGeantFollowerHelper",
140 **kwargs,
141 ExtrapolationEngine=AtlasExtrapolationEngine,
142 ActsExtrapolator=result.getPublicTool(Actsextrapol.name), # PublicToolHandle
143 ExtrapolateDirectly=False,
144 ExtrapolateIncrementally=True,
145 OutputLevel=INFO)
146 result.addPublicTool(followingHelper)
147
148 #Setting up the CA for the ActsGeantFollower
149 from ActsConfig.ActsGeantFollowingConfig import ActsGeantFollowerToolCfg
150 ActsGeantFollowerAction = result.popToolsAndMerge(ActsGeantFollowerToolCfg(flags))
151
152 #Retrieving the default action list
153 from G4AtlasServices.G4AtlasUserActionConfig import getDefaultActions
154 defaultActions = result.popToolsAndMerge(getDefaultActions(flags))
155
156 #Adding LengthIntegrator to defaults
157 actionList = (defaultActions + ActsGeantFollowerAction)
158
159 #Setting up UserActionsService
160 kwargs.setdefault("UserActionTools",actionList)
161 result.addService(CompFactory.G4UA.UserActionSvc(name, **kwargs))
162
163 return result
164
165
166# Argument parsing
167parser = ArgumentParser("ActsGeantFollowing_jobOption_ITk.py")
168parser.add_argument("--simulate", default=True, action="store_true",
169 help="Run Simulation")
170parser.add_argument("-V", "--verboseAccumulators", default=False,
171 action="store_true",
172 help="Print full details of the AlgSequence")
173parser.add_argument("-S", "--verboseStoreGate", default=False,
174 action="store_true",
175 help="Dump the StoreGate(s) each event iteration")
176parser.add_argument("--maxEvents",default=-1, type=int,
177 help="The number of events to run. 0 skips execution")
178parser.add_argument("--inputevntfile",
179 # default="/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/SimCoreTests/e_E50_eta0-25.evgen.pool.root",
180 default="/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/InDetSLHC_Example/inputs/pgun_2M_10GeV_geantinos_Eta6_v2_EVNT.root",
181 # default="/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/InDetSLHC_Example/inputs/EVNT.09244569._000001.pool.root.1",
182 help="The input EVNT file to use")
183parser.add_argument("--outputhitsfile",default="myHITS.pool.root", type=str,
184 help="The output HITS filename")
185args = parser.parse_args()
186
187# Configure
188flags = initConfigFlags()
189defaultTestFlags(flags, args)
190flags.lock()
191
192# Construct our accumulator to run
193acc = ITkCfg(flags)
194kwargs = {}
195
196svcName = "ActsGeantFollowerTool"
197acc.merge(ActsGeantFollowerCfg(flags,svcName,**kwargs))
198kwargs.update(UserActionSvc=svcName)
199
200from G4AtlasAlg.G4AtlasAlgConfig import G4AtlasAlgCfg
201acc.merge(G4AtlasAlgCfg(flags, "ITkG4AtlasAlg", **kwargs))
202
203from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
204from SimuJobTransforms.SimOutputConfig import getStreamHITS_ItemList
205acc.merge( OutputStreamCfg(flags,"HITS", ItemList=getStreamHITS_ItemList(flags), disableEventTag=True, AcceptAlgs=['ITkG4AtlasAlg']) )
206
207# dump pickle
208with open("ITkTest.pkl", "wb") as f:
209 acc.store(f)
210
211# Print and run
212sys.exit(printAndRun(acc, flags, args))
void print(char *figname, TCanvas *c1)
ActsGeantFollowerCfg(flags, name="ActsGeantFollowerTool", **kwargs)