ATLAS Offline Software
Loading...
Searching...
No Matches
DiTauTrackParticleThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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;
68 mask.assign(nTracks,false); // default: don't keep any tracks
69 m_ntot += nTracks;
70
71 // Retrieve containers
72 // ... ditaus
74 if (!importedDiTaus.isValid()) {
75 ATH_MSG_ERROR("No ditau collection with name " << m_ditauKey.key() << " found in StoreGate!");
76 return StatusCode::FAILURE;
77 }
78 unsigned int nDiTaus(importedDiTaus->size());
79 std::vector<const xAOD::DiTauJet*> ditauToCheck; ditauToCheck.clear();
80
81 // Execute the text parser if requested
82 if (!m_selectionString.empty()) {
83 std::vector<int> entries = m_parser->evaluateAsVector();
84 unsigned int nEntries = entries.size();
85 // check the sizes are compatible
86 if (nDiTaus != nEntries ) {
87 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used ditaus??");
88 return StatusCode::FAILURE;
89 } else {
90 // identify which ditaus to keep for the thinning check
91 for (unsigned int i=0; i<nDiTaus; ++i) if (entries[i]==1) ditauToCheck.push_back((*importedDiTaus)[i]);
92 }
93 }
94
95 // Set elements in the mask to true if there is a corresponding ElementLink from a reconstructed object
96 // ... ditaus
97 if (m_selectionString=="") { // check all ditaus as user didn't provide a selection string
98 for (const auto *ditauIt : *importedDiTaus) {
99 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
100 int index = ditauIt->trackLinks().at(i).index();
101 mask[index] = true;
102 }
103 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
104 int index = ditauIt->isoTrackLinks().at(i).index();
105 mask[index] = true;
106 }
107 }
108 } else { // check only ditaus passing user selection string
109 for (auto & ditauIt : ditauToCheck) {
110 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
111 int index = ditauIt->trackLinks().at(i).index();
112 mask[index] = true;
113 }
114 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
115 int index = ditauIt->isoTrackLinks().at(i).index();
116 mask[index] = true;
117 }
118 }
119 }
120
121 // Count up the mask contents
122 unsigned int n_pass=0;
123 for (unsigned int i=0; i<nTracks; ++i) {
124 if (mask[i]) ++n_pass;
125 }
126 m_npass += n_pass;
127
128 // Execute the thinning service based on the mask. Finish.
129 importedTrackParticles.keep (mask);
130
131 return StatusCode::SUCCESS;
132}
133
#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.
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