5 """Define methods to configure beam effects with the ComponentAccumulator"""
6 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
7 from AthenaConfiguration.ComponentFactory
import CompFactory
8 from AthenaConfiguration.Enums
import BeamType, ProductionStep
18 """Return a validity checker tool"""
20 acc.setPrivateTools(CompFactory.Simulation.GenEventValidityChecker(name, **kwargs))
25 """Return a event rotator tool"""
27 acc.setPrivateTools(CompFactory.Simulation.GenEventRotator(name, **kwargs))
32 """Return a lorentz booster tool"""
35 acc.setPrivateTools(CompFactory.Simulation.GenEventBeamEffectBooster(name, **kwargs))
40 """Return a vertex positioner tool"""
45 from SimulationConfig.SimEnums
import VertexSource
46 if flags.Sim.VertexSource
is VertexSource.MatchingBkg:
48 elif flags.Sim.VertexSource
is VertexSource.CondDB:
50 elif flags.Sim.VertexSource
is VertexSource.LongBeamspotVertexPositioner:
53 acc.setPrivateTools(CompFactory.Simulation.GenEventVertexPositioner(name, **kwargs))
59 """Return a conditional (? todo) vertex positioner tool"""
60 from RngComps.RngCompsConfig
import AthRNGSvcCfg
64 kwargs.setdefault(
"RandomSvc", acc.getPrimaryAndMerge(
AthRNGSvcCfg(flags)).name)
65 kwargs.setdefault(
"SimpleTimeSmearing", flags.Sim.VertexTimeSmearing)
66 kwargs.setdefault(
"TimeWidth", flags.Sim.VertexTimeWidth)
68 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
71 acc.setPrivateTools(CompFactory.Simulation.VertexBeamCondPositioner(name, **kwargs))
76 """Return a vertex positioner tool that reads a matching vertex from the background input file."""
79 if flags.Overlay.DataOverlay:
80 kwargs.setdefault(
"PrimaryVertexContainerName", f
"{flags.Overlay.BkgPrefix}PrimaryVertices")
82 from SGComps.SGInputLoaderConfig
import SGInputLoaderCfg
83 acc.merge(
SGInputLoaderCfg(flags, [f
'xAOD::VertexContainer#{kwargs["PrimaryVertexContainerName"]}']))
85 acc.setPrivateTools(CompFactory.Simulation.MatchingBkgVertexPositioner(name, **kwargs))
90 """Return a Crab-Kissing vertex positioner tool"""
93 acc.setPrivateTools(CompFactory.Simulation.CrabKissingVertexPositioner(name, **kwargs))
98 """Return a long beamspot vertex positioner tool"""
101 kwargs.setdefault(
"SimpleTimeSmearing", flags.Sim.VertexTimeSmearing)
102 acc.setPrivateTools(CompFactory.Simulation.LongBeamspotVertexPositioner(name, **kwargs))
107 """Return an accumulator and algorithm for beam effects, wihout output"""
110 from SimulationConfig.SimEnums
import LArParameterization
111 if flags.Sim.LArParameterization
is LArParameterization.FastCaloSim:
112 kwargs.setdefault(
"ISFRun",
True)
114 kwargs.setdefault(
"ISFRun", flags.Sim.ISFRun)
117 if flags.Sim.DoFullChain
and flags.Digitization.PileUp:
118 kwargs.setdefault(
"InputMcEventCollection",
"OriginalEvent_SG+GEN_EVENT")
120 kwargs.setdefault(
"InputMcEventCollection",
"GEN_EVENT")
122 if flags.Sim.DoFullChain
and flags.Common.isOverlay
and not flags.Overlay.DataOverlay:
123 kwargs.setdefault(
'OutputMcEventCollection', f
"{flags.Overlay.SigPrefix}TruthEvent")
125 kwargs.setdefault(
'OutputMcEventCollection',
'BeamTruthEvent')
130 from SimulationConfig.SimEnums
import VertexSource
131 if not flags.Sim.VertexSource == VertexSource.AsGenerated:
133 from SimulationConfig.SimEnums
import CavernBackground
134 if flags.Beam.Type
not in [BeamType.Cosmics, BeamType.TestBeam]
and flags.Sim.CavernBackground
is not CavernBackground.Read:
138 kwargs.setdefault(
"GenEventManipulators", manipulators)
140 acc.addEventAlgo(CompFactory.Simulation.BeamEffectsAlg(name, **kwargs), primary=
True)
145 """Return an accumulator and algorithm for beam effects, with output"""
148 alg = acc.getPrimary()
149 ItemList = [
"McEventCollection#" + alg.OutputMcEventCollection]
150 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
151 acc.merge(
OutputStreamCfg(flags,
"HITS", ItemList=ItemList, disableEventTag=
True))
156 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
159 kwargs.setdefault(
"InputKey",
"Input_EventInfo")
160 if flags.Common.ProductionStep == ProductionStep.PileUpPresampling:
161 kwargs.setdefault(
"OutputKey", flags.Overlay.BkgPrefix +
"EventInfo")
163 kwargs.setdefault(
"OutputKey",
"EventInfo")
165 acc.addEventAlgo(CompFactory.Simulation.BeamSpotFixerAlg(name, **kwargs))
171 kwargs.setdefault(
'ApplyPatch',
True)
172 kwargs.setdefault(
'RemovePatch',
True)
173 result.addService(CompFactory.Simulation.ZeroLifetimePositioner(name, **kwargs), primary =
True)
178 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
181 kwargs.setdefault(
"Input_beam_sigma_z", flags.Digitization.InputBeamSigmaZ)
183 acc.addEventAlgo(CompFactory.Simulation.BeamSpotReweightingAlg(name, **kwargs))
186 from AthenaConfiguration.MainServicesConfig
import OutputUsageIgnoreCfg
192 if __name__ ==
"__main__":
193 from AthenaCommon.Logging
import log
195 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
196 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
198 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
199 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
206 inputDir = os.environ.get(
"ATLAS_REFERENCE_DATA",
207 "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art")
209 flags.Input.Files = [
211 "/SimCoreTests/e_E50_eta34_49.EVNT.pool.root"
215 flags.Output.HITSFileName =
"myHITS.pool.root"
218 from SimulationConfig.SimEnums
import VertexSource
220 flags.Sim.VertexSource = VertexSource.CondDB
224 flags.Input.isMC =
True
225 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
226 flags.IOVDb.GlobalTag =
"OFLCOND-MC16-SDR-14"
227 flags.Input.RunNumbers = [284500]
240 cfg.getService(
"StoreGateSvc").Dump =
True
241 cfg.printConfig(withDetails=
True)
245 with open(
"BeamEffectsAlg.pkl",
"wb")
as f:
249 cfg.run(maxEvents=20)