ATLAS Offline Software
TruthQGDecorationTool.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 // TruthQGDecorationTool.cxx
7 // Create a single decoration for flavor tagging of truth jets
8 
10 #include "StoreGate/ReadHandle.h"
13 #include "xAODJet/JetContainer.h"
14 #include <string>
15 
16 // Constructor
18  const std::string& n,
19  const IInterface* p ) :
20  base_class(t,n,p)
21 {
22 }
23 
24 // Destructor
26 }
27 
28 // Initialize
30 
31  ATH_CHECK(m_jetsKey.initialize());
32  ATH_CHECK(m_decOutput.initialize());
33  return StatusCode::SUCCESS;
34 
35 }
36 
37 // Function to do dressing, implements interface in IAugmentationTool
39 {
40  // Event context
41  const EventContext& ctx = Gaudi::Hive::currentContext();
42 
43  // Retrieve the jet container
44  SG::ReadHandle<xAOD::JetContainer> inputJets(m_jetsKey, ctx);
45  if (!inputJets.isValid()) {
46  ATH_MSG_ERROR("Couldn't retrieve container with name " << m_jetsKey);
47  return StatusCode::FAILURE;
48  }
49 
50  SG::WriteDecorHandle<xAOD::JetContainer,int> output_decorator(m_decOutput, ctx);
51  static const SG::ConstAccessor<int> PartonTruthLabelIDAcc("PartonTruthLabelID");
52  static const SG::ConstAccessor<int> HadronConeExclTruthLabelIDAcc("HadronConeExclTruthLabelID");
53 
54  for (const auto *ajet : *inputJets){
55  if (!PartonTruthLabelIDAcc.isAvailable(*ajet) ){
56  ATH_MSG_ERROR("Did not have input PartonTruthLabelID decorations available");
57  return StatusCode::FAILURE;
58  }
59  else if (!HadronConeExclTruthLabelIDAcc.isAvailable(*ajet) ){
60  ATH_MSG_ERROR("Did not have input HadronConeExclTruthLabelID decorations available");
61  return StatusCode::FAILURE;
62  } // Now we have the input decorations
63  /* Agreement from the HF-tagging and Jet/MET group:
64  - If it is non-zero, use the label from the HF-tagging group (b, c, tau)
65  - If it is zero, use the label from the Jet/MET group (q/g)
66  - In the case that the two disagree (e.g. Jet/MET says b and HF says light),
67  multiply the Jet/MET label by 100 to ensure this case is kept separate
68  */
69  if (HadronConeExclTruthLabelIDAcc(*ajet)!=0){
70  output_decorator(*ajet) = HadronConeExclTruthLabelIDAcc(*ajet);
71  } else {
72  int labelid = PartonTruthLabelIDAcc(*ajet);
73  if (std::abs(labelid)!=5 &&
74  std::abs(labelid)!=4 &&
75  std::abs(labelid)!=15){
76  output_decorator(*ajet) = labelid;
77  } else {
78  output_decorator(*ajet) = labelid*100;
79  }
80  }
81  } // Loop over jets
82 
83  return StatusCode::SUCCESS;
84 }
DerivationFramework::TruthQGDecorationTool::~TruthQGDecorationTool
~TruthQGDecorationTool()
Definition: TruthQGDecorationTool.cxx:25
DerivationFramework::TruthQGDecorationTool::initialize
StatusCode initialize()
Definition: TruthQGDecorationTool.cxx:29
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::TruthQGDecorationTool::TruthQGDecorationTool
TruthQGDecorationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: TruthQGDecorationTool.cxx:17
SG::ConstAccessor< int >
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TruthQGDecorationTool.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JetContainer.h
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
ReadHandle.h
Handle class for reading from StoreGate.
DerivationFramework::TruthQGDecorationTool::addBranches
virtual StatusCode addBranches() const
Definition: TruthQGDecorationTool.cxx:38