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 
42  // Retrieve the jet container
43  SG::ReadHandle<xAOD::JetContainer> inputJets(m_jetsKey, ctx);
44  if (!inputJets.isValid()) {
45  ATH_MSG_ERROR("Couldn't retrieve container with name " << m_jetsKey);
46  return StatusCode::FAILURE;
47  }
48 
49  SG::WriteDecorHandle<xAOD::JetContainer,int> output_decorator(m_decOutput, ctx);
50  static const SG::ConstAccessor<int> PartonTruthLabelIDAcc("PartonTruthLabelID");
51  static const SG::ConstAccessor<int> HadronConeExclTruthLabelIDAcc("HadronConeExclTruthLabelID");
52 
53  for (const auto *ajet : *inputJets){
54  if (!PartonTruthLabelIDAcc.isAvailable(*ajet) ){
55  ATH_MSG_ERROR("Did not have input PartonTruthLabelID decorations available");
56  return StatusCode::FAILURE;
57  }
58  else if (!HadronConeExclTruthLabelIDAcc.isAvailable(*ajet) ){
59  ATH_MSG_ERROR("Did not have input HadronConeExclTruthLabelID decorations available");
60  return StatusCode::FAILURE;
61  } // Now we have the input decorations
62  /* Agreement from the HF-tagging and Jet/MET group:
63  - If it is non-zero, use the label from the HF-tagging group (b, c, tau)
64  - If it is zero, use the label from the Jet/MET group (q/g)
65  - In the case that the two disagree (e.g. Jet/MET says b and HF says light),
66  multiply the Jet/MET label by 100 to ensure this case is kept separate
67  */
68  if (HadronConeExclTruthLabelIDAcc(*ajet)!=0){
69  output_decorator(*ajet) = HadronConeExclTruthLabelIDAcc(*ajet);
70  } else {
71  int labelid = PartonTruthLabelIDAcc(*ajet);
72  if (std::abs(labelid)!=5 &&
73  std::abs(labelid)!=4 &&
74  std::abs(labelid)!=15){
75  output_decorator(*ajet) = labelid;
76  } else {
77  output_decorator(*ajet) = labelid*100;
78  }
79  }
80  } // Loop over jets
81 
82  return StatusCode::SUCCESS;
83 }
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
DerivationFramework::TruthQGDecorationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition: TruthQGDecorationTool.cxx:38
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:727
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.