ATLAS Offline Software
TrigBtagTLATool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: TrigBtagTLATool.cxx
8 // PACKAGE: Trigger/TrigHypothesis/TrigHLTJetHypo
9 //
10 //
11 // ********************************************************************
12 
13 
14 #include "TrigBtagTLATool.h"
17 #include "xAODBase/IParticleHelpers.h" //for getOriginalObjectLink
18 
19 #include "GaudiKernel/StatusCode.h"
20 
22 
24  const std::string& name,
25  const IInterface* parent) :
27 
28 }
29 
31 }
32 
34  ATH_MSG_INFO("Initializing " << name() << "...");
35  CHECK( m_outputBTagInfoKey.initialize() );
37  CHECK( m_bTagJetDecorLinkName.initialize() );
38  return StatusCode::SUCCESS;
39 }
40 
42  return StatusCode::SUCCESS;
43 }
44 
45 StatusCode TrigBtagTLATool::record_btag(const xAOD::TrigCompositeContainer* previousDecisions, const xAOD::JetContainer& jets_to_btag, const EventContext& ctx)const{
46 
47 
48  //###########################################################
49  // Making a new output HLT BTagging container
50  //###########################################################
52  ATH_MSG_DEBUG("Recording BTagging info as " << h_outBTagInfo.key());
53  ATH_CHECK( h_outBTagInfo.record (std::make_unique<xAOD::BTaggingContainer>(),
54  std::make_unique<xAOD::BTaggingAuxContainer>() ) );
56 
57  //###########################################################
58  // Now recording available BTagging information for each jet with steps:
59  // (1) For each previous trigger decision, search for attached BTagging element
60  // (2) If found a BTagging element, retrieve the linked b-jet and its original jet link ("getOriginalObjectLink")
61  // (3) Find the matching jet in jets_to_btag via an identical original jet link.
62  // (4) Duplcate the BTagging element and attach to it a jet element link pointing to the matched jet
63  // (5) Record the duplicated BTagging element in the newly created HLT BTagging container.
64  //###########################################################
65 
66  for (const auto previousDecision : *previousDecisions)
67  {
68  std::vector<LinkInfo<xAOD::BTaggingContainer>> btagDecisionInfoLinks = TrigCompositeUtils::findLinks<xAOD::BTaggingContainer>(previousDecision, "btag", TrigDefs::lastFeatureOfType);
69  if (btagDecisionInfoLinks.size() == 0 ){
70  ATH_MSG_DEBUG("Skipping decision with no b-tag information.");
71  continue;
72  }
73  if (btagDecisionInfoLinks.size() > 1 ){
74  ATH_MSG_ERROR("More than one BTagging element found for this decision!");
75  return StatusCode::FAILURE;
76  }
77 
78  for (auto btagLinkInfo: btagDecisionInfoLinks){
79  ElementLink<xAOD::BTaggingContainer> btagDecisionLink = btagLinkInfo.link;
80  ATH_CHECK(btagDecisionLink.isValid());
81  const xAOD::BTagging * btag = *btagDecisionLink;
82  static const SG::AuxElement::ConstAccessor<ElementLink<xAOD::JetContainer>> getBJet("jetLink");
83  const xAOD::Jet* bjet(nullptr);
84  if (getBJet.isAvailable(*btag) && getBJet(*btag).isValid()) {
85  bjet = *(getBJet(*btag));
86  }
87  else return StatusCode::FAILURE;
88 
89  auto blink = getOriginalObjectLink(*(bjet));
90  bool matched(false);
91  for (auto jet: jets_to_btag ){
92  auto jlink = getOriginalObjectLink(*(jet));
93  if (jlink == blink) {
94  matched=true;
95  if (jet->eta() != bjet->eta()) ATH_MSG_WARNING("Found matching jet for b-jet but their eta values differ (jet eta "<<jet->eta()<<", b-jet eta "<<bjet->eta()<<". Were these jets properly matched?");
97  xAOD::BTagging * copied_bTagInfo = new xAOD::BTagging();
98  h_outBTagInfo->push_back(copied_bTagInfo);
99  *copied_bTagInfo = *bTagInfo;
101  jetEL.toContainedElement(jets_to_btag ,jet);
102  h_bTagJetLinkName(*h_outBTagInfo->back()) = jetEL;
103  break;
104  }
105  }
106  if (!matched) ATH_MSG_WARNING("No matching jet found?");
107  }
108  }
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 
BTaggingUtilities.h
python.BuildSignatureFlags.bjet
AthConfigFlags bjet(AthConfigFlags flags, str instanceName, str recoMode)
Definition: BuildSignatureFlags.py:335
TrigBtagTLATool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigCompositeUtils.h
TrigBtagTLATool::m_bTagJetDecorLinkName
SG::WriteDecorHandleKey< xAOD::BTaggingContainer > m_bTagJetDecorLinkName
Definition: TrigBtagTLATool.h:39
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
TrigBtagTLATool::m_outputBTagInfoKey
SG::WriteHandleKey< xAOD::BTaggingContainer > m_outputBTagInfoKey
Definition: TrigBtagTLATool.h:37
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::getOriginalObjectLink
const ElementLink< IParticleContainer > & getOriginalObjectLink(const IParticle &copy)
This function should be used instead of xAOD::getOriginalObject when we want to use the "original obj...
Definition: IParticleHelpers.cxx:168
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::BTaggingUtilities::getBTagging
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Definition: BTaggingUtilities.cxx:37
TrigBtagTLATool::finalize
StatusCode finalize()
Definition: TrigBtagTLATool.cxx:41
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigBtagTLATool::record_btag
StatusCode record_btag(const xAOD::TrigCompositeContainer *, const xAOD::JetContainer &, const EventContext &) const
Definition: TrigBtagTLATool.cxx:45
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TrigBtagTLATool::initialize
StatusCode initialize()
Definition: TrigBtagTLATool.cxx:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::BTagging
BTagging_v1 BTagging
Definition of the current "BTagging version".
Definition: BTagging.h:17
TrigBtagTLATool::TrigBtagTLATool
TrigBtagTLATool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrigBtagTLATool.cxx:23
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigBtagTLATool::~TrigBtagTLATool
~TrigBtagTLATool()
Definition: TrigBtagTLATool.cxx:30
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
IParticleHelpers.h
AthAlgTool
Definition: AthAlgTool.h:26