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() );
28  return StatusCode::SUCCESS;
29 }
30 
31 
32 StatusCode TrigJetTLAHypoAlg::execute( const EventContext& context ) const {
33 
34  ATH_MSG_DEBUG ( "Executing " << name() << "..." );
35 
36  // create handles for TLA Jets
38  //make the output jet container
39  ATH_CHECK(h_TLAJets.record(std::make_unique<xAOD::JetContainer>(),
40  std::make_unique<xAOD::JetAuxContainer>()));
41 
42 
43  // retrieving previous decisions
44  auto previousDecisionHandle = SG::makeHandle(decisionInput(), context);
45  ATH_CHECK(previousDecisionHandle.isValid());
46  ATH_MSG_DEBUG("Running with " << previousDecisionHandle->size() << " previous decisions");
47 
48 
49  //container for output decisions
51  DecisionContainer* outputDecisions = outputHandle.ptr();
52 
53  int nDecision = 0;
54  int nSavedJets = 0;
55  for (const auto previousDecision : *previousDecisionHandle)
56  {
57  // get jets from the decision
58  const xAOD::Jet *jetPrev = nullptr;
59  auto prevJets = TrigCompositeUtils::findLinks<xAOD::JetContainer>(previousDecision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
60  ATH_MSG_DEBUG("This decision has " << prevJets.size() << " jets");
61 
62  //copy all jets into the new TLA collection
63  for (const auto& jet : prevJets)
64  {
65  auto prevJetLink = jet.link;
66  ATH_CHECK(prevJetLink.isValid());
67  jetPrev = *prevJetLink;
68 
69  // create new decision object for all previous decisions
70  // linking new decision with previous one
71  auto newDecision = newDecisionIn( outputDecisions, hypoAlgNodeName() );
72  TrigCompositeUtils::linkToPrevious( newDecision, previousDecision, context );
73 
74  // Now we ensure not saving jet copies but still linking a TLA jet to each decision
76  bool duplicate_found(false);
77  for (unsigned idx_tla_jet = 0; idx_tla_jet!=h_TLAJets->size(); idx_tla_jet++){
78  const xAOD::Jet* tla_jet = h_TLAJets->at(idx_tla_jet);
79  if (*original_jet_link == *getOriginalObjectLink(*tla_jet)) {
80  ATH_MSG_DEBUG("Jet already found! Adding to decision but not to TLA jet container...");
81  newDecision->setObjectLink(featureString(), ElementLink<xAOD::JetContainer>(*h_TLAJets, idx_tla_jet, context));
82  duplicate_found = true;
83  }
84  }
85  if (duplicate_found) continue;
86 
87  xAOD::Jet *copiedJet = new xAOD::Jet();
88  h_TLAJets->push_back(copiedJet);
89  *copiedJet = *jetPrev;
90  nSavedJets++;
91 
92  ATH_MSG_DEBUG("Copied jet with pT: " << copiedJet->pt() << " and eta "<<copiedJet->eta()<<" from decision " << nDecision);
93 
94  // link TLA jets to decision
95  newDecision->setObjectLink(featureString(), ElementLink<xAOD::JetContainer>(*h_TLAJets, h_TLAJets->size() - 1, context));
96 
97 
98  }
99  nDecision++;
100  }
101 
102  ATH_MSG_DEBUG("Saved "<<nSavedJets<<" TLA jets from "<<nDecision<<" input decisions.");
103 
104  for (const auto& tool: m_hypoTools) {
105 
106  ATH_MSG_DEBUG("Now computing decision for " << tool->name());
107  CHECK(tool->decide(outputDecisions));
108 
109  }//end loop on hypoTools
110 
111  //extra run-time checks
112  ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
113 
114  return StatusCode::SUCCESS;
115 
116 }//end execute
TrigJetTLAHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigJetTLAHypoAlg.cxx:32
TrigJetTLAHypoAlg::m_TLAjetsKey
SG::WriteHandleKey< xAOD::JetContainer > m_TLAjetsKey
Definition: TrigJetTLAHypoAlg.h:42
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:43
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:918
TrigJetTLAHypoAlg.h
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:27
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:274
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
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
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:898
TrigJetTLAHypoAlg::TrigJetTLAHypoAlg
TrigJetTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigJetTLAHypoAlg.cxx:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrigJetTLAHypoAlg::m_hypoTools
ToolHandleArray< TrigJetTLAHypoTool > m_hypoTools
Definition: TrigJetTLAHypoAlg.h:39
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
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
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