ATLAS Offline Software
Loading...
Searching...
No Matches
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"
11#include "xAODBase/IParticleHelpers.h" //for getOriginalObjectLink
12
13
14using namespace TrigCompositeUtils;
15
17
18TrigJetTLAHypoAlg::TrigJetTLAHypoAlg( const std::string& name,
19 ISvcLocator* pSvcLocator ) :
20 ::HypoBase( name, pSvcLocator ) {
21
22 }
23
24
26 CHECK( m_hypoTools.retrieve() );
27 CHECK( m_TLAjetsKey.initialize() );
28 return StatusCode::SUCCESS;
29}
30
31
32StatusCode 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;
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
75 ElementLink<xAOD::IParticleContainer>::ElementConstPointer original_jet_link = getOriginalObjectLink(*(jetPrev));
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
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:18
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:22
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:35
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
SG::WriteHandleKey< xAOD::JetContainer > m_TLAjetsKey
virtual StatusCode execute(const EventContext &context) const override
virtual StatusCode initialize() override
TrigJetTLAHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandleArray< TrigJetTLAHypoTool > m_hypoTools
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition Jet_v1.cxx:44
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition Jet_v1.cxx:49
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
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.
const std::string & featureString()
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void findLinks(const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".