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