ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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 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 21 of file JetTrackParticleThinning.cxx.

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

◆ ~JetTrackParticleThinning()

DerivationFramework::JetTrackParticleThinning::~JetTrackParticleThinning ( )
virtualdefault

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::JetTrackParticleThinning::doThinning ( ) const
overridevirtual

Definition at line 61 of file JetTrackParticleThinning.cxx.

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

◆ finalize()

StatusCode DerivationFramework::JetTrackParticleThinning::finalize ( )
overridevirtual

Definition at line 53 of file JetTrackParticleThinning.cxx.

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

◆ initialize()

StatusCode DerivationFramework::JetTrackParticleThinning::initialize ( )
overridevirtual

Definition at line 32 of file JetTrackParticleThinning.cxx.

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

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.

◆ m_jetKey

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

Definition at line 39 of file JetTrackParticleThinning.h.

◆ m_npass

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

Definition at line 38 of file JetTrackParticleThinning.h.

◆ m_ntot

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

Definition at line 37 of file JetTrackParticleThinning.h.

◆ m_selectionString

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

Definition at line 46 of file JetTrackParticleThinning.h.

◆ m_streamName

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

Definition at line 42 of file JetTrackParticleThinning.h.

◆ m_trackSelectionString

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

Definition at line 48 of file JetTrackParticleThinning.h.


The documentation for this class was generated from the following files:
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::JetTrackParticleThinning::m_npass
std::atomic< unsigned int > m_npass
Definition: JetTrackParticleThinning.h:38
DerivationFramework::JetTrackParticleThinning::m_inDetSGKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
Definition: JetTrackParticleThinning.h:45
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
index
Definition: index.py:1
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::JetTrackParticleThinning::m_trackSelectionString
StringProperty m_trackSelectionString
Definition: JetTrackParticleThinning.h:49
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::JetTrackParticleThinning::m_jetKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetKey
Definition: JetTrackParticleThinning.h:40
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::kTrackThinning
@ kTrackThinning
Definition: JetTrackParticleThinning.h:27
DerivationFramework::kJetSelection
@ kJetSelection
Definition: JetTrackParticleThinning.h:27
DerivationFramework::JetTrackParticleThinning::m_selectionString
StringProperty m_selectionString
Definition: JetTrackParticleThinning.h:47
DerivationFramework::JetTrackParticleThinning::m_streamName
StringProperty m_streamName
Definition: JetTrackParticleThinning.h:43
DeMoScan.index
string index
Definition: DeMoScan.py:364
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
entries
double entries
Definition: listroot.cxx:49
DerivationFramework::JetTrackParticleThinning::m_ntot
std::atomic< unsigned int > m_ntot
Definition: JetTrackParticleThinning.h:37
xAOD::JetAttribute::GhostTrack
@ GhostTrack
Definition: JetAttributes.h:252
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73