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  AthAlgTool(t,n,p)
21 {
22  declareInterface<DerivationFramework::IAugmentationTool>(this);
23 }
24 
25 // Destructor
27 }
28 
29 // Initialize
31 
32  ATH_CHECK(m_jetsKey.initialize());
33  ATH_CHECK(m_decOutput.initialize());
34  return StatusCode::SUCCESS;
35 
36 }
37 
38 // Function to do dressing, implements interface in IAugmentationTool
40 {
41  // Event context
42  const EventContext& ctx = Gaudi::Hive::currentContext();
43 
44  // Retrieve the jet container
45  SG::ReadHandle<xAOD::JetContainer> inputJets(m_jetsKey, ctx);
46  if (!inputJets.isValid()) {
47  ATH_MSG_ERROR("Couldn't retrieve container with name " << m_jetsKey);
48  return StatusCode::FAILURE;
49  }
50 
51  SG::WriteDecorHandle<xAOD::JetContainer,int> output_decorator(m_decOutput, ctx);
52  static const SG::ConstAccessor<int> PartonTruthLabelIDAcc("PartonTruthLabelID");
53  static const SG::ConstAccessor<int> HadronConeExclTruthLabelIDAcc("HadronConeExclTruthLabelID");
54 
55  for (const auto *ajet : *inputJets){
56  if (!PartonTruthLabelIDAcc.isAvailable(*ajet) ){
57  ATH_MSG_ERROR("Did not have input PartonTruthLabelID decorations available");
58  return StatusCode::FAILURE;
59  }
60  else if (!HadronConeExclTruthLabelIDAcc.isAvailable(*ajet) ){
61  ATH_MSG_ERROR("Did not have input HadronConeExclTruthLabelID decorations available");
62  return StatusCode::FAILURE;
63  } // Now we have the input decorations
64  /* Agreement from the HF-tagging and Jet/MET group:
65  - If it is non-zero, use the label from the HF-tagging group (b, c, tau)
66  - If it is zero, use the label from the Jet/MET group (q/g)
67  - In the case that the two disagree (e.g. Jet/MET says b and HF says light),
68  multiply the Jet/MET label by 100 to ensure this case is kept separate
69  */
70  if (HadronConeExclTruthLabelIDAcc(*ajet)!=0){
71  output_decorator(*ajet) = HadronConeExclTruthLabelIDAcc(*ajet);
72  } else {
73  int labelid = PartonTruthLabelIDAcc(*ajet);
74  if (std::abs(labelid)!=5 &&
75  std::abs(labelid)!=4 &&
76  std::abs(labelid)!=15){
77  output_decorator(*ajet) = labelid;
78  } else {
79  output_decorator(*ajet) = labelid*100;
80  }
81  }
82  } // Loop over jets
83 
84  return StatusCode::SUCCESS;
85 }
DerivationFramework::TruthQGDecorationTool::~TruthQGDecorationTool
~TruthQGDecorationTool()
Definition: TruthQGDecorationTool.cxx:26
DerivationFramework::TruthQGDecorationTool::initialize
StatusCode initialize()
Definition: TruthQGDecorationTool.cxx:30
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
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.
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::TruthQGDecorationTool::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TruthQGDecorationTool.cxx:39