ATLAS Offline Software
Loading...
Searching...
No Matches
muonTrkTrackThinTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// muonTrkTrackThinTool.cxx, (c) ATLAS Detector software
8// Author: Saminder Dhaliwal (s.dhaliwal@cern.ch)
9// Follows closely from dimuonTaggingTool and DerviationFrameworkExamples
10
11// STL includes
12#include <algorithm>
13#include <iostream>
14
15// FrameWork includes
16#include "Gaudi/Property.h"
17// StoreGate
19#include "GaudiKernel/ThreadLocalContext.h"
20
21
23//#include "AthenaKernel/errorcheck.h"
24#include <vector>
25#include <string>
26
27// xAOD containers
30
31// Constructor
32muonTrkTrackThinTool::muonTrkTrackThinTool(const std::string& name,ISvcLocator* pSvcLocator):
33 AthReentrantAlgorithm (name, pSvcLocator) {
34}
35// Athena initialize and finalize
37{
38 ATH_MSG_VERBOSE("initialize() ...");
40 ATH_CHECK( m_muonReadKey.initialize());
41 return StatusCode::SUCCESS;
42}
43
45{
46 ATH_MSG_VERBOSE("finalize() ...");
47 ATH_MSG_INFO("muonTrkTrackThinTool Filter number of muons PASSED "<<m_pass<<" FROM "<< m_All);
48 ATH_MSG_INFO("muonTrkTrackThinTool Filter number of Trk::Track PASSED "<<m_trackpass<<" FROM "<< m_trackAll);
49 return StatusCode::SUCCESS;
50}
51
52// The thinning itself
53StatusCode muonTrkTrackThinTool::execute(const EventContext& ctx ) const {
54
56
57 if (alltracks->empty()){
58 ATH_MSG_DEBUG( "------------- Track Collection is empty, collection type: " << m_trackCollKey.key());
59 return StatusCode::SUCCESS;
60 }
61
62 std::vector<bool> mask_t;
63 mask_t.resize(alltracks->size(), false);
64 m_trackAll+= alltracks->size();
65
66 // Retrieve the muons:
68 if(!muonHandle.isValid()){
69 ATH_MSG_ERROR("Could not read "<< m_muonReadKey);
70 return StatusCode::FAILURE;
71 }
72
73 const xAOD::MuonContainer* muons = muonHandle.cptr();
74
75
76 m_All+= muons->size();
77
78 // Loop over muon:
79 for( const auto* muon : *muons ) {
80 m_pass++;
81 const xAOD::TrackParticle* muon_tp = 0;
82 //Needed the below 'if' statements to separate trackparticle cases
83 if (m_trackCollKey.key() == "MuonSpectrometerTracks")
84 muon_tp = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
85
86 if (m_trackCollKey.key() == "CombinedMuonTracks")
87 muon_tp = muon->trackParticle(xAOD::Muon::CombinedTrackParticle);
88
89 if (m_trackCollKey.key() == "MSOnlyExtrapolatedTracks")
90 muon_tp = muon->trackParticle(xAOD::Muon::MSOnlyExtrapolatedMuonSpectrometerTrackParticle);
91
92 if (m_trackCollKey.key() == "ExtrapolatedMuonTracks")
93 muon_tp = muon->trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
94
95
96 if (!muon_tp) {
97 ATH_MSG_DEBUG( "------------- No muon track particle " );
98 continue; // segtagged muons
99 }
100
101 //using element link rather than "const Trk::Track* muontr = muontp->track();"
102 //avoids an additional loop over track collection
103 const ElementLink< TrackCollection >& muontr_link = muon_tp->trackLink();
104 if (!muontr_link.isValid()){
105 ATH_MSG_DEBUG("------------- Elementlink from trackparticle to trk::track not valid");
106 continue; //This shouldn't happen
107 }
108
109 int trIndex = muontr_link.index();
110 if (trIndex < int(mask_t.size())){
111 mask_t[trIndex] = true;
112 m_trackpass++;
113 }
114 }//close muon loop
115
116
117 alltracks.keep (mask_t);
118
119 return StatusCode::SUCCESS;
120}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle for requesting thinning for a data object.
An algorithm that can be simultaneously executed in multiple threads.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
virtual StatusCode finalize() override
std::atomic< int > m_All
muonTrkTrackThinTool(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
SG::ReadHandleKey< xAOD::MuonContainer > m_muonReadKey
SG::ThinningHandleKey< TrackCollection > m_trackCollKey
virtual StatusCode execute(const EventContext &ctx) const override
std::atomic< int > m_trackAll
virtual StatusCode initialize() override
std::atomic< int > m_pass
std::atomic< int > m_trackpass
const ElementLink< TrackCollection > & trackLink() const
Returns a link (which can be invalid) to the Trk::Track which was used to make this TrackParticle.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".