ATLAS Offline Software
VSITrackParticleThinning.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // VSITrackParticleThinning.cxx, (c) ATLAS Detector software
8 // Authors: Amber Roepe (amber.rebecca.roepe@cern.ch)
9 // Jackson Burzynski (jackson.carl.burzynski@cern.ch)
10 // This is a trivial example of an implementation of a thinning tool
11 // which removes all ID tracks which do not pass a user-defined cut
12 
17 #include "GaudiKernel/ThreadLocalContext.h"
18 #include <vector>
19 #include <string>
20 
21 // Constructor
23  const std::string& n,
24  const IInterface* p ) :
25 base_class(t,n,p)
26 {
27 }
28 
29 // Destructor
31 }
32 
33 // Athena initialize and finalize
35 {
36 
37  // Decide which collections need to be checked for ID TrackParticles
38  ATH_MSG_VERBOSE("initialize() ...");
39  ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
40 
41  // Set up the text-parsing machinery for selectiong the dv directly according to user cuts
42  if (!m_trackSelectionString.empty()) {
43  // order must match enum order EJetTrPThinningParser
44  ATH_CHECK( initializeParser( { m_selectionString, m_trackSelectionString } ));
45  }
46 
47  return StatusCode::SUCCESS;
48 }
49 
51 {
52  ATH_MSG_VERBOSE("finalize() ...");
53  ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
54  return StatusCode::SUCCESS;
55 }
56 
57 // The thinning itself
59 {
60 
61  const EventContext& ctx = Gaudi::Hive::currentContext();
62 
63  // Retrieve main TrackParticle collection
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  // Set elements in the mask to true if associated with a DV
77  for ( const auto trkIt: *importedTrackParticles ) {
78  for ( const auto &augVerString: m_augVerStrings) {
79  SG::ConstAccessor<char> acc("is_svtrk_final" + augVerString);
80  if (acc.withDefault (*trkIt, false)) {
81  int index = trkIt->index();
82  mask[index] = true;
83  }
84  }
85  }
86 
87  // Apply a track selection string.
88  if (!m_trackSelectionString.empty()) {
89  std::vector<int> entries = m_parser[kdvTrackThinning]->evaluateAsVector();
90  unsigned int nEntries = entries.size();
91  // check the sizes are compatible
92  if (nTracks != nEntries ) {
93  ATH_MSG_ERROR("Sizes incompatible! Are you sure your track selection string used tracks??");
94  return StatusCode::FAILURE;
95  }
96  else {
97  // identify which dvs to keep for the thinning check
98  for (unsigned int i=0; i<nEntries; ++i) {
99  if (!mask[i]) continue;
100  if (!entries[i]) mask[i] = false;
101  }
102  }
103  }
104 
105 
106  // Count up the mask contents
107  unsigned int n_pass=0;
108  for (unsigned int i=0; i<nTracks; ++i) {
109  if (mask[i]) ++n_pass;
110  }
111  m_npass += n_pass;
112 
113 
114  // Execute the thinning service based on the mask. Finish.
115  importedTrackParticles.keep (mask);
116 
117 
118  return StatusCode::SUCCESS;
119 
120 }
121 
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ThinningHandle.h
Handle for requesting thinning for a data object.
index
Definition: index.py:1
SG::ConstAccessor< char >
DerivationFramework::VSITrackParticleThinning::finalize
virtual StatusCode finalize() override
Definition: VSITrackParticleThinning.cxx:50
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
DerivationFramework::VSITrackParticleThinning::VSITrackParticleThinning
VSITrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition: VSITrackParticleThinning.cxx:22
DerivationFramework::kdvTrackThinning
@ kdvTrackThinning
Definition: VSITrackParticleThinning.h:28
DerivationFramework::VSITrackParticleThinning::initialize
virtual StatusCode initialize() override
Definition: VSITrackParticleThinning.cxx:34
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::VSITrackParticleThinning::doThinning
virtual StatusCode doThinning() const override
Definition: VSITrackParticleThinning.cxx:58
DerivationFramework::VSITrackParticleThinning::~VSITrackParticleThinning
virtual ~VSITrackParticleThinning()
Definition: VSITrackParticleThinning.cxx:30
DeMoScan.index
string index
Definition: DeMoScan.py:362
VertexContainer.h
VSITrackParticleThinning.h
entries
double entries
Definition: listroot.cxx:49
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
TrackParticleContainer.h