ATLAS Offline Software
SV1TrackThinning.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SV1TrackThinning.cxx, (c) ATLAS Detector software
8 
10 #include "xAODJet/JetContainer.h"
12 #include "xAODBTagging/BTagging.h"
15 #include "GaudiKernel/ThreadLocalContext.h"
16 #include <vector>
17 #include <string>
18 
19 // Constructor
21  const std::string& n,
22  const IInterface* p ) :
23  base_class(t,n,p),
24  m_ntot(0),
25  m_npass(0),
26  m_jetSGKey(""),
27  m_selectionString("")
28 {
29  declareProperty("JetKey", m_jetSGKey);
30  declareProperty("SelectionString", m_selectionString);
31 }
32 
33 // Destructor
35 }
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_jetSGKey=="") {
45  ATH_MSG_FATAL("No jet collection provided for thinning.");
46  return StatusCode::FAILURE;
47  } else { ATH_MSG_INFO("Inner detector track particles associated with objects in " << m_jetSGKey << " will be retained in this format with the rest being thinned away");}
48 
49  // Set up the text-parsing machinery for selectiong the jet directly according to user cuts
50  if (!m_selectionString.empty()) {
51  ATH_CHECK(initializeParser(m_selectionString) );
52  }
53  return StatusCode::SUCCESS;
54 }
55 
57 {
58  ATH_MSG_VERBOSE("finalize() ...");
59  ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
60  ATH_CHECK(finalizeParser() );
61  return StatusCode::SUCCESS;
62 }
63 
64 // The thinning itself
66 {
67  const EventContext& ctx = Gaudi::Hive::currentContext();
68 
69  // Retrieve main TrackParticle collection
71  (m_inDetSGKey, ctx);
72 
73  // Check the event contains tracks
74  unsigned int nTracks = importedTrackParticles->size();
75  if (nTracks==0) return StatusCode::SUCCESS;
76 
77  // Set up a mask with the same entries as the full TrackParticle collection
78  std::vector<bool> mask;
79  mask.assign(nTracks, false); // default: don't keep any tracks
80  m_ntot += nTracks;
81 
82  const xAOD::JetContainer* importedJets(0);
83  if (evtStore()->retrieve(importedJets,m_jetSGKey).isFailure()) {
84  ATH_MSG_ERROR("No jet collection with name " << m_jetSGKey << " found in StoreGate!");
85  return StatusCode::FAILURE;
86  }
87 
88  unsigned int nJets(importedJets->size());
89  std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
90 
91  // Execute the text parser if requested
92  if (!m_selectionString.empty()) {
93  std::vector<int> entries = m_parser->evaluateAsVector();
94  unsigned int nEntries = entries.size();
95  // check the sizes are compatible
96  if (nJets != nEntries ) {
97  ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used jets??");
98  return StatusCode::FAILURE;
99  } else {
100  // identify which jets to keep for the thinning check
101  for (unsigned int i=0; i<nJets; ++i) if (entries[i]==1) jetToCheck.push_back((*importedJets)[i]);
102  }
103  }
104 
105  // Retrieve containers
106  // ... jets
107  if (m_selectionString=="") { // check all jets as user didn't provide a selection string
108  for (xAOD::JetContainer::const_iterator jetIt=importedJets->begin(); jetIt!=importedJets->end(); ++jetIt) {
109  const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging( **jetIt );
110  const std::vector< ElementLink<xAOD::TrackParticleContainer> >& SV1_trackParticleLinks =
111  btag->SV1_TrackParticleLinks();
112 
113 
114  for (const ElementLink<xAOD::TrackParticleContainer> &tp : SV1_trackParticleLinks) {
115  int index = (*tp)->index();
116  mask[index] = true;
117  }
118  }
119  } else { // check only jets passing user selection string
120  for (std::vector<const xAOD::Jet*>::iterator jetIt = jetToCheck.begin(); jetIt!=jetToCheck.end(); ++jetIt) {
121  const xAOD::BTagging* btag = xAOD::BTaggingUtilities::getBTagging( **jetIt );
122  const std::vector< ElementLink<xAOD::TrackParticleContainer> >& SV1_trackParticleLinks =
123  btag->SV1_TrackParticleLinks();
124 
125 
126  for (const ElementLink<xAOD::TrackParticleContainer> &tp : SV1_trackParticleLinks) {
127  int index = (*tp)->index();
128  mask[index] = true;
129  }
130  }
131  }
132 
133  // Count up the mask contents
134  for (unsigned int i=0; i<nTracks; ++i) {
135  if (mask[i]) ++m_npass;
136  }
137 
138  // Execute the thinning service based on the mask. Finish.
139  importedTrackParticles.keep (mask);
140 
141  return StatusCode::SUCCESS;
142 }
143 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
BTaggingUtilities.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
BTagging.h
ThinningHandle.h
Handle for requesting thinning for a data object.
index
Definition: index.py:1
ParticleTest.tp
tp
Definition: ParticleTest.py:25
DerivationFramework::SV1TrackThinning::m_jetSGKey
std::string m_jetSGKey
Definition: SV1TrackThinning.h:39
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
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:68
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::BTagging_v1::SV1_TrackParticleLinks
const TPELVec_t & SV1_TrackParticleLinks() const
get vector of SV1 TrackParticle ElementLinks
Definition: BTagging_v1.cxx:106
DerivationFramework::SV1TrackThinning::finalize
virtual StatusCode finalize() override
Definition: SV1TrackThinning.cxx:56
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework::SV1TrackThinning::~SV1TrackThinning
~SV1TrackThinning()
Definition: SV1TrackThinning.cxx:34
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::BTaggingUtilities::getBTagging
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Definition: BTaggingUtilities.cxx:37
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DeMoScan.index
string index
Definition: DeMoScan.py:364
JetContainer.h
SV1TrackThinning.h
entries
double entries
Definition: listroot.cxx:49
DerivationFramework::SV1TrackThinning::doThinning
virtual StatusCode doThinning() const override
Definition: SV1TrackThinning.cxx:65
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
DerivationFramework::SV1TrackThinning::m_selectionString
std::string m_selectionString
Definition: SV1TrackThinning.h:39
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::SV1TrackThinning::SV1TrackThinning
SV1TrackThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition: SV1TrackThinning.cxx:20
TrackParticleContainer.h
DerivationFramework::SV1TrackThinning::initialize
virtual StatusCode initialize() override
Definition: SV1TrackThinning.cxx:38
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.