ATLAS Offline Software
GNNAuxTaskDecoratorAlg.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 
9 
12 
13 #include <vector>
14 #include <map>
15 
16 namespace FlavorTagDiscriminants {
18  const std::string& name, ISvcLocator* svcloc):
20  {
21  }
23  ATH_CHECK(m_jetContainerKey.initialize());
25 
27  ATH_CHECK(m_trackLinksKey.initialize());
28 
30  m_readDecorKeys.reserve(m_trackAuxTasks.size());
31  for (std::pair<std::string,std::string> auxTask : m_trackAuxTasks) {
32  SG::WriteDecorHandleKey<xAOD::TrackParticleContainer>& trackAuxTaskDecorKey = m_trackAuxTasksDecorKeys.emplace_back(this, name()+auxTask.second, m_trackContainerKey.key()+"."+auxTask.second, "");
33  SG::ReadDecorHandleKey<xAOD::BTaggingContainer>& readDecorKey = m_readDecorKeys.emplace_back(this, name()+auxTask.first, m_jetContainerKey.key()+"."+auxTask.first, "");
34  ATH_CHECK(trackAuxTaskDecorKey.initialize());
35  ATH_CHECK(readDecorKey.initialize());
36  }
37 
38  return StatusCode::SUCCESS;
39  }
40 
41  StatusCode GNNAuxTaskDecoratorAlg::execute(const EventContext& ctx) const {
42  // define the required WriteDecorHandle objects
43  std::vector<SG::WriteDecorHandle<xAOD::TrackParticleContainer, char>> track_wdhs;
44  for (const auto& wdhk: m_trackAuxTasksDecorKeys) {
45  track_wdhs.emplace_back(wdhk, ctx);
46  }
47 
48  // define the required ReadDecorHandle objects
49  std::vector<SG::ReadDecorHandle<xAOD::BTaggingContainer, std::vector<char>>> jet_rdhs;
50  for (const auto& rdhk: m_readDecorKeys) {
51  jet_rdhs.emplace_back(rdhk, ctx);
52  }
53 
54  // decorate all the tracks with defaults values
56  ATH_CHECK(tracks.isValid());
57 
58  for (const auto track: *tracks) {
59  for (auto& wdh: track_wdhs) {
60  char value = -1;
61  wdh(*track) = value;
62  }
63  }
64 
65  // adding actual aux task results to a subset of tracks
67  ATH_CHECK(jets.isValid());
69  for (const auto jet: *jets) {
70  auto irdh = jet_rdhs.begin();
71  auto iwdh = track_wdhs.begin();
72  for (; irdh != jet_rdhs.end() && iwdh != track_wdhs.end(); ++irdh, ++iwdh) {
73  std::vector<char> values = (*irdh)(*jet);
74  auto& trackLinks = trackLinks_rdh(*jet);
75  if (values.size() != trackLinks.size()) {
76  throw std::logic_error("Track aux task output size " + std::to_string(values.size()) + " doesn't match the size of track list " + std::to_string(trackLinks.size()));
77  }
78  std::vector<ElementLink<xAOD::TrackParticleContainer>>::const_iterator it = trackLinks.begin();
79  std::vector<char>::const_iterator ival = values.begin();
80  for (; it != trackLinks.end() && ival != values.end(); ++it, ++ival) {
81  (*iwdh)(***it) = *ival;
82  }
83  }
84  }
85 
86  return StatusCode::SUCCESS;
87  }
88 
90  return StatusCode::SUCCESS;
91  }
92 
93 }
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::GNNAuxTaskDecoratorAlg
GNNAuxTaskDecoratorAlg(const std::string &name, ISvcLocator *svcloc)
Definition: GNNAuxTaskDecoratorAlg.cxx:17
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer >
BTagging.h
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::execute
virtual StatusCode execute(const EventContext &cxt) const override
Definition: GNNAuxTaskDecoratorAlg.cxx:41
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
skel.it
it
Definition: skel.GENtoEVGEN.py:396
athena.value
value
Definition: athena.py:124
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
WriteCellNoiseToCool.ival
ival
Definition: WriteCellNoiseToCool.py:337
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::finalize
virtual StatusCode finalize() override
Definition: GNNAuxTaskDecoratorAlg.cxx:89
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_jetContainerKey
SG::ReadHandleKey< xAOD::BTaggingContainer > m_jetContainerKey
Definition: GNNAuxTaskDecoratorAlg.h:34
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_readDecorKeys
std::vector< SG::ReadDecorHandleKey< xAOD::BTaggingContainer > > m_readDecorKeys
Definition: GNNAuxTaskDecoratorAlg.h:48
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
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_trackContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackContainerKey
Definition: GNNAuxTaskDecoratorAlg.h:37
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrackParticle.h
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_trackAuxTasks
Gaudi::Property< std::map< std::string, std::string > > m_trackAuxTasks
Definition: GNNAuxTaskDecoratorAlg.h:43
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
GNNAuxTaskDecoratorAlg.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_trackAuxTasksDecorKeys
std::vector< SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > > m_trackAuxTasksDecorKeys
Definition: GNNAuxTaskDecoratorAlg.h:47
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition: GNNAuxTaskDecoratorAlg.cxx:22
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_trackLinksKey
SG::ReadDecorHandleKey< xAOD::TrackParticleContainer > m_trackLinksKey
Definition: GNNAuxTaskDecoratorAlg.h:40