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
20
22//#include "AthenaKernel/errorcheck.h"
23#include <vector>
24#include <string>
25
26// xAOD containers
29
30// Constructor
31muonTrkTrackThinTool::muonTrkTrackThinTool(const std::string& name,ISvcLocator* pSvcLocator):
32 AthReentrantAlgorithm (name, pSvcLocator) {
33}
34// Athena initialize and finalize
36{
37 ATH_MSG_VERBOSE("initialize() ...");
39 ATH_CHECK( m_muonReadKey.initialize());
40 return StatusCode::SUCCESS;
41}
42
44{
45 ATH_MSG_VERBOSE("finalize() ...");
46 ATH_MSG_INFO("muonTrkTrackThinTool Filter number of muons PASSED "<<m_pass<<" FROM "<< m_All);
47 ATH_MSG_INFO("muonTrkTrackThinTool Filter number of Trk::Track PASSED "<<m_trackpass<<" FROM "<< m_trackAll);
48 return StatusCode::SUCCESS;
49}
50
51// The thinning itself
52StatusCode muonTrkTrackThinTool::execute(const EventContext& ctx ) const {
53
55
56 if (alltracks->empty()){
57 ATH_MSG_DEBUG( "------------- Track Collection is empty, collection type: " << m_trackCollKey.key());
58 return StatusCode::SUCCESS;
59 }
60
61 std::vector<bool> mask_t;
62 mask_t.resize(alltracks->size(), false);
63 m_trackAll+= alltracks->size();
64
65 // Retrieve the muons:
67 if(!muonHandle.isValid()){
68 ATH_MSG_ERROR("Could not read "<< m_muonReadKey);
69 return StatusCode::FAILURE;
70 }
71
72 const xAOD::MuonContainer* muons = muonHandle.cptr();
73
74
75 m_All+= muons->size();
76
77 // Loop over muon:
78 for( const auto* muon : *muons ) {
79 m_pass++;
80 const xAOD::TrackParticle* muon_tp = 0;
81 //Needed the below 'if' statements to separate trackparticle cases
82 if (m_trackCollKey.key() == "MuonSpectrometerTracks")
83 muon_tp = muon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
84
85 if (m_trackCollKey.key() == "CombinedMuonTracks")
86 muon_tp = muon->trackParticle(xAOD::Muon::CombinedTrackParticle);
87
88 if (m_trackCollKey.key() == "MSOnlyExtrapolatedTracks")
89 muon_tp = muon->trackParticle(xAOD::Muon::MSOnlyExtrapolatedMuonSpectrometerTrackParticle);
90
91 if (m_trackCollKey.key() == "ExtrapolatedMuonTracks")
92 muon_tp = muon->trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
93
94
95 if (!muon_tp) {
96 ATH_MSG_DEBUG( "------------- No muon track particle " );
97 continue; // segtagged muons
98 }
99
100 //using element link rather than "const Trk::Track* muontr = muontp->track();"
101 //avoids an additional loop over track collection
102 const ElementLink< TrackCollection >& muontr_link = muon_tp->trackLink();
103 if (!muontr_link.isValid()){
104 ATH_MSG_DEBUG("------------- Elementlink from trackparticle to trk::track not valid");
105 continue; //This shouldn't happen
106 }
107
108 int trIndex = muontr_link.index();
109 if (trIndex < int(mask_t.size())){
110 mask_t[trIndex] = true;
111 m_trackpass++;
112 }
113 }//close muon loop
114
115
116 alltracks.keep (mask_t);
117
118 return StatusCode::SUCCESS;
119}
#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".