ATLAS Offline Software
GNNAuxTaskDecoratorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 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  }
25 
26  ATH_CHECK(m_trackLinksKey.initialize());
27 
29  m_readDecorKeys.reserve(m_trackAuxTasks.size());
30  for (const auto& [jetDecor, trackDecor] : m_trackAuxTasks) {
31  m_trackAuxTasksDecorKeys.emplace_back(m_trackContainerKey, trackDecor);
32  m_readDecorKeys.emplace_back(m_jetContainerKey, jetDecor);
33  }
34  ATH_CHECK(m_trackAuxTasksDecorKeys.initialize());
35  ATH_CHECK(m_readDecorKeys.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::JetContainer, 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::m_readDecorKeys
SG::ReadDecorHandleKeyArray< xAOD::JetContainer > m_readDecorKeys
Definition: GNNAuxTaskDecoratorAlg.h:48
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::GNNAuxTaskDecoratorAlg
GNNAuxTaskDecoratorAlg(const std::string &name, ISvcLocator *svcloc)
Definition: GNNAuxTaskDecoratorAlg.cxx:17
BTagging.h
FlavorTagDiscriminants
Definition: DL2.h:18
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::execute
virtual StatusCode execute(const EventContext &cxt) const override
Definition: GNNAuxTaskDecoratorAlg.cxx:41
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
skel.it
it
Definition: skel.GENtoEVGEN.py:407
defineDB.jets
jets
Definition: JetTagCalibration/share/defineDB.py:24
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_jetContainerKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContainerKey
Definition: GNNAuxTaskDecoratorAlg.h:34
athena.value
value
Definition: athena.py:124
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
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
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
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:240
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
GNNAuxTaskDecoratorAlg.h
FlavorTagDiscriminants::GNNAuxTaskDecoratorAlg::m_trackAuxTasksDecorKeys
SG::WriteDecorHandleKeyArray< xAOD::TrackParticleContainer > m_trackAuxTasksDecorKeys
Definition: GNNAuxTaskDecoratorAlg.h:47
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
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