11#include <unordered_set>
13 using IdSet_t = std::unordered_set<Identifier>;
15 using TruthPartWithIds_t = std::tuple<const xAOD::TruthParticle*, IdSet_t>;
40 return StatusCode::SUCCESS;
53 std::vector<IdDecorHandle_t> idDecorHandles{};
55 idDecorHandles.emplace_back(hitKey, ctx);
58 std::vector<TruthPartWithIds_t> truthWithIds{};
64 ATH_MSG_DEBUG(
"Truth muon: pT:"<<truthMuon->pt()<<
" [GeV], eta: "<<truthMuon->eta()<<
", phi: "
68 for (
const IdDecorHandle_t& hitDecor : idDecorHandles) {
69 std::ranges::transform(hitDecor(*truthMuon), std::inserter(assocIds, assocIds.begin()),
70 [
this](
unsigned long long rawId) {
71 const Identifier id{rawId};
76 truthWithIds.emplace_back(std::make_tuple(truthMuon, std::move(assocIds)));
82 ATH_MSG_ERROR(
"Associated reconstructed track is not available for "<<m_trkKey);
83 return StatusCode::FAILURE;
87 for (
const Trk::TrackStateOnSurface* tsos : *
track->trackStateOnSurfaces()) {
88 const Trk::MeasurementBase* meas = tsos->measurementOnTrack();
93 const Identifier measId = m_edmHelperSvc->getIdentifier(*meas);
94 if (!measId.
is_valid() || !m_idHelperSvc->isMuon(measId)){
98 trackIds.insert(measId);
101 int bestMatchFrac{-1};
103 for (
const auto& [truthPart, truthIds]: truthWithIds) {
104 const int matchedReco = std::ranges::count_if(trackIds,[&truthIds](
const Identifier& recoId){
105 return truthIds.count(recoId);
108 if (!matchedReco || matchedReco < bestMatchFrac){
111 bestMatchFrac = matchedReco;
112 bestMatch = truthPart;
123 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
Handle class for adding a decoration to an object.
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
ElementLink implementation for ROOT usage.
bool is_valid() const
Check if id is in a valid state.
TruthReadDecorKey_t m_truMuOriginKey
FIXME ReadDecorHandle should not be used to access dynamic variables applied by the algorithm which c...
TruthReadDecorKeyArr_t m_simHitKeys
Declaration of the dependency on the simHit decorations.
TrkWriteDecorKey_t m_linkWriteKey
TrkWriteDecorKey_t m_typeWriteKey
TrkWriteDecorKey_t m_classificationWriteKey
TruthReadDecorKey_t m_truMuClassificationKey
StatusCode initialize() override final
TrkWriteDecorKey_t m_originWriteKey
Decorations to be written to the TrackParticle truthOrigin/truthType/truthParticleLink.
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
Helper service to handle the Identifiers of measurements.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< std::vector< std::string > > m_simHitIds
List of simHit id decorations to read from the truth particle.
TruthReadDecorKey_t m_truMuTypeKey
TruthReadKey_t m_truthMuonKey
size_t index() const
Return the index of this element within its container.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
int getParticleTruthClassification(const xAOD::IParticle &p)
Return the particle's truth classification (as defined by the MC Truth Classifier)
int getParticleTruthType(const xAOD::IParticle &p)
Return the particle's truth type (as defined by the MC Truth Classifier)
int getParticleTruthOrigin(const xAOD::IParticle &p)
Return the particle's truth origin (as defined by the MC Truth Classifier)
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.