189 {
191 FastReseededPRNG prng{
m_seed.value(), hs_id};
192
193
194 bool sf_updated_throwaway;
195 const float beam_lumi_sf =
197 ctx.eventID().lumi_block(),
198 sf_updated_throwaway)
199 : 1.f;
200 std::vector<float> avg_num_mb_by_bunch(n_bunches,
202
204
205
210 avg_num_mb_by_bunch[
idx] *=
m_beamInt->normFactor(bunch);
211 }
212 }
213
215 num_mb_by_bunch.clear();
216 num_mb_by_bunch.resize(n_bunches);
217
219 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
220 num_mb_by_bunch.begin(), [&prng](float avg) {
221 return std::poisson_distribution<std::uint64_t>(avg)(prng);
222 });
223 } else {
224 std::transform(avg_num_mb_by_bunch.begin(), avg_num_mb_by_bunch.end(),
225 num_mb_by_bunch.begin(), [](float f) {
226 return static_cast<std::uint64_t>(std::round(f));
227 });
228 }
229
230 std::uint64_t num_mb = std::accumulate(num_mb_by_bunch.begin(), num_mb_by_bunch.end(), std::uint64_t{0});
231 std::vector<std::uint64_t>& index_array = *
m_idx_lists.get(ctx);
233
234 if (num_mb > mbBatchSize) {
237 rv::iota(0ULL, num_mb_by_bunch.size()) |
238 rv::filter([center_bunch, &num_mb_by_bunch](int idx) {
239 bool good =
idx != center_bunch;
241 good && num_mb_by_bunch[
idx] > 0;
243 }) |
244 ranges::to<std::vector>;
245
246 ranges::stable_sort(indices, std::greater{},
247 [center_bunch](std::size_t
idx) {
248 return std::size_t(std::abs(int(idx) - center_bunch));
249 });
250
251 for (auto idx : indices) {
252 const std::uint64_t max_to_subtract = num_mb - mbBatchSize;
253 const std::uint64_t num_subtracted =
254 std::min(max_to_subtract, num_mb_by_bunch[idx]);
255 num_mb_by_bunch[
idx] -= num_subtracted;
256 num_mb -= num_subtracted;
257 if (num_mb <= mbBatchSize) {
258 break;
259 }
260 }
261
262 ATH_MSG_ERROR(
"We need " << num_mb <<
" events but the batch size is "
263 << mbBatchSize << ". Restricting to "
264 << mbBatchSize << " events!");
265 }
266 index_array = rv::ints(0, int(mbBatchSize)) | rv::sample(num_mb, prng) |
267 ranges::to<std::vector<std::uint64_t>>;
268 ranges::shuffle(index_array, prng);
269 ATH_MSG_DEBUG(
"HS ID " << hs_id <<
" uses " << num_mb <<
" events");
270
271
272
273
274
275 return num_mb;
276}
Gaudi::Property< std::uint64_t > m_seed
Gaudi::Property< float > m_nPerBunch
Gaudi::Property< bool > m_useBeamLumi
ServiceHandle< IBeamIntensity > m_beamInt
Gaudi::Property< int > m_earliestDeltaBC
Gaudi::Property< bool > m_usePoisson
Gaudi::Property< int > m_latestDeltaBC
SG::SlotSpecificObj< std::vector< std::uint64_t > > m_idx_lists
Gaudi::Property< bool > m_useBeamInt
Gaudi::Property< int > m_MBBatchSize
SG::SlotSpecificObj< std::vector< std::uint64_t > > m_num_mb_by_bunch
ServiceHandle< IBeamLuminosity > m_beamLumi
std::pair< long int, long int > indices