Execute method.
185 {
187 std::string trace_buf{};
188 auto trace = std::back_inserter(trace_buf);
190 const auto& evtID = ctx.eventID();
191
194
195
196
197 std::unique_ptr<const xAOD::EventInfo> hsEvt = nullptr;
198 std::unique_ptr<xAOD::EventAuxInfo> hsEvtAux = nullptr;
200
201
202 SG::WriteHandle<xAOD::EventInfo> overlaidEvt(
m_evtInfoKey, ctx);
203 ATH_CHECK(overlaidEvt.record(std::make_unique<xAOD::EventInfo>(),
204 std::make_unique<xAOD::EventAuxInfo>()));
205 *overlaidEvt = *hsEvt;
207 overlaidEvt->clearSubEvents();
208
209
210
211 overlaidEvt->setRunNumber(evtID.run_number());
212 overlaidEvt->setLumiBlock(evtID.lumi_block());
213 overlaidEvt->setEventNumber(evtID.event_number());
214 overlaidEvt->setBCID(evtID.bunch_crossing_id());
215 overlaidEvt->setTimeStamp(evtID.time_stamp());
216 overlaidEvt->setTimeStampNSOffset(evtID.time_stamp_ns_offset());
217
218 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle{
m_beamSpotKey, ctx};
219 if (!beamSpotHandle.
isValid()) {
221 return StatusCode::FAILURE;
222 }
223
224 overlaidEvt->setBeamPos(beamSpotHandle->beamPos()[
Amg::x],
225 beamSpotHandle->beamPos()[
Amg::y],
226 beamSpotHandle->beamPos()[
Amg::z]);
227 overlaidEvt->setBeamPosSigma(beamSpotHandle->beamSigma(0),
228 beamSpotHandle->beamSigma(1),
229 beamSpotHandle->beamSigma(2));
230 overlaidEvt->setBeamPosSigmaXY(beamSpotHandle->beamSigmaXY());
231 overlaidEvt->setBeamTiltXZ(beamSpotHandle->beamTilt(0));
232 overlaidEvt->setBeamTiltYZ(beamSpotHandle->beamTilt(1));
233 overlaidEvt->setBeamStatus(beamSpotHandle->beamStatus());
234
235
237 ATH_CHECK(puCont.record(std::make_unique<xAOD::EventInfoContainer>(),
238 std::make_unique<xAOD::EventInfoAuxContainer>()));
239
240
242 overlaidEvt->setBCID(
m_beamInt->getCurrentT0BunchCrossing());
243
244
245 overlaidEvt->setEventTypeBitmask(hsEvt->eventTypeBitmask() |
247
248
249 bool sf_updated = false;
250 float lumi_sf =
m_beamLumi->scaleFactor(evtID.run_number(),
251 evtID.lumi_block(), sf_updated);
252 float cur_avg_mu = lumi_sf *
m_avgMu;
253 overlaidEvt->setAverageInteractionsPerCrossing(cur_avg_mu);
254 overlaidEvt->setActualInteractionsPerCrossing(
m_beamInt->normFactor(0) *
255 cur_avg_mu);
256
257
259 std::format_to(trace,
260 "Idx: {} Run: {} LB: {} EVT: {} "
261 "HS ID: {}\n",
262 ctx.evt(), evtID.run_number(), evtID.lumi_block(),
264 auto bunch_pattern =
266 rv::transform(
267 [
this](
int bc) {
return int(
m_beamInt->normFactor(bc)); }) |
268#if RANGE_V3_VERSION >= 1200
269 rv::chunk_by(std::equal_to{}) |
270#else
271 rv::group_by(std::equal_to{}) |
272#endif
273 rv::transform([](const auto& rng) {
274 return std::format(
"{}{}",
rng.size(), rng[0] == 0 ?
'E' :
'F');
275 }) |
276 ranges::to<std::vector<std::string>>;
277
278 std::string joined_pattern;
279 for (
size_t i = 0;
i < bunch_pattern.size(); ++
i) {
280 joined_pattern += bunch_pattern[
i];
281 if (i + 1 < bunch_pattern.size()) {
282 joined_pattern += " ";
283 }
284 }
285
286 std::format_to(trace,
287 "mu = {}, central BCID = {}, bunch pattern = [{}]\n",
288 cur_avg_mu,
m_beamInt->getCurrentT0BunchCrossing(),
289 joined_pattern);
290 }
291
292 if (!hsEvt->subEvents().empty()) {
293 for (
const SubEvent& se : hsEvt->subEvents()) {
296 }
297 } else {
298
301 }
302
303
306 }
309 }
312 }
315 }
318 }
319
320 std::uint32_t central_bcid = overlaidEvt->bcid();
321 std::vector<std::uint32_t>
bcid{};
323
326 }
327
328
330
332 }
333
334
335 std::uint64_t low_pt_count = 0;
336 std::uint64_t high_pt_count = 0;
337 std::uint64_t cavern_count = 0;
338 std::uint64_t beam_halo_count = 0;
339 std::uint64_t beam_gas_count = 0;
340 auto now = std::chrono::high_resolution_clock::now();
343
344 continue;
345 }
346 std::vector<std::uint64_t> subevts_vec{};
349 std::format_to(trace, "\tBC {:03} : LOW PT {} ", bc,
351 }
352 for (std::size_t i = 0;
i <
m_lowptMBSvc->getNumForBunch(ctx, bc); ++
i) {
354 PUType::MinimumBias, bc, ctx, low_pt_count,
355 subevts_vec));
356 ++low_pt_count;
357 }
358 }
361 std::format_to(trace, "HIGH PT {} | ",
363 }
364 for (std::size_t i = 0;
i <
m_highptMBSvc->getNumForBunch(ctx, bc); ++
i) {
366 PUType::HighPtMinimumBias, bc, ctx, high_pt_count,
367 subevts_vec));
368 ++high_pt_count;
369 }
370 }
373 std::format_to(trace, "CAVERN {} | ",
375 }
376 for (std::size_t i = 0;
i <
m_cavernMBSvc->getNumForBunch(ctx, bc); ++
i) {
378 PUType::Cavern, bc, ctx, cavern_count,
379 subevts_vec));
380 ++cavern_count;
381 }
382 }
385 std::format_to(trace, "BEAM HALO {} | ",
387 }
391 PUType::HaloGas, bc, ctx, beam_halo_count,
392 subevts_vec));
393 ++beam_halo_count;
394 }
395 }
398 std::format_to(trace, "BEAM GAS {} | ",
400 }
404 PUType::HaloGas, bc, ctx, beam_gas_count,
405 subevts_vec));
406 ++beam_gas_count;
407 }
408 }
410 std::format_to(trace, "TOTAL {} | HASH {:08X}\n", subevts_vec.size(),
412 }
413 }
415 std::format_to(trace, "\n");
416 m_pileupTrace.print(trace_buf);
417 }
418
420 try {
422 } catch (const std::exception& e) {
425 return StatusCode::FAILURE;
426 }
427
428 if (!
tool->filterPassed()) {
430 }
431 }
432 ATH_MSG_DEBUG(std::format(
"***** Took {:%OMm %OSs} to process all subevents",
433 std::chrono::high_resolution_clock::now() - now));
434
435
436 PileUpHashHelper pileUpHashHelper;
439
440
441 uuid_t pileUpHash;
443 overlaidEvt->setPileUpMixtureID(
445 ATH_MSG_DEBUG(
"PileUpMixtureID = " << overlaidEvt->pileUpMixtureID());
446
450 }
453 }
456 }
459 }
462 }
463 return StatusCode::SUCCESS;
464}
#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.