ATLAS Offline Software
Loading...
Searching...
No Matches
IDPerfMuonRefitter.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
6//==================================================================================
7
8//==================================================================================
9// Include files...
10//==================================================================================
11
12// This file's header
14
15
16// Need containers
17#include "xAODMuon/Muon.h"
19
20//Interface Headers
22
23// ATLAS headers
25#include "GaudiKernel/IInterface.h"
26
27
28//==================================================================================
29// Public Methods
30//==================================================================================
32 ISvcLocator* pSvcLocator):
33 AthAlgorithm(name, pSvcLocator),
36 m_N_Muons(0),
39{
40 // Properties that are set from the python scripts.
41 declareProperty("OutputTracksName", m_outputTracksName = "IDMuonTracks");
42 declareProperty("ReFitterTool1", m_TrackRefitter1, "ToolHandle for track fitter implementation");
43 declareProperty("ReFitterTool2", m_TrackRefitter2, "ToolHandle for track fitter implementation");
44
45}
46
47
50
51
53{
54 // Retrieve fitter
55 if (m_TrackRefitter1.retrieve().isFailure()) {
56 ATH_MSG_FATAL("Unable to retrieve " << m_TrackRefitter1 );
57 return StatusCode::FAILURE;
58 } else {
59 ATH_MSG_INFO("Retrieved tool" << m_TrackRefitter1 );
60 }
61 // Retrieve the second fitter
62 if (m_TrackRefitter2.retrieve().isFailure()) {
63 ATH_MSG_FATAL("Unable to retrieve " << m_TrackRefitter2 );
64 return StatusCode::FAILURE;
65 } else {
66 ATH_MSG_INFO("Retrieved tool" << m_TrackRefitter2 );
67 }
68
69 ATH_CHECK( m_muonContainerKey.initialize() );
70 return StatusCode::SUCCESS;
71}
72
73
74
75
77{
82 for (const auto muon : *pxMuonContainer){
83 if (!muon) {
84 ATH_MSG_WARNING("CB Muons missing!");
85 continue;
86 }
87 ++m_N_Muons;
88 const xAOD::TrackParticle* idTP = muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
89 if (!idTP) {
90 ATH_MSG_DEBUG("ID TrackParticles missing! Skipping Muon");
91 continue;
92 }
93 Trk::Track* defaultMuonTrk{};
94 Trk::Track* refit1MuonTrk{};
95 Trk::Track* refit2MuonTrk{};
96 const xAOD::Electron* eg{};
97 StatusCode fitStatus;
98 //save default and refit track parameters
99 if( idTP->track() ) {
100 defaultMuonTrk = new Trk::Track(*idTP->track());
101 //save tracks to storegrate /
102 muonTrks->push_back(defaultMuonTrk);
104 cache1.electron=eg;
105 fitStatus = m_TrackRefitter1->refitTrack( Gaudi::Hive::currentContext(),idTP->track(), cache1 );
107 if (fitStatus == StatusCode::SUCCESS) {
108 refit1MuonTrk = cache1.refittedTrack.release();
109 muonTrksRefit1->push_back(refit1MuonTrk);
110 } else {
111 ATH_MSG_DEBUG("Track Refit1 Failed. Skipping Muon");
113 continue;
114 }
116 cache2.electron=eg;
117 fitStatus = m_TrackRefitter2->refitTrack(Gaudi::Hive::currentContext(),idTP->track(), cache2 );
118 if (fitStatus == StatusCode::SUCCESS) {
119 refit2MuonTrk = cache2.refittedTrack.release();
120 muonTrksRefit2->push_back(refit2MuonTrk);
121 } else {
122 ATH_MSG_DEBUG("Track Refit2 Failed. Skipping Muon");
123 continue;
124 }
125 }
126 }// End loop over muons
127 //Store information into storegate
128 StatusCode sc = evtStore()->record(muonTrks, m_outputTracksName, false);
129 if (sc.isFailure()) {
130 ATH_MSG_WARNING( "Failed storing " << m_outputTracksName);
131 } else{
132 ATH_MSG_DEBUG( "Stored "<< muonTrks->size() << " " << m_outputTracksName <<" into StoreGate" );
133 }
134 sc = evtStore()->record(muonTrksRefit1, m_outputTracksName + "Refit1", false);
135 if (sc.isFailure()) {
136 ATH_MSG_WARNING( "Failed storing " << m_outputTracksName + "Refit1" );
137 } else {
138 ATH_MSG_DEBUG( "Stored "<< muonTrksRefit1->size() << " " << m_outputTracksName + "Refit1" <<" into StoreGate");
139 }
140 sc = evtStore()->record(muonTrksRefit2, m_outputTracksName + "Refit2", false);
141 if (sc.isFailure()) {
142 ATH_MSG_WARNING( "Failed storing " << m_outputTracksName +"Refit2" );
143 } else {
144 ATH_MSG_DEBUG( "Stored "<< muonTrksRefit2->size() << " " << m_outputTracksName + "Refit2" <<" into StoreGate" );
145 }
146 return StatusCode::SUCCESS;
147}
148
149
151{
152 ATH_MSG_INFO("***************************************************");
153 ATH_MSG_INFO("**************** IDPerfMuonRefitter ***************");
154 ATH_MSG_INFO("***************************************************");
155 ATH_MSG_INFO(m_N_Muons << "\t\t Muons inspected" );
156 ATH_MSG_INFO(m_N_MuonsRefit << "\t\t Muons refit" );
157 ATH_MSG_INFO(m_N_MuonRefitFailures << "\t\t Muons refit failures" );
158 ATH_MSG_INFO("***************************************************");
159 ATH_MSG_INFO("***************************************************");
160 return StatusCode::SUCCESS;
161}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Handle class for reading from StoreGate.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
ToolHandle< IegammaTrkRefitterTool > m_TrackRefitter2
The track refitter.
virtual StatusCode initialize()
virtual StatusCode execute()
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerKey
std::string m_outputTracksName
virtual StatusCode finalize()
IDPerfMuonRefitter(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< IegammaTrkRefitterTool > m_TrackRefitter1
The track refitter.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
@ OWN_ELEMENTS
this data object owns its elements
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Electron_v1 Electron
Definition of the current "egamma version".
Struct Holding the result to return and intermediate objects Things are owned by the EDM or the uniqu...
std::unique_ptr< Trk::Track > refittedTrack
Pointer to the refitted track.
const xAOD::Electron * electron
pointer to the Electron input