13 #include <GaudiKernel/SystemOfUnits.h>
23 ATH_MSG_FATAL(
"Please provide at least one container to sort");
24 return StatusCode::FAILURE;
29 return StatusCode::SUCCESS;
35 if(!readHandle.isValid()) {
37 return StatusCode::FAILURE;
39 std::copy(readHandle->begin(), readHandle->end(), std::back_inserter(allSimHits));
41 std::stable_sort(allSimHits.begin(), allSimHits.end(),
44 const IdentifierHash hashA = m_idHelperSvc->detElementHash(a->identify());
45 const IdentifierHash hashB = m_idHelperSvc->detElementHash(a->identify());
50 if (
a->identify() !=
b->identify()) {
51 return a->identify() < b->identify();
54 if (std::abs(
a->pdgId()) != std::abs(
b->pdgId())){
55 return a->pdgId() > b->pdgId();
59 if (
a->genParticleLink().barcode() !=
b->genParticleLink().barcode()) {
60 return a->genParticleLink().barcode() < b->genParticleLink().barcode();
63 return a->globalTime() <
b->globalTime();
65 if (m_removeDuplicates) {
66 std::vector<const xAOD::MuonSimHit*> dupFreeHits{};
67 std::copy_if(allSimHits.begin(), allSimHits.end(), std::back_inserter(dupFreeHits),
69 const int barcode = hit->genParticleLink().barcode();
70 const Identifier hitId = hit->identify();
71 const Amg::Vector3D lPos{xAOD::toEigen(hit->localPosition())};
72 const Amg::Vector3D lDir{xAOD::toEigen(hit->localDirection())};
76 return std::find_if(dupFreeHits.begin(), dupFreeHits.end(),
78 if (selHit->identify() != hitId ||
79 barcode != selHit->genParticleLink().barcode()) return false;
80 if (barcode) return true;
81 const Amg::Vector3D dPos = lPos - xAOD::toEigen(selHit->localPosition());
82 const Amg::Vector3D dDir = lDir - xAOD::toEigen(selHit->localDirection());
83 return dPos.mag() < tolerance && dDir.mag() < tolerance;
84 }) == dupFreeHits.end();
87 std::copy(dupFreeHits.begin(), dupFreeHits.end(), std::back_inserter(allSimHits));
90 if (m_writeDeepCopy) {
91 ATH_CHECK(writeHandle.record(std::make_unique<xAOD::MuonSimHitContainer>(),
92 std::make_unique<xAOD::MuonSimHitAuxContainer>()));
95 writeHandle->push_back(newHit);
96 (*newHit) = (*copy_me);
99 ATH_CHECK(writeHandle.record(std::make_unique<xAOD::MuonSimHitContainer>(*allSimHits.asDataVector())));
101 return StatusCode::SUCCESS;