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 readVtxPosFromFile = flags.Sim.VertexSource
in [VertexSource.VertexOverrideFile, VertexSource.VertexOverrideEventFile]
47 if readVtxPosFromFile:
49 elif flags.Sim.VertexSource
is VertexSource.CondDB:
51 elif flags.Sim.VertexSource
is VertexSource.LongBeamspotVertexPositioner:
54 acc.setPrivateTools(CompFactory.Simulation.GenEventVertexPositioner(name, **kwargs))
60 """Return a conditional (? todo) vertex positioner tool"""
61 from RngComps.RngCompsConfig
import AthRNGSvcCfg
65 kwargs.setdefault(
"RandomSvc", acc.getPrimaryAndMerge(
AthRNGSvcCfg(flags)).name)
66 kwargs.setdefault(
"SimpleTimeSmearing", flags.Sim.VertexTimeSmearing)
67 kwargs.setdefault(
"TimeWidth", flags.Sim.VertexTimeWidth)
69 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
72 acc.setPrivateTools(CompFactory.Simulation.VertexBeamCondPositioner(name, **kwargs))
77 """Return a vertex positioner tool"""
80 acc.setPrivateTools(CompFactory.Simulation.VertexPositionFromFile(name, **kwargs))
85 """Return a Crab-Kissing vertex positioner tool"""
88 acc.setPrivateTools(CompFactory.Simulation.CrabKissingVertexPositioner(name, **kwargs))
93 """Return a long beamspot vertex positioner tool"""
96 kwargs.setdefault(
"SimpleTimeSmearing", flags.Sim.VertexTimeSmearing)
97 acc.setPrivateTools(CompFactory.Simulation.LongBeamspotVertexPositioner(name, **kwargs))
102 """Return an accumulator and algorithm for beam effects, wihout output"""
105 from SimulationConfig.SimEnums
import LArParameterization
106 if flags.Sim.LArParameterization
is LArParameterization.FastCaloSim:
107 kwargs.setdefault(
"ISFRun",
True)
109 kwargs.setdefault(
"ISFRun", flags.Sim.ISFRun)
112 if flags.Sim.DoFullChain
and flags.Digitization.PileUp:
113 kwargs.setdefault(
"InputMcEventCollection",
"OriginalEvent_SG+GEN_EVENT")
115 kwargs.setdefault(
"InputMcEventCollection",
"GEN_EVENT")
117 if flags.Common.isOverlay
and flags.Sim.DoFullChain:
118 kwargs.setdefault(
'OutputMcEventCollection', f
"{flags.Overlay.SigPrefix}TruthEvent")
120 kwargs.setdefault(
'OutputMcEventCollection',
'BeamTruthEvent')
125 from SimulationConfig.SimEnums
import VertexSource
126 if not flags.Sim.VertexSource == VertexSource.AsGenerated:
128 from SimulationConfig.SimEnums
import CavernBackground
129 if flags.Beam.Type
not in [BeamType.Cosmics, BeamType.TestBeam]
and flags.Sim.CavernBackground
is not CavernBackground.Read:
135 kwargs.setdefault(
"GenEventManipulators", manipulators)
137 acc.addEventAlgo(CompFactory.Simulation.BeamEffectsAlg(name, **kwargs), primary=
True)
142 """Return an accumulator and algorithm for beam effects, with output"""
145 alg = acc.getPrimary()
146 ItemList = [
"McEventCollection#" + alg.OutputMcEventCollection]
147 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
148 acc.merge(
OutputStreamCfg(flags,
"HITS", ItemList=ItemList, disableEventTag=
True))
153 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
156 kwargs.setdefault(
"InputKey",
"Input_EventInfo")
157 if flags.Common.ProductionStep == ProductionStep.PileUpPresampling:
158 kwargs.setdefault(
"OutputKey", flags.Overlay.BkgPrefix +
"EventInfo")
160 kwargs.setdefault(
"OutputKey",
"EventInfo")
162 acc.addEventAlgo(CompFactory.Simulation.BeamSpotFixerAlg(name, **kwargs))
168 kwargs.setdefault(
'ApplyPatch',
True)
169 kwargs.setdefault(
'RemovePatch',
True)
170 result.addService(CompFactory.Simulation.ZeroLifetimePositioner(name, **kwargs), primary =
True)
175 from BeamSpotConditions.BeamSpotConditionsConfig
import BeamSpotCondAlgCfg
178 kwargs.setdefault(
"Input_beam_sigma_z", flags.Digitization.InputBeamSigmaZ)
180 acc.addEventAlgo(CompFactory.Simulation.BeamSpotReweightingAlg(name, **kwargs))
183 from AthenaConfiguration.MainServicesConfig
import OutputUsageIgnoreCfg
189 if __name__ ==
"__main__":
190 from AthenaCommon.Logging
import log
192 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
193 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
195 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
196 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
203 inputDir = os.environ.get(
"ATLAS_REFERENCE_DATA",
204 "/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art")
206 flags.Input.Files = [
208 "/SimCoreTests/e_E50_eta34_49.EVNT.pool.root"
212 flags.Output.HITSFileName =
"myHITS.pool.root"
215 from SimulationConfig.SimEnums
import VertexSource
217 flags.Sim.VertexSource = VertexSource.CondDB
221 flags.Input.isMC =
True
222 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
223 flags.IOVDb.GlobalTag =
"OFLCOND-MC16-SDR-14"
224 flags.Input.RunNumbers = [284500]
237 cfg.getService(
"StoreGateSvc").Dump =
True
238 cfg.printConfig(withDetails=
True)
242 with open(
"BeamEffectsAlg.pkl",
"wb")
as f:
246 cfg.run(maxEvents=20)