ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::JetTrackParticleThinning Class Reference

#include <JetTrackParticleThinning.h>

Inheritance diagram for DerivationFramework::JetTrackParticleThinning:
Collaboration diagram for DerivationFramework::JetTrackParticleThinning:

Public Member Functions

 JetTrackParticleThinning (const std::string &t, const std::string &n, const IInterface *p)
virtual ~JetTrackParticleThinning ()
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode doThinning (const EventContext &ctx) const override

Private Attributes

std::atomic< unsigned int > m_ntot {}
std::atomic< unsigned int > m_npass {}
SG::ReadHandleKey< xAOD::JetContainerm_jetKey { this, "JetKey", "", ""}
StringProperty m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
SG::ThinningHandleKey< xAOD::TrackParticleContainerm_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
StringProperty m_selectionString { this, "SelectionString", "", "" }
StringProperty m_trackSelectionString { this, "TrackSelectionString", "", "" }

Detailed Description

Definition at line 28 of file JetTrackParticleThinning.h.

Constructor & Destructor Documentation

◆ JetTrackParticleThinning()

DerivationFramework::JetTrackParticleThinning::JetTrackParticleThinning ( const std::string & t,
const std::string & n,
const IInterface * p )

Definition at line 20 of file JetTrackParticleThinning.cxx.

22 :
23base_class(t,n,p)
24{
25}

◆ ~JetTrackParticleThinning()

DerivationFramework::JetTrackParticleThinning::~JetTrackParticleThinning ( )
virtualdefault

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::JetTrackParticleThinning::doThinning ( const EventContext & ctx) const
overridevirtual

Definition at line 60 of file JetTrackParticleThinning.cxx.

61{
62
63 // Retrieve main TrackParticle collection
64 SG::ThinningHandle<xAOD::TrackParticleContainer> importedTrackParticles
65 (m_inDetSGKey, ctx);
66
67 // Check the event contains tracks
68 unsigned int nTracks = importedTrackParticles->size();
69 if (nTracks==0) return StatusCode::SUCCESS;
70
71 // Set up a mask with the same entries as the full TrackParticle collection
72 std::vector<bool> mask;
73 mask.assign(nTracks,false); // default: don't keep any tracks
74 m_ntot += nTracks;
75
76 // Retrieve containers
77 // ... jets
78 SG::ReadHandle<xAOD::JetContainer> importedJets(m_jetKey,ctx);
79 if (!importedJets.isValid()) {
80 ATH_MSG_ERROR("No jet collection with name " << m_jetKey.key() << " found in StoreGate!");
81 return StatusCode::FAILURE;
82 }
83 unsigned int nJets(importedJets->size());
84 std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
85
86 // Execute the text parser if requested
87 if (!m_selectionString.empty()) {
88 std::vector<int> entries = m_parser[kJetSelection]->evaluateAsVector();
89 unsigned int nEntries = entries.size();
90 // check the sizes are compatible
91 if (nJets != nEntries ) {
92 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used jets??");
93 return StatusCode::FAILURE;
94 } else {
95 // identify which jets to keep for the thinning check
96 for (unsigned int i=0; i<nJets; ++i) if (entries[i]==1) jetToCheck.push_back((*importedJets)[i]);
97 }
98 }
99
100 // Set elements in the mask to true if there is a corresponding ElementLink from a reconstructed object
101 // ... jets
102 if (m_selectionString.empty()) { // check all jets as user didn't provide a selection string
103 for (const auto *jetIt : *importedJets) {
104 std::vector<const xAOD::TrackParticle*> jetTracks;
105 bool haveJetTracks = jetIt->getAssociatedObjects(xAOD::JetAttribute::GhostTrack, jetTracks);
106 if ( !haveJetTracks ) {ATH_MSG_WARNING("Associated tracks not found");}
107 else {
108 for (auto & jetTrack : jetTracks) {
109 int index = jetTrack->index();
110 mask[index] = true;
111 }
112 }
113 }
114 } else { // check only jets passing user selection string
115 for (auto & jetIt : jetToCheck) {
116 std::vector<const xAOD::TrackParticle*> jetTracks;
117 bool haveJetTracks = jetIt->getAssociatedObjects(xAOD::JetAttribute::GhostTrack, jetTracks);
118 if ( !haveJetTracks ) {ATH_MSG_WARNING("Associated tracks not found");}
119 else {
120 for (auto & jetTrack : jetTracks) {
121 int index = jetTrack->index();
122 mask[index] = true;
123 }
124 }
125 }
126 }
127
128 // Apply a track selection string.
129 if (!m_trackSelectionString.empty()) {
130 std::vector<int> entries = m_parser[kTrackThinning]->evaluateAsVector();
131 unsigned int nEntries = entries.size();
132 // check the sizes are compatible
133 if (nTracks != nEntries ) {
134 ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
135 return StatusCode::FAILURE;
136 } else {
137 // identify which jets to keep for the thinning check
138 for (unsigned int i=0; i<nEntries; ++i) {
139 if (!entries[i]) mask[i] = false;
140 }
141 }
142 }
143
144 // Count up the mask contents
145 unsigned int n_pass=0;
146 for (unsigned int i=0; i<nTracks; ++i) {
147 if (mask[i]) ++n_pass;
148 }
149 m_npass += n_pass;
150
151 // Execute the thinning service based on the mask. Finish.
152 importedTrackParticles.keep (mask);
153
154 return StatusCode::SUCCESS;
155}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
SG::ReadHandleKey< xAOD::JetContainer > m_jetKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
double entries
Definition listroot.cxx:49
str index
Definition DeMoScan.py:362

