Execute method.
184 {
186 std::string trace_buf{};
187 auto trace = std::back_inserter(trace_buf);
189 const auto& evtID = ctx.eventID();
190
193
194
195
196 std::unique_ptr<const xAOD::EventInfo> hsEvt = nullptr;
197 std::unique_ptr<xAOD::EventAuxInfo> hsEvtAux = nullptr;
199
200
201 SG::WriteHandle<xAOD::EventInfo> overlaidEvt(
m_evtInfoKey, ctx);
202 ATH_CHECK(overlaidEvt.record(std::make_unique<xAOD::EventInfo>(),
203 std::make_unique<xAOD::EventAuxInfo>()));
204 *overlaidEvt = *hsEvt;
206 overlaidEvt->clearSubEvents();
207
208
209
210 overlaidEvt->setRunNumber(evtID.run_number());
211 overlaidEvt->setLumiBlock(evtID.lumi_block());
212 overlaidEvt->setEventNumber(evtID.event_number());
213 overlaidEvt->setBCID(evtID.bunch_crossing_id());
214 overlaidEvt->setTimeStamp(evtID.time_stamp());
215 overlaidEvt->setTimeStampNSOffset(evtID.time_stamp_ns_offset());
216
217 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle{
m_beamSpotKey, ctx};
218 if (!beamSpotHandle.
isValid()) {
220 return StatusCode::FAILURE;
221 }
222
223 overlaidEvt->setBeamPos(beamSpotHandle->beamPos()[
Amg::x],
224 beamSpotHandle->beamPos()[
Amg::y],
225 beamSpotHandle->beamPos()[
Amg::z]);
226 overlaidEvt->setBeamPosSigma(beamSpotHandle->beamSigma(0),
227 beamSpotHandle->beamSigma(1),
228 beamSpotHandle->beamSigma(2));
229 overlaidEvt->setBeamPosSigmaXY(beamSpotHandle->beamSigmaXY());
230 overlaidEvt->setBeamTiltXZ(beamSpotHandle->beamTilt(0));
231 overlaidEvt->setBeamTiltYZ(beamSpotHandle->beamTilt(1));
232 overlaidEvt->setBeamStatus(beamSpotHandle->beamStatus());
233
234
236 ATH_CHECK(puCont.record(std::make_unique<xAOD::EventInfoContainer>(),
237 std::make_unique<xAOD::EventInfoAuxContainer>()));
238
239
241 overlaidEvt->setBCID(
m_beamInt->getCurrentT0BunchCrossing());
242
243
244 overlaidEvt->setEventTypeBitmask(hsEvt->eventTypeBitmask() |
246
247
248 bool sf_updated = false;
249 float lumi_sf =
m_beamLumi->scaleFactor(evtID.run_number(),
250 evtID.lumi_block(), sf_updated);
251 float cur_avg_mu = lumi_sf *
m_avgMu;
252 overlaidEvt->setAverageInteractionsPerCrossing(cur_avg_mu);
253 overlaidEvt->setActualInteractionsPerCrossing(
m_beamInt->normFactor(0) *
254 cur_avg_mu);
255
256
258 std::format_to(trace,
259 "Idx: {} Run: {} LB: {} EVT: {} "
260 "HS ID: {}\n",
261 ctx.evt(), evtID.run_number(), evtID.lumi_block(),
264 | rv::transform([
this](
int bc) {
return int(
m_beamInt->normFactor(bc));})
265 | rv::chunk_by(std::equal_to{})
266 | rv::transform([](auto&& chunk) { return std::format("{}{}", std::ranges::distance(chunk), *chunk.begin() == 0 ? 'E' : 'F');}))
267 | std::ranges::to<std::vector<std::string>>();
268
269 std::string joined_pattern;
270 for (
size_t i = 0;
i < bunch_pattern.size(); ++
i) {
271 joined_pattern += bunch_pattern[
i];
272 if (i + 1 < bunch_pattern.size()) {
273 joined_pattern += " ";
274 }
275 }
276
277 std::format_to(trace,
278 "mu = {}, central BCID = {}, bunch pattern = [{}]\n",
279 cur_avg_mu,
m_beamInt->getCurrentT0BunchCrossing(),
280 joined_pattern);
281 }
282
283 if (!hsEvt->subEvents().empty()) {
284 for (
const SubEvent& se : hsEvt->subEvents()) {
287 }
288 } else {
289
292 }
293
294
297 }
300 }
303 }
306 }
309 }
310
311 std::uint32_t central_bcid = overlaidEvt->bcid();
312 std::vector<std::uint32_t>
bcid{};
314
317 }
318
319
321
323 }
324
325
326 std::uint64_t low_pt_count = 0;
327 std::uint64_t high_pt_count = 0;
328 std::uint64_t cavern_count = 0;
329 std::uint64_t beam_halo_count = 0;
330 std::uint64_t beam_gas_count = 0;
331 auto now = std::chrono::high_resolution_clock::now();
334
335 continue;
336 }
337 std::vector<std::uint64_t> subevts_vec{};
340 std::format_to(trace, "\tBC {:03} : LOW PT {} ", bc,
342 }
343 for (std::size_t i = 0;
i <
m_lowptMBSvc->getNumForBunch(ctx, bc); ++
i) {
345 PUType::MinimumBias, bc, ctx, low_pt_count,
346 subevts_vec));
347 ++low_pt_count;
348 }
349 }
352 std::format_to(trace, "HIGH PT {} | ",
354 }
355 for (std::size_t i = 0;
i <
m_highptMBSvc->getNumForBunch(ctx, bc); ++
i) {
357 PUType::HighPtMinimumBias, bc, ctx, high_pt_count,
358 subevts_vec));
359 ++high_pt_count;
360 }
361 }
364 std::format_to(trace, "CAVERN {} | ",
366 }
367 for (std::size_t i = 0;
i <
m_cavernMBSvc->getNumForBunch(ctx, bc); ++
i) {
369 PUType::Cavern, bc, ctx, cavern_count,
370 subevts_vec));
371 ++cavern_count;
372 }
373 }
376 std::format_to(trace, "BEAM HALO {} | ",
378 }
382 PUType::HaloGas, bc, ctx, beam_halo_count,
383 subevts_vec));
384 ++beam_halo_count;
385 }
386 }
389 std::format_to(trace, "BEAM GAS {} | ",
391 }
395 PUType::HaloGas, bc, ctx, beam_gas_count,
396 subevts_vec));
397 ++beam_gas_count;
398 }
399 }
401 std::format_to(trace, "TOTAL {} | HASH {:08X}\n", subevts_vec.size(),
403 }
404 }
406 std::format_to(trace, "\n");
407 m_pileupTrace.print(trace_buf);
408 }
409
411 try {
413 } catch (const std::exception& e) {
416 return StatusCode::FAILURE;
417 }
418
419 if (!
tool->filterPassed()) {
421 }
422 }
423 ATH_MSG_DEBUG(std::format(
"***** Took {:%OMm %OSs} to process all subevents",
424 std::chrono::high_resolution_clock::now() - now));
425
426
427 PileUpHashHelper pileUpHashHelper;
430
431
432 uuid_t pileUpHash;
434 overlaidEvt->setPileUpMixtureID(
436 ATH_MSG_DEBUG(
"PileUpMixtureID = " << overlaidEvt->pileUpMixtureID());
437
441 }
444 }
447 }
450 }
453 }
454 return StatusCode::SUCCESS;
455}
#define ATH_MSG_VERBOSE(x)
xAOD::EventInfo::SubEvent SubEvent
virtual void setFilterPassed(bool state, const EventContext &ctx) const
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?)
setEventNumber setTimeStamp bcid
std::uint64_t hash64(const void *data, std::size_t size)
Passthrough to XXH3_64bits.