ATLAS Offline Software
Loading...
Searching...
No Matches
MuonAODFixAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: MuonAODFixAlg.cxx 298140 2013-11-19 11:32:49Z emoyse $
6
7// Gaudi/Athena include(s):
9
10// EDM include(s):
14
15// Local include(s):
16#include "MuonAODFixAlg.h"
17
18// Misc
19#include <memory>
20
21namespace xAOD {
22
24 ISvcLocator* svcLoc )
25 : AthAlgorithm( name, svcLoc )
26 {
27
28 declareProperty( "MuonContainerName", m_containerName = "Muons" );
29 }
30
32 // Return gracefully:
33 return StatusCode::SUCCESS;
34
35 }
36
38
39 // Code copied from InDetVxLinksToMuons
40 const SG::DataProxy* proxy =
43 if (!proxy) {
44 ATH_MSG_WARNING( "No xAOD::MuonContainer "
45 << "with key \"" << m_containerName << "\" found" );
46 return StatusCode::SUCCESS;
47 }
48
49 xAOD::MuonContainer* muons=nullptr;
50
51 if (proxy->isConst()) {
52 const xAOD::MuonContainer* originalMuons = nullptr;
53 ATH_CHECK( evtStore()->retrieve (originalMuons,
55
56 muons = new xAOD::MuonContainer;
57 auto store = std::make_unique<xAOD::MuonAuxContainer>();
58 muons->setStore (store.get());
59 for (const xAOD::Muon* oldMuon : *originalMuons) {
61 muons->push_back (muon);
62 *muons->back() = *oldMuon;
63 fixMuon(*muon);
64 }
65 ATH_CHECK( evtStore()->overwrite (muons,
67 true, false) );
68 ATH_CHECK( evtStore()->overwrite (std::move(store),
69 m_containerName + "Aux.",
70 true, false) );
71 } else {
72 ATH_CHECK( evtStore()->retrieve (muons,
74 for (auto muon: *muons){
75 fixMuon(*muon);
76 }
77 }
78
79 return StatusCode::SUCCESS;
80 }
81
83 // Get primary trackparticle
84 const xAOD::TrackParticle * tp = muon.primaryTrackParticle();
85 if (!tp) {
86 ATH_MSG_WARNING("No primary track particle for this muon. Skipping.");
87 return;
88 }
89 muon.setP4(tp->pt(), tp->eta(), tp->phi());
90 static const SG::Accessor<ElementLink<xAOD::TruthParticleContainer> > truthParticleLinkAcc ("truthParticleLink");
91 static const SG::Accessor<int> truthTypeAcc ("truthType");
92 static const SG::Accessor<int> truthOriginAcc ("truthOrigin");
93 if (truthParticleLinkAcc.isAvailable (*tp)) {
94 truthParticleLinkAcc (muon) = truthParticleLinkAcc (*tp);
95 truthTypeAcc (muon) = truthTypeAcc (*tp);
96 truthOriginAcc (muon) = truthOriginAcc (*tp);
97 }
98 }
99
100}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Helper class to provide type-safe access to aux data.
Helpers for checking error return status codes and reporting errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
void fixMuon(xAOD::Muon &muon) const
virtual StatusCode execute()
Function executing the algorithm.
virtual StatusCode initialize()
Function initialising the algorithm.
MuonAODFixAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
std::string m_containerName
The key for the output xAOD::CaloClusterContainer.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".