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 "GaudiKernel/ThreadLocalContext.h"
16#include <vector>
17#include <string>
18
19// Constructor
21 const std::string& n,
22 const IInterface* p ) :
23base_class(t,n,p)
24{}
25
26// Destructor
28
29// Athena initialize and finalize
31{
32 // Decide which collections need to be checked for ID TrackParticles
33 ATH_MSG_VERBOSE("initialize() ...");
34 ATH_CHECK( m_ditauKey.initialize () );
35 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
36 ATH_MSG_INFO("Using " << m_inDetSGKey.key() << "as the source collection for inner detector track particles");
37 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");
38
39 // Set up the text-parsing machinery for selectiong the ditau directly according to user cuts
40 if (!m_selectionString.empty()) {
41 ATH_CHECK(initializeParser(m_selectionString));
42 }
43 return StatusCode::SUCCESS;
44}
45
47{
48 ATH_MSG_VERBOSE("finalize() ...");
49 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
50 ATH_CHECK( finalizeParser() );
51 return StatusCode::SUCCESS;
52}
53
54// The thinning itself
56{
57
58 const EventContext& ctx = Gaudi::Hive::currentContext();
59
60 // Retrieve main TrackParticle collection
62 (m_inDetSGKey, ctx);
63
64 // Check the event contains tracks
65 unsigned int nTracks = importedTrackParticles->size();
66 if (nTracks==0) return StatusCode::SUCCESS;
67
68 // Set up a mask with the same entries as the full TrackParticle collection
69 std::vector<bool> mask;
70 mask.assign(nTracks,false); // default: don't keep any tracks
71 m_ntot += nTracks;
72
73 // Retrieve containers
74 // ... ditaus
76 if (!importedDiTaus.isValid()) {
77 ATH_MSG_ERROR("No ditau collection with name " << m_ditauKey.key() << " found in StoreGate!");
78 return StatusCode::FAILURE;
79 }
80 unsigned int nDiTaus(importedDiTaus->size());
81 std::vector<const xAOD::DiTauJet*> ditauToCheck; ditauToCheck.clear();
82
83 // Execute the text parser if requested
84 if (!m_selectionString.empty()) {
85 std::vector<int> entries = m_parser->evaluateAsVector();
86 unsigned int nEntries = entries.size();
87 // check the sizes are compatible
88 if (nDiTaus != nEntries ) {
89 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used ditaus??");
90 return StatusCode::FAILURE;
91 } else {
92 // identify which ditaus to keep for the thinning check
93 for (unsigned int i=0; i<nDiTaus; ++i) if (entries[i]==1) ditauToCheck.push_back((*importedDiTaus)[i]);
94 }
95 }
96
97 // Set elements in the mask to true if there is a corresponding ElementLink from a reconstructed object
98 // ... ditaus
99 if (m_selectionString=="") { // check all ditaus as user didn't provide a selection string
100 for (const auto *ditauIt : *importedDiTaus) {
101 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
102 int index = ditauIt->trackLinks().at(i).index();
103 mask[index] = true;
104 }
105 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
106 int index = ditauIt->isoTrackLinks().at(i).index();
107 mask[index] = true;
108 }
109 }
110 } else { // check only ditaus passing user selection string
111 for (auto & ditauIt : ditauToCheck) {
112 for (unsigned int i=0; i<ditauIt->nTracks(); ++i) {
113 int index = ditauIt->trackLinks().at(i).index();
114 mask[index] = true;
115 }
116 for (unsigned int i=0; i<ditauIt->nIsoTracks(); ++i) {
117 int index = ditauIt->isoTrackLinks().at(i).index();
118 mask[index] = true;
119 }
120 }
121 }
122
123 // Count up the mask contents
124 unsigned int n_pass=0;
125 for (unsigned int i=0; i<nTracks; ++i) {
126 if (mask[i]) ++n_pass;
127 }
128 m_npass += n_pass;
129
130 // Execute the thinning service based on the mask. Finish.
131 importedTrackParticles.keep (mask);
132
133 return StatusCode::SUCCESS;
134}
135
#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 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