ATLAS Offline Software
Loading...
Searching...
No Matches
VSITrackParticleThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// VSITrackParticleThinning.cxx, (c) ATLAS Detector software
8// Authors: Amber Roepe (amber.rebecca.roepe@cern.ch)
9// Jackson Burzynski (jackson.carl.burzynski@cern.ch)
10// This is a trivial example of an implementation of a thinning tool
11// which removes all ID tracks which do not pass a user-defined cut
12
17#include "GaudiKernel/ThreadLocalContext.h"
18#include <vector>
19#include <string>
20
21// Constructor
23 const std::string& n,
24 const IInterface* p ) :
25base_class(t,n,p)
26{
27}
28
29// Destructor
32
33// Athena initialize and finalize
35{
36
37 // Decide which collections need to be checked for ID TrackParticles
38 ATH_MSG_VERBOSE("initialize() ...");
39 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
40
41 // Set up the text-parsing machinery for selectiong the dv directly according to user cuts
42 if (!m_trackSelectionString.empty()) {
43 // order must match enum order EJetTrPThinningParser
44 ATH_CHECK( initializeParser( { m_selectionString, m_trackSelectionString } ));
45 }
46
47 return StatusCode::SUCCESS;
48}
49
51{
52 ATH_MSG_VERBOSE("finalize() ...");
53 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
54 return StatusCode::SUCCESS;
55}
56
57// The thinning itself
59{
60
61 const EventContext& ctx = Gaudi::Hive::currentContext();
62
63 // Retrieve main TrackParticle collection
65 (m_inDetSGKey, ctx);
66
67 // Check the event contains tracks
68 unsigned int nTracks = importedTrackParticles->size();
69 if (nTracks==0) return StatusCode::SUCCESS;
70
71 // Set up a mask with the same entries as the full TrackParticle collection
72 std::vector<bool> mask;
73 mask.assign(nTracks,false); // default: don't keep any tracks
74 m_ntot += nTracks;
75
76 // Set elements in the mask to true if associated with a DV
77 for ( const auto trkIt: *importedTrackParticles ) {
78 for ( const auto &augVerString: m_augVerStrings) {
79 SG::ConstAccessor<char> acc("is_svtrk_final" + augVerString);
80 if (acc.withDefault (*trkIt, false)) {
81 int index = trkIt->index();
82 mask[index] = true;
83 }
84 }
85 }
86
87 // Apply a track selection string.
88 if (!m_trackSelectionString.empty()) {
89 std::vector<int> entries = m_parser[kdvTrackThinning]->evaluateAsVector();
90 unsigned int nEntries = entries.size();
91 // check the sizes are compatible
92 if (nTracks != nEntries ) {
93 ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
94 return StatusCode::FAILURE;
95 }
96 else {
97 // identify which dvs to keep for the thinning check
98 for (unsigned int i=0; i<nEntries; ++i) {
99 if (!mask[i]) continue;
100 if (!entries[i]) mask[i] = false;
101 }
102 }
103 }
104
105
106 // Count up the mask contents
107 unsigned int n_pass=0;
108 for (unsigned int i=0; i<nTracks; ++i) {
109 if (mask[i]) ++n_pass;
110 }
111 m_npass += n_pass;
112
113
114 // Execute the thinning service based on the mask. Finish.
115 importedTrackParticles.keep (mask);
116
117
118 return StatusCode::SUCCESS;
119
120}
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)
Handle for requesting thinning for a data object.
VSITrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
Helper class to provide constant type-safe access to aux data.
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.
double entries
Definition listroot.cxx:49
Definition index.py:1