ATLAS Offline Software
Loading...
Searching...
No Matches
CommonSimulationSteering.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3# Possible cases:
4# 1) inputEVNTFile (normal)
5# 2) inputEVNT_TRFile (TrackRecords from pre-simulated events,
6# used with TrackRecordGenerator)
7# Three common cases here:
8# 2a) Cosmics simulation
9# 2b) Stopped particle simulation
10# 2c) Cavern background simulation
11# 3) no input file (on-the-fly generation)
12# Common cases
13# 3a) ParticleGun
14# 3b) CosmicGenerator
15# 4) inputHITSFile (re-simulation)
16
17from PyJobTransforms.TransformUtils import executeFromFragment
18from AthenaConfiguration.ComponentFactory import CompFactory
19from AthenaConfiguration.Enums import BeamType, MetadataCategory
20from SimulationConfig.SimEnums import CavernBackground
21
22
24 fragment = flags.Input.SpecialConfiguration.get("preInclude", None)
25 if fragment and fragment != 'NONE':
26 executeFromFragment(fragment, flags) #FIXME assumes only one fragment?
27
28
30 fragment = flags.Input.SpecialConfiguration.get("postInclude", None)
31 if fragment and fragment != 'NONE':
32 executeFromFragment(fragment, flags, cfg) #FIXME assumes only one fragment?
33
34
35def CommonSimulationCfg(flags, log):
36 # Configure main services and input reading (if required)
37 if not flags.Input.Files:
38 # Cases 3a, 3b
39 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
40 cfg = MainEvgenServicesCfg(flags)
41 # Make sure we get xAOD::EventInfo
42 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
43 cfg.merge(EventInfoCnvAlgCfg(flags, name="xAODMaker::EventInfoCnvAlg", disableBeamSpot = True))
44
45 # For Simulation we need to override the RunNumber to pick up
46 # the right conditions. These next two lines are required for
47 # this to work.
48 cfg.getService("EventSelector").FirstLB = flags.Input.LumiBlockNumbers[0]
49 cfg.getService("EventSelector").OverrideRunNumber = True
50 from AthenaKernel.EventIdOverrideConfig import EvtIdModifierSvcCfg
51 cfg.merge(EvtIdModifierSvcCfg(flags))
52 if flags.Beam.Type is BeamType.Cosmics:
53 # Case 3b: Configure the cosmic Generator
54 from CosmicGenerator.CosmicGeneratorConfig import CosmicGeneratorCfg
55 cfg.merge(CosmicGeneratorCfg(flags))
56 else:
57 # Case 3a: Configure ParticleGun
58 fragment = flags.Sim.GenerationConfiguration
59 if fragment and fragment != 'NONE':
60 executeFromFragment(fragment, flags, cfg)
61 log.info("On-the-fly generation using ParticleGun!")
62 else:
63 log.error("No input file or on-the-fly generation configuration provided!")
64 else:
65 # Cases 1, 2a, 2b, 2c, 4
66 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
67 cfg = MainServicesCfg(flags)
68 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
69 cfg.merge(PoolReadCfg(flags))
70 if flags.Sim.ReadTR or flags.Sim.CavernBackground is CavernBackground.Read:
71 # Cases 2a, 2b, 2c
72 from TrackRecordGenerator.TrackRecordGeneratorConfig import Input_TrackRecordGeneratorCfg
73 cfg.merge(Input_TrackRecordGeneratorCfg(flags))
74 if flags.Sim.ISF.ReSimulation:
75 # Case 4
76 if "xAOD::EventInfo#EventInfo" not in flags.Input.TypedCollections:
77 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
78 cfg.merge(EventInfoCnvAlgCfg(flags))
79 else:
80 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoUpdateFromContextAlgCfg
81 cfg.merge(EventInfoUpdateFromContextAlgCfg(flags))
82 from McEventCollectionFilter.McEventCollectionFilterConfig import TruthResetAlgCfg
83 cfg.merge(TruthResetAlgCfg(flags))
84 cfg.addSequence(CompFactory.AthSequencer('SimSequence'), parentName='AthAlgSeq')
85 cfg.addSequence(CompFactory.AthSequencer('CopyHitSequence'), parentName='AthAlgSeq')
86
87 # force CollectionType to be RootCollection to ensure Event Tag reading
88 if flags.Input.Files:
89 evSel = cfg.getService("EventSelector")
90 evSel.CollectionType = "RootCollection"
91
92 if flags.Sim.ISF.ReSimulation:
93 # Case 4
94 from ISF_Algorithms.ISF_AlgorithmsConfig import SimEventFilterCfg, InvertedSimEventFilterCfg, RenameHitCollectionsCfg
95 cfg.merge(SimEventFilterCfg(flags, sequenceName='SimSequence'))
96 cfg.merge(InvertedSimEventFilterCfg(flags, sequenceName='CopyHitSequence'))
97 cfg.merge(RenameHitCollectionsCfg(flags, sequenceName='CopyHitSequence'))
98 else:
99 #Cases 1, 2, 3
100 # add BeamEffectsAlg
101 from BeamEffects.BeamEffectsAlgConfig import BeamEffectsAlgCfg
102 cfg.merge(BeamEffectsAlgCfg(flags))
103 if flags.Input.Files:
104 #Cases 1, 2
105 if "xAOD::EventInfo#EventInfo" not in flags.Input.TypedCollections:
106 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
107 cfg.merge(EventInfoCnvAlgCfg(flags))
108 else:
109 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoUpdateFromContextAlgCfg
110 cfg.merge(EventInfoUpdateFromContextAlgCfg(flags))
111 else:
112 #Case 3: xAOD::EventInfo#EventInfo will have already been created
113 pass
114
115 if flags.Beam.Type is BeamType.TestBeam:
116 from TBDetDescrAlg.TBDetDescrAlgConfig import TBDetDescrLoaderCfg
117 cfg.merge(TBDetDescrLoaderCfg(flags))
118 AcceptAlgNames=[]
119 if flags.Sim.ISFRun:
120 # add the ISF_MainConfig
121 from ISF_Config.ISF_MainConfig import ISF_KernelCfg
122 cfg.merge(ISF_KernelCfg(flags))
123 AcceptAlgNames = ['ISF_Kernel_' + flags.Sim.ISF.Simulator.value]
124 if flags.Sim.ISF.ReSimulation:
125 AcceptAlgNames += ['RenameHitCollections']
126 else:
127 if not flags.Sim.UseG4Workers:
128 AcceptAlgNames = ['G4AtlasAlg']
129 #add the G4AtlasAlg
130 from G4AtlasAlg.G4AtlasAlgConfig import G4AtlasAlgCfg
131 cfg.merge(G4AtlasAlgCfg(flags))
132 else:
133 AcceptAlgNames = ['G4RunAlg']
134 #add the G4AtlasAlg
135 from G4AtlasAlg.G4RunAlgConfig import G4RunAlgCfg
136 cfg.merge(G4RunAlgCfg(flags))
137 from SimulationConfig.SimEnums import LArParameterization
138 if flags.Sim.LArParameterization is LArParameterization.FastCaloSim:
139 cfg.getEventAlgo("ISF_CollectionMerger").InputLArEMBHits.data.sort() # temporary workaround
140 cfg.getEventAlgo("ISF_CollectionMerger").InputLArEMECHits.data.sort() # temporary workaround
141 cfg.getEventAlgo("ISF_CollectionMerger").InputLArFCALHits.data.sort() # temporary workaround
142 cfg.getEventAlgo("ISF_CollectionMerger").InputLArHECHits.data.sort() # temporary workaround
143 cfg.getEventAlgo("ISF_CollectionMerger").InputTileHits.data.sort() # temporary workaround
144 cfg.getEventAlgo("ISF_CollectionMerger").InputMBTSHits.data.sort() # temporary workaround
145
146 from SimulationConfig.SimEnums import CalibrationRun
147 if flags.Sim.CalibrationRun in [CalibrationRun.LAr, CalibrationRun.LArTile, CalibrationRun.LArTileZDC]:
148 from LArG4SD.LArG4SDToolConfig import DeadMaterialCalibrationHitMergerCfg
149 cfg.merge(DeadMaterialCalibrationHitMergerCfg(flags))
150
151 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
152 from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
153
154 if flags.Output.HITSFileName:
155 from SimuJobTransforms.SimOutputConfig import getStreamHITS_ItemList
156 cfg.merge( OutputStreamCfg(flags,"HITS", ItemList=getStreamHITS_ItemList(flags), disableEventTag=False, AcceptAlgs=AcceptAlgNames) )
157 cfg.merge(SetupMetaDataForStreamCfg(flags, "HITS", AcceptAlgs=AcceptAlgNames, createMetadata=[MetadataCategory.IOVMetaData]))
158 if flags.Sim.ISF.ReSimulation:
159 cfg.getEventAlgo(outputStreamName("HITS")).TakeItemsFromInput=False
160
161 if flags.Output.EVNT_TRFileName:
162 from SimuJobTransforms.SimOutputConfig import getStreamEVNT_TR_ItemList
163 cfg.merge( OutputStreamCfg(flags,"EVNT_TR", ItemList=getStreamEVNT_TR_ItemList(flags), disableEventTag=True, AcceptAlgs=AcceptAlgNames) )
164 cfg.merge(SetupMetaDataForStreamCfg(flags, "EVNT_TR", AcceptAlgs=AcceptAlgNames, createMetadata=[MetadataCategory.IOVMetaData]))
165
166 return cfg