8 #include <GeoModelKernel/throwExcept.h>
13 const std::string&
name,
14 const IInterface* pIID):
21 return StatusCode::FAILURE;
25 return StatusCode::FAILURE;
38 return StatusCode::SUCCESS;
42 unsigned int nInputEvents) {
44 ATH_MSG_DEBUG(
"prepareEvent() called for " << nInputEvents <<
" input events");
47 return StatusCode::SUCCESS;
51 for (
const auto& [timeIndex, simHitColl] : hitColl) {
52 timedHits.reserve(timedHits.capacity() + simHitColl->size());
54 timedHits.emplace_back(timeIndex.time(), timeIndex.index(), simHit, timeIndex.type());
57 std::sort(timedHits.begin(), timedHits.end(),
59 if (a->identify() != b->identify()){
60 return a->identify() < b->identify();
62 if (
a.eventId() !=
b.eventId()) {
63 return a.eventId() < b.eventId();
65 return a.eventTime() <
b.eventTime();
67 return StatusCode::SUCCESS;
70 return hit.
eventTime() + hit->globalTime();
72 StatusCode MuonDigitizationTool::processAllSubEvents(
const EventContext& ctx) {
77 StatusCode MuonDigitizationTool::processAllSubEvents(
const EventContext& ctx)
const {
81 if (!m_onlyUseContainerName) {
83 ATH_CHECK(retrieveContainer(ctx, m_simHitKey, hitCollection));
86 ATH_CHECK(m_mergeSvc->retrieveSubEvtsData(m_inputObjectName, hitCollList));
88 ATH_CHECK(fillTimedHits(std::move(hitCollList), timedHits));
90 if (!m_sdoKey.empty()) {
92 ATH_CHECK(sdoContainer.record(std::make_unique<xAOD::MuonSimHitContainer>(),
93 std::make_unique<xAOD::MuonSimHitAuxContainer>()));
95 ATH_CHECK(digitize(ctx, timedHits, !m_sdoKey.empty() ? sdoContainer.ptr() :
nullptr));
96 return StatusCode::SUCCESS;
98 StatusCode MuonDigitizationTool::mergeEvent(
const EventContext& ctx) {
102 if (!m_sdoKey.empty()) {
104 ATH_CHECK(sdoContainer.record(std::make_unique<xAOD::MuonSimHitContainer>(),
105 std::make_unique<xAOD::MuonSimHitAuxContainer>()));
107 ATH_CHECK(digitize(ctx, m_timedHits, !m_sdoKey.empty() ? sdoContainer.ptr() :
nullptr));
110 return StatusCode::SUCCESS;
114 StatusCode MuonDigitizationTool::processBunchXing(
int bunchXing,
119 ATH_CHECK(m_mergeSvc->retrieveSubSetEvtData(m_inputObjectName, hitList, bunchXing, bSubEvents, eSubEvents));
120 ATH_MSG_VERBOSE(hitList.size() <<
" hits in xAODMuonSimHitContainer " << m_inputObjectName <<
" found");
121 for (
auto& [hitPtr, hitContainer] : hitList) {
122 auto copyContainer = std::make_unique<xAOD::MuonSimHitContainer>();
123 auto copyAuxContainer = std::make_unique<xAOD::MuonSimHitAuxContainer>();
124 copyContainer->setStore(copyAuxContainer.get());
126 (*copyContainer->push_back(std::make_unique<xAOD::MuonSimHit>())) = (*copyMe);
128 hitListPermanent.emplace_back(hitPtr, copyContainer.get());
129 m_simHits.emplace_back(std::move(copyContainer), std::move(copyAuxContainer));
131 ATH_CHECK(fillTimedHits(std::move(hitListPermanent), m_timedHits));
132 return StatusCode::SUCCESS;
135 CLHEP::HepRandomEngine* MuonDigitizationTool::getRandomEngine(
const EventContext&ctx)
const {
137 std::string rngName = m_streamName;
138 rngWrapper->
setSeed(rngName, ctx);
143 if (!retrieveContainer(ctx, m_geoCtxKey, gctx).isSuccess()) {
144 THROW_EXCEPTION(
"Failed to retrieve the geometry context "<<m_geoCtxKey.fullKey());
155 ATH_MSG_VERBOSE(
"Hit "<<m_idHelperSvc->toString(hit->identify())<<
" is a pile-up truth link");
164 acc_eventTime(*sdoHit) = hit.
eventTime();
165 acc_eventID(*sdoHit) = hit.
eventId();
171 const double deadTimeWindow,
175 if (insertItr.second) {
178 if (
hitTime - insertItr.first->second < deadTimeWindow) {
182 insertItr.first->second =
hitTime;