ATLAS Offline Software
TruthQGDecorationTool.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 // 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 // Initialize
18 
21  return StatusCode::SUCCESS;
22 
23 }
24 
25 // Function to do dressing, implements interface in IAugmentationTool
27 {
28  // Event context
29 
30  // Retrieve the jet container
31  SG::ReadHandle<xAOD::JetContainer> inputJets(m_jetsKey, ctx);
32  if (!inputJets.isValid()) {
33  ATH_MSG_ERROR("Couldn't retrieve container with name " << m_jetsKey);
34  return StatusCode::FAILURE;
35  }
36 
37  SG::WriteDecorHandle<xAOD::JetContainer,int> output_decorator(m_decOutput, ctx);
38  static const SG::ConstAccessor<int> PartonTruthLabelIDAcc("PartonTruthLabelID");
39  static const SG::ConstAccessor<int> HadronConeExclTruthLabelIDAcc("HadronConeExclTruthLabelID");
40 
41  for (const auto *ajet : *inputJets){
42  if (!PartonTruthLabelIDAcc.isAvailable(*ajet) ){
43  ATH_MSG_ERROR("Did not have input PartonTruthLabelID decorations available");
44  return StatusCode::FAILURE;
45  }
46  else if (!HadronConeExclTruthLabelIDAcc.isAvailable(*ajet) ){
47  ATH_MSG_ERROR("Did not have input HadronConeExclTruthLabelID decorations available");
48  return StatusCode::FAILURE;
49  } // Now we have the input decorations
50  /* Agreement from the HF-tagging and Jet/MET group:
51  - If it is non-zero, use the label from the HF-tagging group (b, c, tau)
52  - If it is zero, use the label from the Jet/MET group (q/g)
53  - In the case that the two disagree (e.g. Jet/MET says b and HF says light),
54  multiply the Jet/MET label by 100 to ensure this case is kept separate
55  */
56  if (HadronConeExclTruthLabelIDAcc(*ajet)!=0){
57  output_decorator(*ajet) = HadronConeExclTruthLabelIDAcc(*ajet);
58  } else {
59  int labelid = PartonTruthLabelIDAcc(*ajet);
60  if (std::abs(labelid)!=5 &&
61  std::abs(labelid)!=4 &&
62  std::abs(labelid)!=15){
63  output_decorator(*ajet) = labelid;
64  } else {
65  output_decorator(*ajet) = labelid*100;
66  }
67  }
68  } // Loop over jets
69 
70  return StatusCode::SUCCESS;
71 }
DerivationFramework::TruthQGDecorationTool::initialize
StatusCode initialize()
Definition: TruthQGDecorationTool.cxx:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::TruthQGDecorationTool::m_jetsKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsKey
input collection key
Definition: TruthQGDecorationTool.h:35
SG::ConstAccessor< int >
DerivationFramework::TruthQGDecorationTool::m_decOutput
SG::WriteDecorHandleKey< xAOD::JetContainer > m_decOutput
output decoration
Definition: TruthQGDecorationTool.h:38
DerivationFramework::TruthQGDecorationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition: TruthQGDecorationTool.cxx:26
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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::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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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.
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.