185 {
187 std::string trace_buf{};
188 auto trace = std::back_inserter(trace_buf);
190 const EventContext& ctx = Gaudi::Hive::currentContext();
191 const auto& evtID = ctx.eventID();
192
194 setFilterPassed(false);
195
196
197
198 std::unique_ptr<const xAOD::EventInfo> hsEvt = nullptr;
199 std::unique_ptr<xAOD::EventAuxInfo> hsEvtAux = nullptr;
201
202
203 SG::WriteHandle<xAOD::EventInfo> overlaidEvt(
m_evtInfoKey, ctx);
204 ATH_CHECK(overlaidEvt.record(std::make_unique<xAOD::EventInfo>(),
205 std::make_unique<xAOD::EventAuxInfo>()));
206 *overlaidEvt = *hsEvt;
208 overlaidEvt->clearSubEvents();
209
210
211
212 overlaidEvt->setRunNumber(evtID.run_number());
213 overlaidEvt->setLumiBlock(evtID.lumi_block());
214 overlaidEvt->setEventNumber(evtID.event_number());
215 overlaidEvt->setBCID(evtID.bunch_crossing_id());
216 overlaidEvt->setTimeStamp(evtID.time_stamp());
217 overlaidEvt->setTimeStampNSOffset(evtID.time_stamp_ns_offset());
218
219 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle{
m_beamSpotKey, ctx};
220 if (!beamSpotHandle.
isValid()) {
222 return StatusCode::FAILURE;
223 }
224
225 overlaidEvt->setBeamPos(beamSpotHandle->beamPos()[
Amg::x],
226 beamSpotHandle->beamPos()[
Amg::y],
227 beamSpotHandle->beamPos()[
Amg::z]);
228 overlaidEvt->setBeamPosSigma(beamSpotHandle->beamSigma(0),
229 beamSpotHandle->beamSigma(1),
230 beamSpotHandle->beamSigma(2));
231 overlaidEvt->setBeamPosSigmaXY(beamSpotHandle->beamSigmaXY());
232 overlaidEvt->setBeamTiltXZ(beamSpotHandle->beamTilt(0));
233 overlaidEvt->setBeamTiltYZ(beamSpotHandle->beamTilt(1));
234 overlaidEvt->setBeamStatus(beamSpotHandle->beamStatus());
235
236
238 ATH_CHECK(puCont.record(std::make_unique<xAOD::EventInfoContainer>(),
239 std::make_unique<xAOD::EventInfoAuxContainer>()));
240
241
242 m_beamInt->selectT0(evtID.run_number(), evtID.event_number());
243 overlaidEvt->setBCID(
m_beamInt->getCurrentT0BunchCrossing());
244
245
246 overlaidEvt->setEventTypeBitmask(hsEvt->eventTypeBitmask() |
248
249
250 bool sf_updated = false;
251 float lumi_sf =
m_beamLumi->scaleFactor(evtID.run_number(),
252 evtID.lumi_block(), sf_updated);
253 float cur_avg_mu = lumi_sf *
m_avgMu;
254 overlaidEvt->setAverageInteractionsPerCrossing(cur_avg_mu);
255 overlaidEvt->setActualInteractionsPerCrossing(
m_beamInt->normFactor(0) *
256 cur_avg_mu);
257
258
260 std::format_to(trace,
261 "Idx: {} Run: {} LB: {} EVT: {} "
262 "HS ID: {}\n",
263 ctx.evt(), evtID.run_number(), evtID.lumi_block(),
265 auto bunch_pattern =
267 rv::transform(
268 [
this](
int bc) {
return int(
m_beamInt->normFactor(bc)); }) |
269#if RANGE_V3_VERSION >= 1200
270 rv::chunk_by(std::equal_to{}) |
271#else
272 rv::group_by(std::equal_to{}) |
273#endif
274 rv::transform([](const auto& rng) {
275 return std::format(
"{}{}",
rng.size(), rng[0] == 0 ?
'E' :
'F');
276 }) |
277 ranges::to<std::vector<std::string>>;
278
279 std::string joined_pattern;
280 for (
size_t i = 0;
i < bunch_pattern.size(); ++
i) {
281 joined_pattern += bunch_pattern[
i];
282 if (i + 1 < bunch_pattern.size()) {
283 joined_pattern += " ";
284 }
285 }
286
287 std::format_to(trace,
288 "mu = {}, central BCID = {}, bunch pattern = [{}]\n",
289 cur_avg_mu,
m_beamInt->getCurrentT0BunchCrossing(),
290 joined_pattern);
291 }
292
293 if (!hsEvt->subEvents().empty()) {
294 for (
const SubEvent& se : hsEvt->subEvents()) {
297 }
298 } else {
299
302 }
303
304
307 }
310 }
313 }
316 }
319 }
320
321 std::uint32_t central_bcid = overlaidEvt->bcid();
322 std::vector<std::uint32_t>
bcid{};
324
327 }
328
329
331
333 }
334
335
336 std::uint64_t low_pt_count = 0;
337 std::uint64_t high_pt_count = 0;
338 std::uint64_t cavern_count = 0;
339 std::uint64_t beam_halo_count = 0;
340 std::uint64_t beam_gas_count = 0;
341 auto now = std::chrono::high_resolution_clock::now();
344
345 continue;
346 }
347 std::vector<std::uint64_t> subevts_vec{};
350 std::format_to(trace, "\tBC {:03} : LOW PT {} ", bc,
352 }
353 for (std::size_t i = 0;
i <
m_lowptMBSvc->getNumForBunch(ctx, bc); ++
i) {
355 PUType::MinimumBias, bc, ctx, low_pt_count,
356 subevts_vec));
357 ++low_pt_count;
358 }
359 }
362 std::format_to(trace, "HIGH PT {} | ",
364 }
365 for (std::size_t i = 0;
i <
m_highptMBSvc->getNumForBunch(ctx, bc); ++
i) {
367 PUType::HighPtMinimumBias, bc, ctx, high_pt_count,
368 subevts_vec));
369 ++high_pt_count;
370 }
371 }
374 std::format_to(trace, "CAVERN {} | ",
376 }
377 for (std::size_t i = 0;
i <
m_cavernMBSvc->getNumForBunch(ctx, bc); ++
i) {
379 PUType::Cavern, bc, ctx, cavern_count,
380 subevts_vec));
381 ++cavern_count;
382 }
383 }
386 std::format_to(trace, "BEAM HALO {} | ",
388 }
392 PUType::HaloGas, bc, ctx, beam_halo_count,
393 subevts_vec));
394 ++beam_halo_count;
395 }
396 }
399 std::format_to(trace, "BEAM GAS {} | ",
401 }
405 PUType::HaloGas, bc, ctx, beam_gas_count,
406 subevts_vec));
407 ++beam_gas_count;
408 }
409 }
411 std::format_to(trace, "TOTAL {} | HASH {:08X}\n", subevts_vec.size(),
413 }
414 }
416 std::format_to(trace, "\n");
417 m_pileupTrace.print(trace_buf);
418 }
419
421 try {
423 } catch (const std::exception& e) {
426 return StatusCode::FAILURE;
427 }
428
429 if (!
tool->filterPassed()) {
430 setFilterPassed(false);
431 }
432 }
433 ATH_MSG_DEBUG(std::format(
"***** Took {:%OMm %OSs} to process all subevents",
434 std::chrono::high_resolution_clock::now() - now));
435
436
437 PileUpHashHelper pileUpHashHelper;
440
441
442 uuid_t pileUpHash;
444 overlaidEvt->setPileUpMixtureID(
446 ATH_MSG_DEBUG(
"PileUpMixtureID = " << overlaidEvt->pileUpMixtureID());
447
448 setFilterPassed(true);
451 }
454 }
457 }
460 }
463 }
464 return StatusCode::SUCCESS;
465}
#define ATH_MSG_VERBOSE(x)
xAOD::EventInfo::SubEvent SubEvent
ServiceHandle< StoreGateSvc > & evtStore()
std::string hashSource() const
Get the current hash base.
void addToHashSource(const std::string &string)
Add a plain string to the stream.
void calculateHash(uuid_t &hash) const
Calculate the hash.
static xAOD::EventInfo::PileUpMixtureID uuidToPileUpMixtureId(const uuid_t &hash)
Convert uuid_t to xAOD::EventInfo::PileUpMixtureID.
Gaudi::Property< int > m_latestDeltaBC
Gaudi::Property< float > m_avgMu
Gaudi::Property< float > m_numCavern
unsigned int get_BCID(int bc, unsigned int central_BCID) const
Gaudi::Property< float > m_fracLowPt
ServiceHandle< IBeamLuminosity > m_beamLumi
ToolHandleArray< IPileUpTool > m_puTools
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
ServiceHandle< IMinbiasSvc > m_beamgasMBSvc
ServiceHandle< IMinbiasSvc > m_highptMBSvc
ServiceHandle< IMinbiasSvc > m_cavernMBSvc
Gaudi::Property< float > m_fracHighPt
SG::WriteHandleKey< xAOD::EventInfo > m_evtInfoKey
ServiceHandle< IBeamIntensity > m_beamInt
ServiceHandle< IMinbiasSvc > m_lowptMBSvc
Other useful methods provided by base class are: evtStore() : ServiceHandle to main event data storeg...
Gaudi::Property< float > m_numBeamGas
Gaudi::Property< float > m_numBeamHalo
StatusCode add_subevt(const std::vector< std::uint32_t > &bcid, SG::WriteHandle< xAOD::EventInfo > &overlaidEvt, SG::WriteHandle< xAOD::EventInfoContainer > &puCont, ServiceHandle< IMinbiasSvc > &mbSvc, xAOD::EventInfo::PileUpType puType, int bc, const EventContext &ctx, unsigned long subevt_id, std::vector< std::uint64_t > &trace)
ServiceHandle< IMinbiasSvc > m_beamhaloMBSvc
PileUpType
Enumerator describing the types of pileup events.
@ Signal
The signal event.
@ IS_SIMULATION
true: simulation, false: data
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
retrieve(aClass, aKey=None)
setEventNumber setTimeStamp bcid
std::uint64_t hash64(const void *data, std::size_t size)
Passthrough to XXH3_64bits.