ATLAS Offline Software
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 
12 import sys
13 from argparse import ArgumentParser
14 
15 from AthenaCommon.Constants import INFO
16 from AthenaConfiguration.AllConfigFlags import initConfigFlags
17 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
18 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
19 from AthenaConfiguration.ComponentFactory import CompFactory
20 
21 def 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 
65 def 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 
84 def 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 
110 def 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
167 parser = ArgumentParser("ActsGeantFollowing_jobOption_ITk.py")
168 parser.add_argument("--simulate", default=True, action="store_true",
169  help="Run Simulation")
170 parser.add_argument("-V", "--verboseAccumulators", default=False,
171  action="store_true",
172  help="Print full details of the AlgSequence")
173 parser.add_argument("-S", "--verboseStoreGate", default=False,
174  action="store_true",
175  help="Dump the StoreGate(s) each event iteration")
176 parser.add_argument("--maxEvents",default=-1, type=int,
177  help="The number of events to run. 0 skips execution")
178 parser.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")
183 parser.add_argument("--outputhitsfile",default="myHITS.pool.root", type=str,
184  help="The output HITS filename")
185 args = parser.parse_args()
186 
187 # Configure
189 defaultTestFlags(flags, args)
190 flags.lock()
191 
192 # Construct our accumulator to run
193 acc = ITkCfg(flags)
194 kwargs = {}
195 
196 svcName = "ActsGeantFollowerTool"
197 acc.merge(ActsGeantFollowerCfg(flags,svcName,**kwargs))
198 kwargs.update(UserActionSvc=svcName)
199 
200 from G4AtlasAlg.G4AtlasAlgConfig import G4AtlasAlgCfg
201 acc.merge(G4AtlasAlgCfg(flags, "ITkG4AtlasAlg", **kwargs))
202 
203 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
204 from SimuJobTransforms.SimOutputConfig import getStreamHITS_ItemList
205 acc.merge( OutputStreamCfg(flags,"HITS", ItemList=getStreamHITS_ItemList(flags), disableEventTag=True, AcceptAlgs=['ITkG4AtlasAlg']) )
206 
207 # dump pickle
208 with open("ITkTest.pkl", "wb") as f:
209  acc.store(f)
210 
211 # Print and run
212 sys.exit(printAndRun(acc, flags, args))
python.AtlasExtrapolationEngineConfig.AtlasExtrapolationEngineCfg
def AtlasExtrapolationEngineCfg(flags, name='Extrapolation', nameprefix='Atlas')
Definition: AtlasExtrapolationEngineConfig.py:14
ActsGeantFollowing_jobOptions_ITk.ActsGeantFollowerCfg
def ActsGeantFollowerCfg(flags, name="ActsGeantFollowerTool", **kwargs)
Definition: ActsGeantFollowing_jobOptions_ITk.py:110
ActsGeometryConfig.ActsTrackingGeometrySvcCfg
ComponentAccumulator ActsTrackingGeometrySvcCfg(flags, str name="ActsTrackingGeometrySvc", **kwargs)
Definition: ActsGeometryConfig.py:6
G4AtlasAlgConfig.G4AtlasAlgCfg
def G4AtlasAlgCfg(flags, name="G4AtlasAlg", **kwargs)
Definition: G4AtlasAlgConfig.py:12
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
BeamPipeGMConfig.BeamPipeGeometryCfg
def BeamPipeGeometryCfg(flags)
Definition: BeamPipeGMConfig.py:5
ActsGeantFollowing_jobOptions_ITk.printAndRun
def printAndRun(accessor, flags, args)
Definition: ActsGeantFollowing_jobOptions_ITk.py:65
python.AtlasTrackingGeometrySvcConfig.TrackingGeometrySvcCfg
def TrackingGeometrySvcCfg(flags, name='AtlasTrackingGeometrySvc', doMaterialValidation=False, **kwargs)
Definition: AtlasTrackingGeometrySvcConfig.py:7
BeamEffectsAlgConfig.BeamEffectsAlgCfg
def BeamEffectsAlgCfg(flags, name="BeamEffectsAlg", **kwargs)
Definition: BeamEffectsAlgConfig.py:101
ActsGeantFollowingConfig.ActsGeantFollowerToolCfg
ComponentAccumulator ActsGeantFollowerToolCfg(flags, str name="ActsGeantFollowerTool", **kwargs)
Definition: ActsGeantFollowingConfig.py:5
ActsGeometryConfig.ActsExtrapolationToolCfg
ComponentAccumulator ActsExtrapolationToolCfg(flags, str name="ActsExtrapolationTool", **kwargs)
Definition: ActsGeometryConfig.py:109
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
ActsGeantFollowing_jobOptions_ITk.defaultTestFlags
def defaultTestFlags(flags, args)
Definition: ActsGeantFollowing_jobOptions_ITk.py:21
python.DetectorConfigFlags.setupDetectorFlags
def setupDetectorFlags(flags, custom_list=None, use_metadata=False, toggle_geometry=False, validate_only=False, keep_beampipe=False)
Definition: DetectorConfigFlags.py:289
ITkPixelGeoModelConfig.ITkPixelReadoutGeometryCfg
def ITkPixelReadoutGeometryCfg(flags, setGeometryAlignable=False, setAlignmentFolderName="/Indet/Align")
Definition: ITkPixelGeoModelConfig.py:39
Trk::open
@ open
Definition: BinningType.h:40
ITkStripGeoModelConfig.ITkStripReadoutGeometryCfg
def ITkStripReadoutGeometryCfg(flags, setGeometryAlignable=False, setAlignmentFolderName="/Indet/Align")
Definition: ITkStripGeoModelConfig.py:39
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
G4AtlasUserActionConfig.getDefaultActions
def getDefaultActions(flags)
Definition: G4AtlasUserActionConfig.py:106
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
python.FilterHit_Skeleton.getStreamHITS_ItemList
def getStreamHITS_ItemList(flags)
Definition: FilterHit_Skeleton.py:12
python.GeoModelConfig.GeoModelCfg
def GeoModelCfg(flags)
Definition: GeoModelConfig.py:16
ActsGeantFollowing_jobOptions_ITk.ITkCfg
def ITkCfg(flags)
Definition: ActsGeantFollowing_jobOptions_ITk.py:84