ATLAS Offline Software
Loading...
Searching...
No Matches
JetLargeD0TrackParticleThinning.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// JetLargeD0TrackParticleThinning.cxx, (c) ATLAS Detector software
8// Author: Jackson Burzynski (jackson.carl.burzynski@cern.ch)
9// This tool associates InDetLargeD0TrackParticles to jets using a
10// user-defined DeltaR matching.
11// n.b. The standard JetTrackParticleThinning tool will not work
12// for LargeD0 tracks due to the fact that they are not considered
13// when running the ghost association.
14//
15// TODO: implement jet-origin correction under the assumption that
16// the jet originates from a secondary vertex instead of the PV
17
22#include "GaudiKernel/ThreadLocalContext.h"
23#include <vector>
24#include <string>
25
26// Constructor
28 const std::string& n,
29 const IInterface* p ) :
30base_class(t,n,p)
31{
32}
33
34// Destructor
37
38// Athena initialize and finalize
40{
41 // Decide which collections need to be checked for ID TrackParticles
42 ATH_MSG_VERBOSE("initialize() ...");
43 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
44 ATH_MSG_INFO("Using " << m_inDetSGKey << "as the source collection for inner detector track particles");
45 if (m_jetKey.key().empty()) {
46 ATH_MSG_FATAL("No jet collection provided for thinning.");
47 return StatusCode::FAILURE;
48 }
49 ATH_CHECK( m_jetKey.initialize() );
50 ATH_MSG_INFO("Inner detector track particles associated with objects in " << m_jetKey.key() << " will be retained in this format with the rest being thinned away");
51
52 // Set up the text-parsing machinery for selectiong the jet directly according to user cuts
53 if (!m_selectionString.empty() || !m_trackSelectionString.empty()) {
54 // order must match enum order EJetTrPThinningParser
55 ATH_CHECK( initializeParser( {m_selectionString, m_trackSelectionString } ));
56 }
57 return StatusCode::SUCCESS;
58}
59
61{
62 ATH_MSG_VERBOSE("finalize() ...");
63 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
64 return StatusCode::SUCCESS;
65}
66
67// The thinning itself
69{
70 const EventContext& ctx = Gaudi::Hive::currentContext();
71
72 // Retrieve main TrackParticle collection
74 (m_inDetSGKey, ctx);
76
77 // Check the event contains tracks
78 unsigned int nTracks = importedTrackParticles->size();
79 if (nTracks==0) return StatusCode::SUCCESS;
80
81 // Set up a mask with the same entries as the full TrackParticle collection
82 std::vector<bool> mask;
83 mask.assign(nTracks,false); // default: don't keep any tracks
84 m_ntot += nTracks;
85
86 // Retrieve containers
87 // ... jets
89 if (!importedJets.isValid()) {
90 ATH_MSG_ERROR("No jet collection with name " << m_jetKey.key() << " found in StoreGate!");
91 return StatusCode::FAILURE;
92 }
93 unsigned int nJets(importedJets->size());
94 std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
95
96 // Execute the text parser if requested
97 if (!m_selectionString.empty()) {
98 std::vector<int> entries = m_parser[kJetSelection]->evaluateAsVector();
99 unsigned int nEntries = entries.size();
100 // check the sizes are compatible
101 if (nJets != nEntries ) {
102 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used jets??");
103 return StatusCode::FAILURE;
104 } else {
105 // identify which jets to keep for the thinning check
106 for (unsigned int i=0; i<nJets; ++i) if (entries[i]==1) jetToCheck.push_back((*importedJets)[i]);
107 }
108 }
109
110 // Set elements in the mask to true if they are matched to a reconstructed object
111 // ... jets
112 static const SG::AuxElement::ConstAccessor<std::vector<ElementLink<DataVector<xAOD::IParticle> > > > ghostTrackLRT ("GhostTrackLRT");
113
114 if (m_selectionString.empty()) { // check all jets as user didn't provide a selection string
115 for (xAOD::JetContainer::const_iterator jetIt=importedJets->begin(); jetIt!=importedJets->end(); ++jetIt) {
116 const std::vector< ElementLink<DataVector<xAOD::IParticle> > > &jetTrackLinks = ghostTrackLRT( **jetIt );
117 for (const auto &jetTrkIt : jetTrackLinks) {
118 const xAOD::TrackParticle* trackPart = dynamic_cast<const xAOD::TrackParticle*>(*jetTrkIt);
119 int index = trackPart->index();
120 mask[index] = true;
121 }
122 }
123 } else { // check only jets passing user selection string
124 for (std::vector<const xAOD::Jet*>::const_iterator jetIt=jetToCheck.begin(); jetIt!=jetToCheck.end(); ++jetIt) {
125 const std::vector< ElementLink<DataVector<xAOD::IParticle> > > &jetTrackLinks = ghostTrackLRT( **jetIt );
126 for (const auto &jetTrkIt : jetTrackLinks) {
127 const xAOD::TrackParticle* trackPart = dynamic_cast<const xAOD::TrackParticle*>(*jetTrkIt);
128 int index = trackPart->index();
129 mask[index] = true;
130 }
131 }
132 }
133
134 // Apply a track selection string.
135 if (!m_trackSelectionString.empty()) {
136 std::vector<int> entries = m_parser[kTrackThinning]->evaluateAsVector();
137 unsigned int nEntries = entries.size();
138 // check the sizes are compatible
139 if (nTracks != nEntries ) {
140 ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
141 return StatusCode::FAILURE;
142 } else {
143 // identify which jets to keep for the thinning check
144 for (unsigned int i=0; i<nEntries; ++i) {
145 if (!entries[i]) mask[i] = false;
146 }
147 }
148 }
149
150 // Count up the mask contents
151 unsigned int n_pass=0;
152 for (unsigned int i=0; i<nTracks; ++i) {
153 if (mask[i]) ++n_pass;
154 }
155 m_npass += n_pass;
156
157 // Execute the thinning service based on the mask. Finish.
158 importedTrackParticles.keep (mask);
159
160 return StatusCode::SUCCESS;
161}
162
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
Handle for requesting thinning for a data object.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
JetLargeD0TrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
size_t index() const
Return the index of this element within its container.
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
TrackParticle_v1 TrackParticle
Reference the current persistent version: