ATLAS Offline Software
TrigJetTLAHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #include <algorithm>
6 #include "TrigJetTLAHypoAlg.h"
9 #include "xAODJet/JetContainer.h"
11 #include "xAODBase/IParticleHelpers.h" //for getOriginalObjectLink
12 
13 
14 using namespace TrigCompositeUtils;
15 
16 using xAOD::JetContainer;
17 
19  ISvcLocator* pSvcLocator ) :
20  ::HypoBase( name, pSvcLocator ) {
21 
22  }
23 
24 
26  CHECK( m_hypoTools.retrieve() );
27  CHECK( m_TLAjetsKey.initialize() );
28  if (m_attach_btag) CHECK(m_btag_record_tool.retrieve());
29  return StatusCode::SUCCESS;
30 }
31 
32 
33 StatusCode TrigJetTLAHypoAlg::execute( const EventContext& context ) const {
34 
35  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
36 
37  // create handles for TLA Jets
39  //make the output jet container
40  ATH_CHECK(h_TLAJets.record(std::make_unique<xAOD::JetContainer>(),
41  std::make_unique<xAOD::JetAuxContainer>()));
42 
43 
44  // retrieving previous decisions
45  auto previousDecisionHandle = SG::makeHandle(decisionInput(), context);
46  ATH_CHECK(previousDecisionHandle.isValid());
47  ATH_MSG_DEBUG("Running with " << previousDecisionHandle->size() << " previous decisions");
48 
49 
50  //container for output decisions
52  DecisionContainer* outputDecisions = outputHandle.ptr();
53 
54  int nDecision = 0;
55  int nSavedJets = 0;
56  for (const auto previousDecision : *previousDecisionHandle)
57  {
58  // get jets from the decision
59  const xAOD::Jet *jetPrev = nullptr;
60  auto prevJets = TrigCompositeUtils::findLinks<xAOD::JetContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
61  ATH_MSG_DEBUG("This decision has " << prevJets.size() << " jets");
62 
63  //copy all jets into the new TLA collection
64  for (const auto& jet : prevJets)
65  {
66  auto prevJetLink = jet.link;
67  ATH_CHECK(prevJetLink.isValid());
68  jetPrev = *prevJetLink;
69 
70  // create new decision object for all previous decisions
71  // linking new decision with previous one
72  auto newDecision = newDecisionIn( outputDecisions, hypoAlgNodeName() );
73  TrigCompositeUtils::linkToPrevious( newDecision, previousDecision, context );
74 
75  // Now we ensure not saving jet copies but still linking a TLA jet to each decision
77  bool duplicate_found(false);
78  for (unsigned idx_tla_jet = 0; idx_tla_jet!=h_TLAJets->size(); idx_tla_jet++){
79  const xAOD::Jet* tla_jet = h_TLAJets->at(idx_tla_jet);
80  if (*original_jet_link == *getOriginalObjectLink(*tla_jet)) {
81  ATH_MSG_DEBUG("Jet already found! Adding to decision but not to TLA jet container...");
82  newDecision->setObjectLink(featureString(), ElementLink<xAOD::JetContainer>(*h_TLAJets, idx_tla_jet, context));
83  duplicate_found = true;
84  }
85  }
86  if (duplicate_found) continue;
87 
88  xAOD::Jet *copiedJet = new xAOD::Jet();
89  h_TLAJets->push_back(copiedJet);
90  *copiedJet = *jetPrev;
91  nSavedJets++;
92 
93  ATH_MSG_DEBUG("Copied jet with pT: " << copiedJet->pt() << " and eta "<<copiedJet->eta()<<" from decision " << nDecision);
94 
95  // link TLA jets to decision
96  newDecision->setObjectLink(featureString(), ElementLink<xAOD::JetContainer>(*h_TLAJets, h_TLAJets->size() - 1, context));
97 
98 
99  }
100  nDecision++;
101  }
102 
103  ATH_MSG_DEBUG("Saved "<<nSavedJets<<" TLA jets from "<<nDecision<<" input decisions.");
104 
105  if(m_attach_btag){
106  ATH_MSG_DEBUG("Attaching any available b-tag information to TLA jets.");
107  const DecisionContainer* previousDecisions = previousDecisionHandle.get();
108  // ** Calling record_btag() on this tool will create a new TLA HLT Btagging container
109  // which will be filled with copies of BTagging elements attached to the previous decision
110  // and linked to matching jets in h_TLAJets. **
111  CHECK(m_btag_record_tool->record_btag(previousDecisions, *h_TLAJets, context));
112  }
113 
114  for (const auto& tool: m_hypoTools) {
115 
116  ATH_MSG_DEBUG("Now computing decision for " << tool->name());
117  CHECK(tool->decide(outputDecisions));
118 
119  }//end loop on hypoTools
120 
121  //extra run-time checks
122  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
123 
124  return StatusCode::SUCCESS;
125 
126 }//end execute
TrigJetTLAHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigJetTLAHypoAlg.cxx:33
TrigJetTLAHypoAlg::m_TLAjetsKey
SG::WriteHandleKey< xAOD::JetContainer > m_TLAjetsKey
Definition: TrigJetTLAHypoAlg.h:44
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
TrigJetTLAHypoAlg.h
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
HypoBase::decisionInput
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition: HypoBase.cxx:16
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
HypoBase::decisionOutput
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition: HypoBase.cxx:20
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigJetTLAHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigJetTLAHypoAlg.cxx:25
TrigCompositeUtils.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
HypoBase::hypoBaseOutputProcessing
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition: HypoBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::Jet_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: Jet_v1.cxx:49
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
TrigJetTLAHypoAlg::TrigJetTLAHypoAlg
TrigJetTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigJetTLAHypoAlg.cxx:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigJetTLAHypoAlg::m_hypoTools
ToolHandleArray< TrigJetTLAHypoTool > m_hypoTools
Definition: TrigJetTLAHypoAlg.h:41
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
JetContainer.h
HLTIdentifier.h
JetAuxContainer.h
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
IParticleHelpers.h
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition: JetContainer.h:17
TrigJetTLAHypoAlg::m_attach_btag
Gaudi::Property< bool > m_attach_btag
Definition: TrigJetTLAHypoAlg.h:47
xAOD::Jet_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition: Jet_v1.cxx:44
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
TrigJetTLAHypoAlg::m_btag_record_tool
ToolHandle< TrigBtagTLATool > m_btag_record_tool
Definition: TrigJetTLAHypoAlg.h:48