ATLAS Offline Software
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):
13 #include "AthContainers/Accessor.h"
14 
15 // Local include(s):
16 #include "MuonAODFixAlg.h"
17 
18 // Misc
19 #include <memory>
20 
21 namespace xAOD {
22 
23  MuonAODFixAlg::MuonAODFixAlg( const std::string& name,
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,
54  m_containerName) );
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) {
60  xAOD::Muon* muon = new xAOD::Muon;
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,
73  m_containerName) );
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
xAOD::MuonAODFixAlg::m_containerName
std::string m_containerName
The key for the output xAOD::CaloClusterContainer.
Definition: MuonAODFixAlg.h:46
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::MuonAODFixAlg::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: MuonAODFixAlg.cxx:31
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonAuxContainer.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::MuonAODFixAlg::fixMuon
void fixMuon(xAOD::Muon &muon) const
Definition: MuonAODFixAlg.cxx:82
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
xAOD::MuonAODFixAlg::MuonAODFixAlg
MuonAODFixAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: MuonAODFixAlg.cxx:23
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition: Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
MuonAODFixAlg.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
Accessor.h
Helper class to provide type-safe access to aux data.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MuonAODFixAlg::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: MuonAODFixAlg.cxx:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
SG::DataProxy
Definition: DataProxy.h:44