ATLAS Offline Software
Loading...
Searching...
No Matches
DiTauTrackParticleThinning.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// DiTauTrackParticleThinning.cxx, (c) ATLAS Detector software
8// Author: James Catmore (James.Catmore@cern.ch)
9// This is a trivial example of an implementation of a thinning tool
10// which removes all ID tracks which do not pass a user-defined cut
11
15#include <vector>
16#include <string>
17
18// Constructor
20 const std::string& n,
21 const IInterface* p ) :
22base_class(t,n,p)
23{}
24
25// Destructor
27
28// Athena initialize and finalize
30{
31 // Decide which collections need to be checked for ID TrackParticles
32 ATH_MSG_VERBOSE("initialize() ...");
33 ATH_CHECK( m_ditauKey.initialize () );
34 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
35 ATH_MSG_INFO("Using " << m_inDetSGKey.key() << "as the source collection for inner detector track particles");
36 ATH_MSG_INFO("Inner detector track particles associated with objects in " << m_ditauKey.key() << " will be retained in this format with the rest being thinned away");
37
38 // Set up the text-parsing machinery for selectiong the ditau directly according to user cuts
39 if (!m_selectionString.empty()) {
40 ATH_CHECK(initializeParser(m_selectionString));
41 }
42 return StatusCode::SUCCESS;
43}
44
46{
47 ATH_MSG_VERBOSE("finalize() ...");
48 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
49 ATH_CHECK( finalizeParser() );
50 return StatusCode::SUCCESS;
51}
52
53// The thinning itself
54StatusCode DerivationFramework::DiTauTrackParticleThinning::doThinning(const EventContext& ctx) const
55{
56
57
58 // Retrieve main TrackParticle collection
60 (m_inDetSGKey, ctx);
61
62 // Check the event contains tracks
63 unsigned int nTracks = importedTrackParticles->size();
64 if (nTracks==0) return StatusCode::SUCCESS;
65
66 // Set up a mask with the same entries as the full TrackParticle collection
67 std::vector<bool> mask(nTracks);
68 m_ntot += nTracks;
69
70 // Retrieve containers
71 // ... ditaus
73 if (!importedDiTaus.isValid()) {
74 ATH_MSG_ERROR("No ditau collection with name " << m_ditauKey.key() << " found in StoreGate!");
75 return StatusCode::FAILURE;
76 }
77 unsigned int nDiTaus(importedDiTaus->size());
78 std::vector<const xAOD::DiTauJet*> ditauToCheck; ditauToCheck.clear();
79
80 // Execute the text parser if requested
81 if (!m_selectionString.empty()) {
82 std::vector<int> entries = m_parser->evaluateAsVector();
83 unsigned int nEntries = entries.size();
84 // check the sizes are compatible
85 if (nDiTaus != nEntries ) {
86 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used ditaus??");
87 return StatusCode::FAILURE;
88 } else {
89 // identify which ditaus to keep for the thinning check
90 for (unsigned int i=0; i<nDiTaus; ++i) if (entries[i]==1) ditauToCheck.push_back((*importedDiTaus)[i]);
91 }
92 }
93
94 // Set elements in the mask to true if there is a corresponding ElementLink from a reconstructed object
95 // ... ditaus
96 if (m_selectionString=="") { // check all ditaus as user didn't provide a selection string
97 for (const auto *ditauIt : *importedDiTaus) {
98 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
99 std::size_t index = ditauIt->trackLinks().at(i).index();
100 mask.at(index) = true;
101 }
102 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
103 std::size_t index = ditauIt->isoTrackLinks().at(i).index();
104 mask.at(index) = true;
105 }
106 }
107 } else { // check only ditaus passing user selection string
108 for (auto & ditauIt : ditauToCheck) {
109 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
110 std::size_t index = ditauIt->trackLinks().at(i).index();
111 mask.at(index) = true;
112 }
113 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
114 std::size_t index = ditauIt->isoTrackLinks().at(i).index();
115 mask.at(index) = true;
116 }
117 }
118 }
119
120 // Count up the mask contents
121 unsigned int n_pass=0;
122 for (unsigned int i=0; i<nTracks; ++i) {
123 if (mask[i]) ++n_pass;
124 }
125 m_npass += n_pass;
126
127 // Execute the thinning service based on the mask. Finish.
128 importedTrackParticles.keep (mask);
129
130 return StatusCode::SUCCESS;
131}
132
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
Handle for requesting thinning for a data object.
SG::ReadHandleKey< xAOD::DiTauJetContainer > m_ditauKey
DiTauTrackParticleThinning(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
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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