ATLAS Offline Software
Loading...
Searching...
No Matches
SV1TrackThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SV1TrackThinning.cxx, (c) ATLAS Detector software
8
15#include "GaudiKernel/ThreadLocalContext.h"
16#include <vector>
17#include <string>
18
19// Constructor
21 const std::string& n,
22 const IInterface* p ) :
23 base_class(t,n,p),
24 m_ntot(0),
25 m_npass(0),
26 m_jetSGKey(""),
28{
29 declareProperty("JetKey", m_jetSGKey);
30 declareProperty("SelectionString", m_selectionString);
31}
32
33// Destructor
36
37// Athena initialize and finalize
39{
40 // Decide which collections need to be checked for ID TrackParticles
41 ATH_MSG_VERBOSE("initialize() ...");
42 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
43 ATH_MSG_INFO("Using " << m_inDetSGKey << "as the source collection for inner detector track particles");
44 if (m_jetSGKey=="") {
45 ATH_MSG_FATAL("No jet collection provided for thinning.");
46 return StatusCode::FAILURE;
47 } else { ATH_MSG_INFO("Inner detector track particles associated with objects in " << m_jetSGKey << " will be retained in this format with the rest being thinned away");}
48
49 // Set up the text-parsing machinery for selectiong the jet directly according to user cuts
50 if (!m_selectionString.empty()) {
51 ATH_CHECK(initializeParser(m_selectionString) );
52 }
53 return StatusCode::SUCCESS;
54}
55
57{
58 ATH_MSG_VERBOSE("finalize() ...");
59 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
60 ATH_CHECK(finalizeParser() );
61 return StatusCode::SUCCESS;
62}
63
64// The thinning itself
66{
67 const EventContext& ctx = Gaudi::Hive::currentContext();
68
69 // Retrieve main TrackParticle collection
71 (m_inDetSGKey, ctx);
72
73 // Check the event contains tracks
74 unsigned int nTracks = importedTrackParticles->size();
75 if (nTracks==0) return StatusCode::SUCCESS;
76
77 // Set up a mask with the same entries as the full TrackParticle collection
78 std::vector<bool> mask;
79 mask.assign(nTracks, false); // default: don't keep any tracks
80 m_ntot += nTracks;
81
82 const xAOD::JetContainer* importedJets(0);
83 if (evtStore()->retrieve(importedJets,m_jetSGKey).isFailure()) {
84 ATH_MSG_ERROR("No jet collection with name " << m_jetSGKey << " found in StoreGate!");
85 return StatusCode::FAILURE;
86 }
87
88 unsigned int nJets(importedJets->size());
89 std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
90
91 // Execute the text parser if requested
92 if (!m_selectionString.empty()) {
93 std::vector<int> entries = m_parser->evaluateAsVector();
94 unsigned int nEntries = entries.size();
95 // check the sizes are compatible
96 if (nJets != nEntries ) {
97 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used jets??");
98 return StatusCode::FAILURE;
99 } else {
100 // identify which jets to keep for the thinning check
101 for (unsigned int i=0; i<nJets; ++i) if (entries[i]==1) jetToCheck.push_back((*importedJets)[i]);
102 }
103 }
104
105 // Retrieve containers
106 // ... jets
107 if (m_selectionString=="") { // check all jets as user didn't provide a selection string
108 for (xAOD::JetContainer::const_iterator jetIt=importedJets->begin(); jetIt!=importedJets->end(); ++jetIt) {
110 const std::vector< ElementLink<xAOD::TrackParticleContainer> >& SV1_trackParticleLinks =
112
113
114 for (const ElementLink<xAOD::TrackParticleContainer> &tp : SV1_trackParticleLinks) {
115 int index = (*tp)->index();
116 mask[index] = true;
117 }
118 }
119 } else { // check only jets passing user selection string
120 for (std::vector<const xAOD::Jet*>::iterator jetIt = jetToCheck.begin(); jetIt!=jetToCheck.end(); ++jetIt) {
122 const std::vector< ElementLink<xAOD::TrackParticleContainer> >& SV1_trackParticleLinks =
124
125
126 for (const ElementLink<xAOD::TrackParticleContainer> &tp : SV1_trackParticleLinks) {
127 int index = (*tp)->index();
128 mask[index] = true;
129 }
130 }
131 }
132
133 // Count up the mask contents
134 for (unsigned int i=0; i<nTracks; ++i) {
135 if (mask[i]) ++m_npass;
136 }
137
138 // Execute the thinning service based on the mask. Finish.
139 importedTrackParticles.keep (mask);
140
141 return StatusCode::SUCCESS;
142}
143
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
Handle for requesting thinning for a data object.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
std::atomic< unsigned int > m_npass
std::atomic< unsigned int > m_ntot
virtual StatusCode doThinning() const override
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
virtual StatusCode initialize() override
virtual StatusCode finalize() override
SV1TrackThinning(const std::string &t, const std::string &n, const IInterface *p)
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.
const TPELVec_t & SV1_TrackParticleLinks() const
get vector of SV1 TrackParticle ElementLinks
double entries
Definition listroot.cxx:49
Definition index.py:1
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
BTagging_v1 BTagging
Definition of the current "BTagging version".
Definition BTagging.h:17
JetContainer_v1 JetContainer
Definition of the current "jet container version".