1 """ComponentAccumulator configuration for MT pileup digitization
3 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
6 from AthenaConfiguration.ComponentFactory
import CompFactory
7 from AthenaConfiguration.Enums
import ProductionStep
8 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
9 from SGComps.AddressRemappingConfig
import InputRenameCfg
10 from DigitizationConfig.RunDependentConfig
import (
15 from DigitizationConfig.PileUpConfig
import (
16 LowPtMinBiasEventSelectorCfg,
17 HighPtMinBiasEventSelectorCfg,
18 CavernEventSelectorCfg,
19 BeamGasEventSelectorCfg,
20 BeamHaloEventSelectorCfg,
28 from hashlib
import blake2b
31 "Given number of bkg needed (on average) per BC, returns number to load per batch"
36 boundaries = np.array([1.74752840e-03, 4.03701726e-03, 7.74263683e-03, 1.23284674e-02,
37 1.78864953e-02, 2.36448941e-02, 3.12571585e-02, 3.76493581e-02,
38 4.53487851e-02, 5.46227722e-02, 6.57933225e-02, 7.92482898e-02,
39 8.69749003e-02, 9.54548457e-02, 1.04761575e-01, 1.14975700e-01,
40 1.26185688e-01, 1.38488637e-01, 1.51991108e-01, 1.66810054e-01,
41 1.83073828e-01, 2.00923300e-01, 2.20513074e-01, 2.42012826e-01,
42 2.65608778e-01, 2.91505306e-01, 3.19926714e-01, 3.51119173e-01,
43 3.85352859e-01, 4.22924287e-01, 4.64158883e-01, 5.09413801e-01,
44 5.59081018e-01, 6.13590727e-01, 6.73415066e-01, 7.39072203e-01,
45 8.11130831e-01, 8.90215085e-01, 9.77009957e-01, 1.07226722e+00,
46 1.17681195e+00, 1.29154967e+00, 1.41747416e+00, 1.55567614e+00,
47 1.70735265e+00, 1.87381742e+00, 2.05651231e+00, 2.25701972e+00,
48 2.47707636e+00, 2.71858824e+00, 2.98364724e+00, 3.27454916e+00,
49 3.59381366e+00, 3.94420606e+00, 4.32876128e+00, 4.75081016e+00,
50 5.21400829e+00, 5.72236766e+00, 6.28029144e+00, 6.89261210e+00,
51 7.56463328e+00, 8.30217568e+00, 9.11162756e+00, 1.00000000e+01])
52 n_to_load = np.array([ 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13.,
53 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.,
54 26., 27., 29., 31., 33., 35., 37., 39., 42., 44., 47.,
55 51., 54., 58., 62., 66., 71., 76., 81., 88., 94., 101.,
56 109., 117., 126., 136., 147., 158., 171., 185., 200., 216., 234.,
57 253., 275., 298., 323., 350., 380., 413., 448., 487.])
59 return int(ceil(1.224 * nPerBC * 39))
60 return int(n_to_load[np.searchsorted(boundaries, nPerBC, side=
'right')])
72 acc.merge(
InputRenameCfg(
"xAOD::EventInfo",
"EventInfo",
"HSEventInfo"))
73 acc.merge(
InputRenameCfg(
"xAOD::EventAuxInfo",
"EventInfoAux.",
"HSEventInfoAux."))
75 acc.merge(
InputRenameCfg(
"McEventCollection",
"TruthEvent",
"HSTruthEvent"))
76 acc.merge(
InputRenameCfg(
"TrackRecordCollection",
"MuonEntryLayer",
"HSMuonEntryLayer"))
83 int.from_bytes(blake2b(name.encode(), digest_size=8).digest(),
'big')
84 + flags.Digitization.RandomSeedOffset
90 n_evt = flags.Exec.MaxEvents
91 skip = flags.Exec.SkipEvents
94 if kind == PUBkgKind.LOWPT:
96 kwargs.setdefault(
"OnDemandMB",
True)
97 kwargs.setdefault(
"SkippedHSEvents", skip)
98 kwargs.setdefault(
"MBBatchSize", 10000)
99 kwargs.setdefault(
"NSimultaneousBatches", 1)
100 kwargs.setdefault(
"HSBatchSize", 128)
101 kwargs.setdefault(
"AvgMBPerBunch", flags.Digitization.PU.NumberOfLowPtMinBias)
102 evt_per_batch = kwargs[
"HSBatchSize"]
103 actualNHSEventsPerBatch = (
104 (skip // evt_per_batch) * [0]
105 + (skip % evt_per_batch != 0) * [evt_per_batch - (skip % evt_per_batch)]
106 + (n_evt // evt_per_batch) * [evt_per_batch]
107 + (n_evt % evt_per_batch != 0) * [n_evt % evt_per_batch]
109 kwargs[
"actualNHSEventsPerBatch"] = actualNHSEventsPerBatch
111 "BkgEventSelector", acc.getService(
"LowPtMinBiasEventSelector")
113 elif kind == PUBkgKind.HIGHPT:
115 kwargs.setdefault(
"OnDemandMB",
False)
116 kwargs.setdefault(
"SkippedHSEvents", skip)
117 kwargs.setdefault(
"AvgMBPerBunch", flags.Digitization.PU.NumberOfHighPtMinBias)
119 "BkgEventSelector", acc.getService(
"HighPtMinBiasEventSelector")
121 elif kind == PUBkgKind.CAVERN:
123 kwargs.setdefault(
"OnDemandMB",
False)
124 kwargs.setdefault(
"SkippedHSEvents", skip)
125 kwargs.setdefault(
"AvgMBPerBunch", flags.Digitization.PU.NumberOfCavern)
126 kwargs.setdefault(
"UsePoisson",
False)
127 kwargs.setdefault(
"UseBeamInt",
False)
128 kwargs.setdefault(
"UseBeamLumi",
False)
129 kwargs.setdefault(
"BkgEventSelector", acc.getService(
"CavernEventSelector"))
130 elif kind == PUBkgKind.BEAMGAS:
132 kwargs.setdefault(
"OnDemandMB",
False)
133 kwargs.setdefault(
"SkippedHSEvents", skip)
134 kwargs.setdefault(
"AvgMBPerBunch", flags.Digitization.PU.NumberOfBeamGas)
135 kwargs.setdefault(
"UseBeamInt",
True)
136 kwargs.setdefault(
"UseBeamLumi",
False)
137 kwargs.setdefault(
"BkgEventSelector", acc.getService(
"BeamGasEventSelector"))
138 elif kind == PUBkgKind.BEAMHALO:
140 kwargs.setdefault(
"OnDemandMB",
False)
141 kwargs.setdefault(
"SkippedHSEvents", skip)
142 kwargs.setdefault(
"AvgMBPerBunch", flags.Digitization.PU.NumberOfBeamHalo)
143 kwargs.setdefault(
"UseBeamInt",
True)
144 kwargs.setdefault(
"UseBeamLumi",
False)
145 kwargs.setdefault(
"BkgEventSelector", acc.getService(
"BeamHaloEventSelector"))
147 if kind == PUBkgKind.LOWPT:
148 acc.addService(CompFactory.BatchedMinbiasSvc(name, **kwargs), primary=
True)
150 acc.addService(CompFactory.OnDemandMinbiasSvc(name, **kwargs), primary=
True)
156 acc.addService(CompFactory.SkipEventIdxSvc(
"SkipEventIdxSvc"))
157 kwargs.setdefault(
"Cardinality", flags.Concurrency.NumThreads)
161 not flags.Digitization.DoXingByXingPileUp
162 ),
"PileUpMTAlg does not support XingByXing pile-up!"
165 if flags.Digitization.PU.BeamIntensityPattern:
166 if flags.Digitization.PU.SignalPatternForSteppingCache:
169 kwargs.setdefault(
"BeamIntSvc", acc.getService(
"StepArrayBM"))
170 elif flags.Digitization.PU.FixedT0BunchCrossing:
173 kwargs.setdefault(
"BeamIntSvc", acc.getService(
"FixedArrayBM"))
177 kwargs.setdefault(
"BeamIntSvc", acc.getService(
"ArrayBM"))
179 kwargs.setdefault(
"SkippedHSEvents", flags.Exec.SkipEvents)
180 kwargs.setdefault(
"BCSpacing", flags.Digitization.PU.BunchSpacing)
181 kwargs.setdefault(
"EarliestDeltaBC", flags.Digitization.PU.InitialBunchCrossing)
182 kwargs.setdefault(
"LatestDeltaBC", flags.Digitization.PU.FinalBunchCrossing)
183 if flags.Input.RunAndLumiOverrideList:
185 kwargs.setdefault(
"BeamLumiSvc", acc.getService(
"LumiProfileSvc"))
189 kwargs.setdefault(
"BeamLumiSvc", acc.getService(
"NoProfileSvc"))
190 kwargs.setdefault(
"AverageMu", flags.Digitization.PU.NumberOfCollisions)
193 assert not flags.Input.SecondaryFiles, (
194 "Found ConfigFlags.Input.SecondaryFiles = %r; "
195 "double event selection is not supported "
196 "by PileUpMTAlg" % (
not flags.Input.SecondaryFiles)
211 if flags.Digitization.PU.LowPtMinBiasInputCols:
212 svc = acc.getPrimaryAndMerge(
214 flags, name=
"LowPtMinBiasSvc", kind=PUBkgKind.LOWPT, **mbKwargs
217 kwargs.setdefault(
"LowPtMinbiasSvc", svc)
220 flags.Digitization.PU.NumberOfLowPtMinBias
221 / flags.Digitization.PU.NumberOfCollisions,
223 if flags.Digitization.PU.HighPtMinBiasInputCols:
224 svc = acc.getPrimaryAndMerge(
226 flags, name=
"HighPtMinBiasSvc", kind=PUBkgKind.HIGHPT, **mbKwargs
229 kwargs.setdefault(
"HighPtMinbiasSvc", svc)
232 flags.Digitization.PU.NumberOfHighPtMinBias
233 / flags.Digitization.PU.NumberOfCollisions,
235 if flags.Digitization.PU.CavernInputCols:
236 svc = acc.getPrimaryAndMerge(
238 flags, name=
"CavernMinBiasSvc", kind=PUBkgKind.CAVERN, **mbKwargs
241 kwargs.setdefault(
"CavernMinbiasSvc", svc)
242 kwargs.setdefault(
"NumCavern", flags.Digitization.PU.NumberOfCavern)
243 if flags.Digitization.PU.BeamGasInputCols:
244 svc = acc.getPrimaryAndMerge(
246 flags, name=
"BeamGasMinBiasSvc", kind=PUBkgKind.BEAMGAS, **mbKwargs
249 kwargs.setdefault(
"BeamGasMinbiasSvc", svc)
250 kwargs.setdefault(
"NumBeamGas", flags.Digitization.PU.NumberOfBeamGas)
251 if flags.Digitization.PU.BeamHaloInputCols:
252 svc = acc.getPrimaryAndMerge(
254 flags, name=
"BeamHaloMinBiasSvc", kind=PUBkgKind.BEAMHALO, **mbKwargs
257 kwargs.setdefault(
"BeamHaloMinbiasSvc", svc)
258 kwargs.setdefault(
"NumBeamHalo", flags.Digitization.PU.NumberOfBeamHalo)
259 presampling = flags.Common.ProductionStep == ProductionStep.PileUpPresampling
261 kwargs.setdefault(
"EventInfoKey", flags.Overlay.BkgPrefix +
"EventInfo")
263 kwargs.setdefault(
"EventInfoKey",
"EventInfo")
266 CompFactory.PileUpMTAlg(flags.Digitization.DigiSteeringConf, **kwargs)
270 if flags.Output.doWriteRDO:
271 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
278 "xAOD::EventInfoContainer#PileUpEventInfo",
279 "xAOD::EventInfoAuxContainer#PileUpEventInfo*",