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 <vector>
18#include <string>
19
20// Constructor
22 const std::string& n,
23 const IInterface* p ) :
24base_class(t,n,p)
25{
26}
27
28// Destructor
31
32// Athena initialize and finalize
34{
35
36 // Decide which collections need to be checked for ID TrackParticles
37 ATH_MSG_VERBOSE("initialize() ...");
38 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
39
40 // Set up the text-parsing machinery for selectiong the dv directly according to user cuts
41 if (!m_trackSelectionString.empty()) {
42 // order must match enum order EJetTrPThinningParser
43 ATH_CHECK( initializeParser( { m_selectionString, m_trackSelectionString } ));
44 }
45
46 return StatusCode::SUCCESS;
47}
48
50{
51 ATH_MSG_VERBOSE("finalize() ...");
52 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
53 return StatusCode::SUCCESS;
54}
55
56// The thinning itself
57StatusCode DerivationFramework::VSITrackParticleThinning::doThinning(const EventContext& ctx) const
58{
59
60
61 // Retrieve main TrackParticle collection
63 (m_inDetSGKey, ctx);
64
65 // Check the event contains tracks
66 unsigned int nTracks = importedTrackParticles->size();
67 if (nTracks==0) return StatusCode::SUCCESS;
68
69 // Set up a mask with the same entries as the full TrackParticle collection
70 std::vector<bool> mask;
71 mask.assign(nTracks,false); // default: don't keep any tracks
72 m_ntot += nTracks;
73
74 // Set elements in the mask to true if associated with a DV
75 for ( const auto trkIt: *importedTrackParticles ) {
76 for ( const auto &augVerString: m_augVerStrings) {
77 SG::ConstAccessor<char> acc("is_svtrk_final" + augVerString);
78 if (acc.withDefault (*trkIt, false)) {
79 int index = trkIt->index();
80 mask[index] = true;
81 }
82 }
83 }
84
85 // Apply a track selection string.
86 if (!m_trackSelectionString.empty()) {
87 std::vector<int> entries = m_parser[kdvTrackThinning]->evaluateAsVector();
88 unsigned int nEntries = entries.size();
89 // check the sizes are compatible
90 if (nTracks != nEntries ) {
91 ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
92 return StatusCode::FAILURE;
93 }
94 else {
95 // identify which dvs to keep for the thinning check
96 for (unsigned int i=0; i<nEntries; ++i) {
97 if (!mask[i]) continue;
98 if (!entries[i]) mask[i] = false;
99 }
100 }
101 }
102
103
104 // Count up the mask contents
105 unsigned int n_pass=0;
106 for (unsigned int i=0; i<nTracks; ++i) {
107 if (mask[i]) ++n_pass;
108 }
109 m_npass += n_pass;
110
111
112 // Execute the thinning service based on the mask. Finish.
113 importedTrackParticles.keep (mask);
114
115
116 return StatusCode::SUCCESS;
117
118}
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)
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
virtual StatusCode doThinning(const EventContext &ctx) const override
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