◆ finalize()

StatusCode DerivationFramework::JetTrackParticleThinning::finalize ( )
overridevirtual

Definition at line 52 of file JetTrackParticleThinning.cxx.

53{
54 ATH_MSG_VERBOSE("finalize() ...");
55 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
56 return StatusCode::SUCCESS;
57}
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)

◆ initialize()

StatusCode DerivationFramework::JetTrackParticleThinning::initialize ( )
overridevirtual

Definition at line 31 of file JetTrackParticleThinning.cxx.

32{
33 // Decide which collections need to be checked for ID TrackParticles
34 ATH_MSG_VERBOSE("initialize() ...");
35 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
36 ATH_MSG_INFO("Using " << m_inDetSGKey << "as the source collection for inner detector track particles");
37 if (m_jetKey.key().empty()) {
38 ATH_MSG_FATAL("No jet collection provided for thinning.");
39 return StatusCode::FAILURE;
40 }
41 ATH_CHECK( m_jetKey.initialize() );
42 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");
43
44 // Set up the text-parsing machinery for selectiong the jet directly according to user cuts
45 if (!m_selectionString.empty() || !m_trackSelectionString.empty()) {
46 // order must match enum order EJetTrPThinningParser
47 ATH_CHECK( initializeParser( {m_selectionString, m_trackSelectionString } ));
48 }
49 return StatusCode::SUCCESS;
50}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)

Member Data Documentation

◆ m_inDetSGKey

SG::ThinningHandleKey<xAOD::TrackParticleContainer> DerivationFramework::JetTrackParticleThinning::m_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
private

Definition at line 44 of file JetTrackParticleThinning.h.

45{ this, "InDetTrackParticlesKey", "InDetTrackParticles", "" };

◆ m_jetKey

SG::ReadHandleKey<xAOD::JetContainer> DerivationFramework::JetTrackParticleThinning::m_jetKey { this, "JetKey", "", ""}
private

Definition at line 39 of file JetTrackParticleThinning.h.

40{ this, "JetKey", "", ""};

◆ m_npass

std::atomic<unsigned int> DerivationFramework::JetTrackParticleThinning::m_npass {}
mutableprivate

Definition at line 38 of file JetTrackParticleThinning.h.

38{};

◆ m_ntot

std::atomic<unsigned int> DerivationFramework::JetTrackParticleThinning::m_ntot {}
mutableprivate

Definition at line 37 of file JetTrackParticleThinning.h.

37{};

◆ m_selectionString

StringProperty DerivationFramework::JetTrackParticleThinning::m_selectionString { this, "SelectionString", "", "" }
private

Definition at line 46 of file JetTrackParticleThinning.h.

47{ this, "SelectionString", "", "" };

◆ m_streamName

StringProperty DerivationFramework::JetTrackParticleThinning::m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
private

Definition at line 42 of file JetTrackParticleThinning.h.

43{ this, "StreamName", "", "Name of the stream being thinned" };

◆ m_trackSelectionString

StringProperty DerivationFramework::JetTrackParticleThinning::m_trackSelectionString { this, "TrackSelectionString", "", "" }
private

Definition at line 48 of file JetTrackParticleThinning.h.

49{ this, "TrackSelectionString", "", "" };

The documentation for this class was generated from the following files: