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 <vector>
23#include <string>
24
25// Constructor
27 const std::string& n,
28 const IInterface* p ) :
29base_class(t,n,p)
30{
31}
32
33// Destructor
36
37// Athena initialize and finalize
39{
40 // Decide which collections need to be checked for ID TrackParticles
41 ATH_MSG_VERBOSE("initialize() ...");
42 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
43 ATH_MSG_INFO("Using " << m_inDetSGKey << "as the source collection for inner detector track particles");
44 if (m_jetKey.key().empty()) {
45 ATH_MSG_FATAL("No jet collection provided for thinning.");
46 return StatusCode::FAILURE;
47 }
48 ATH_CHECK( m_jetKey.initialize() );
49 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");
50
51 // Set up the text-parsing machinery for selectiong the jet directly according to user cuts
52 if (!m_selectionString.empty() || !m_trackSelectionString.empty()) {
53 // order must match enum order EJetTrPThinningParser
54 ATH_CHECK( initializeParser( {m_selectionString, m_trackSelectionString } ));
55 }
56 return StatusCode::SUCCESS;
57}
58
60{
61 ATH_MSG_VERBOSE("finalize() ...");
62 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
63 return StatusCode::SUCCESS;
64}
65
66// The thinning itself
68{
69
70 // Retrieve main TrackParticle collection
72 (m_inDetSGKey, ctx);
74
75 // Check the event contains tracks
76 unsigned int nTracks = importedTrackParticles->size();
77 if (nTracks==0) return StatusCode::SUCCESS;
78
79 // Set up a mask with the same entries as the full TrackParticle collection
80 std::vector<bool> mask;
81 mask.assign(nTracks,false); // default: don't keep any tracks
82 m_ntot += nTracks;
83
84 // Retrieve containers
85 // ... jets
87 if (!importedJets.isValid()) {
88 ATH_MSG_ERROR("No jet collection with name " << m_jetKey.key() << " found in StoreGate!");
89 return StatusCode::FAILURE;
90 }
91 unsigned int nJets(importedJets->size());
92 std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
93
94 // Execute the text parser if requested
95 if (!m_selectionString.empty()) {
96 std::vector<int> entries = m_parser[kJetSelection]->evaluateAsVector();
97 unsigned int nEntries = entries.size();
98 // check the sizes are compatible
99 if (nJets != nEntries ) {
100 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used jets??");
101 return StatusCode::FAILURE;
102 } else {
103 // identify which jets to keep for the thinning check
104 for (unsigned int i=0; i<nJets; ++i) if (entries[i]==1) jetToCheck.push_back((*importedJets)[i]);
105 }
106 }
107
108 // Set elements in the mask to true if they are matched to a reconstructed object
109 // ... jets
110 static const SG::AuxElement::ConstAccessor<std::vector<ElementLink<DataVector<xAOD::IParticle> > > > ghostTrackLRT ("GhostTrackLRT");
111
112 if (m_selectionString.empty()) { // check all jets as user didn't provide a selection string
113 for (xAOD::JetContainer::const_iterator jetIt=importedJets->begin(); jetIt!=importedJets->end(); ++jetIt) {
114 const std::vector< ElementLink<DataVector<xAOD::IParticle> > > &jetTrackLinks = ghostTrackLRT( **jetIt );
115 for (const auto &jetTrkIt : jetTrackLinks) {
116 const xAOD::TrackParticle* trackPart = dynamic_cast<const xAOD::TrackParticle*>(*jetTrkIt);
117 int index = trackPart->index();
118 mask[index] = true;
119 }
120 }
121 } else { // check only jets passing user selection string
122 for (std::vector<const xAOD::Jet*>::const_iterator jetIt=jetToCheck.begin(); jetIt!=jetToCheck.end(); ++jetIt) {
123 const std::vector< ElementLink<DataVector<xAOD::IParticle> > > &jetTrackLinks = ghostTrackLRT( **jetIt );
124 for (const auto &jetTrkIt : jetTrackLinks) {
125 const xAOD::TrackParticle* trackPart = dynamic_cast<const xAOD::TrackParticle*>(*jetTrkIt);
126 int index = trackPart->index();
127 mask[index] = true;
128 }
129 }
130 }
131
132 // Apply a track selection string.
133 if (!m_trackSelectionString.empty()) {
134 std::vector<int> entries = m_parser[kTrackThinning]->evaluateAsVector();
135 unsigned int nEntries = entries.size();
136 // check the sizes are compatible
137 if (nTracks != nEntries ) {
138 ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
139 return StatusCode::FAILURE;
140 } else {
141 // identify which jets to keep for the thinning check
142 for (unsigned int i=0; i<nEntries; ++i) {
143 if (!entries[i]) mask[i] = false;
144 }
145 }
146 }
147
148 // Count up the mask contents
149 unsigned int n_pass=0;
150 for (unsigned int i=0; i<nTracks; ++i) {
151 if (mask[i]) ++n_pass;
152 }
153 m_npass += n_pass;
154
155 // Execute the thinning service based on the mask. Finish.
156 importedTrackParticles.keep (mask);
157
158 return StatusCode::SUCCESS;
159}
160
#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
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
TrackParticle_v1 TrackParticle
Reference the current persistent version: