ATLAS Offline Software
Loading...
Searching...
No Matches
JetRecAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetRecAlg.cxx
6
7#include <memory>
8#include "JetRec/JetRecAlg.h"
11
13
14#if !defined (GENERATIONBASE) && !defined (XAOD_ANALYSIS)
16#include "GaudiKernel/SystemOfUnits.h"
17#endif
18
19using std::string;
20
21//**********************************************************************
22
24
25 ATH_CHECK(m_output.initialize());
26
27 if(!m_parentKey.empty()) m_parentKey = m_output.key() + "." + m_parentKey.key();
28 ATH_CHECK(m_parentKey.initialize(!m_parentKey.empty()));
29
30 ATH_CHECK(m_jetprovider.retrieve());
31 // Some providers (e.g. copy) need the output WriteHandle
32 // to be provided during initialisation
33 ATH_CHECK(m_jetprovider->initWithOutput(m_output));
34
35 ATH_MSG_INFO("Initialized IJetProvider : "<< m_jetprovider->name());
36
37 ATH_MSG_INFO("Initialize .... List of modifiers: ");
38 ATH_CHECK(m_modifiers.retrieve());
39 for(const ToolHandle<IJetModifier>& t : m_modifiers){
40 ATH_MSG_INFO(" --> : "<< t->name());
41 }
42
43 ATH_CHECK(m_output.initialize());
44
45#if !defined (GENERATIONBASE) && !defined (XAOD_ANALYSIS)
46 if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
47#endif
48
49 return StatusCode::SUCCESS;
50}
51
52//**********************************************************************
53
54#if !defined (GENERATIONBASE) && !defined (XAOD_ANALYSIS)
55#define DOMONITORING
56#endif
57
58StatusCode JetRecAlg::execute(const EventContext& ctx) const {
59 // Get JetContainer by running fastjet, grooming or copying existing jets...
60 // Pass in the WriteHandle so that the provider can do the record, and we
61 // needn't know the type of the jet aux container
62 // We can subsequently access the jets from the handle and don't have to
63 // worry about memory management.
64
65#ifdef DOMONITORING
66 auto t_total = Monitored::Timer<std::chrono::milliseconds>( "TIME_jetreco" );
67 auto t_jpv = Monitored::Timer<std::chrono::milliseconds>( "TIME_jetprovider" );
68 auto t_mod = Monitored::Timer<std::chrono::milliseconds>( "TIME_jetmod" );
69#endif
70
72 static const SG::AuxElement::ConstAccessor<ElementLink<xAOD::JetContainer> > parentELacc("Parent_TEMP");
73
74 // Define a scope to ease monitoring of the JetProvider action
75 {
76#ifdef DOMONITORING
77 Monitored::ScopedTimer time_provider(t_jpv);
78#endif
79 ATH_CHECK( m_jetprovider->getAndRecordJets(jetContHandle) );
80 ATH_MSG_DEBUG("Created jet container of size "<< (*jetContHandle).size() << " | writing to "<< m_output.key() );
81
82 if(!m_parentKey.empty()){
84 for (xAOD::Jet* jet : *jetContHandle)
85 parentDecorHandle(*jet) = parentELacc(*jet);
86 }
87 }
88
89 // Define a scope to ease monitoring of the JetModifier action
90 {
91#ifdef DOMONITORING
92 Monitored::ScopedTimer time_modifiers(t_mod);
93#endif
94 ATH_MSG_DEBUG("Applying jet modifiers to " << m_output.key());
95 // Calculate moments, calibrate, sort, filter... -----------
96 for(const ToolHandle<IJetModifier>& t : m_modifiers){
97 ATH_MSG_DEBUG("Running " << t.name());
98 ATH_CHECK(t->modify(*jetContHandle));
99 }
100 }
101
102#ifdef DOMONITORING
103 // monitor jet multiplicity and basic jet kinematics
104 auto njets = Monitored::Scalar<int>("JET_n");
105 njets = jetContHandle->size();
106 constexpr float invGeV = 1./Gaudi::Units::GeV;
107 auto pt = Monitored::Collection("JET_pt", *jetContHandle, [c=invGeV]( const xAOD::Jet* jet ) { return jet->pt()*c; });
108 auto et = Monitored::Collection("JET_et", *jetContHandle, [c=invGeV]( const xAOD::Jet* jet ) { return jet->p4().Et()*c; });
109 auto mass = Monitored::Collection("JET_m", *jetContHandle, [c=invGeV]( const xAOD::Jet* jet ) { return jet->m()*c; });
110 auto eta = Monitored::Collection("JET_eta", *jetContHandle, []( const xAOD::Jet* jet ) { return jet->eta(); });
111 auto phi = Monitored::Collection("JET_phi", *jetContHandle, []( const xAOD::Jet* jet ) { return jet->phi(); });
112
113 auto mon = Monitored::Group(m_monTool,t_total,t_jpv,t_mod,njets,pt,et,mass,eta,phi);
114#endif
115
116
117 return StatusCode::SUCCESS;
118
119}
120
121//**********************************************************************
122
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
Header file to be included by clients of the Monitored infrastructure.
constexpr float invGeV
SG::WriteDecorHandleKey< xAOD::JetContainer > m_parentKey
Definition JetRecAlg.h:50
StatusCode initialize() override
Athena algorithm's Hooks.
Definition JetRecAlg.cxx:23
ToolHandleArray< IJetModifier > m_modifiers
Definition JetRecAlg.h:48
SG::WriteHandleKey< xAOD::JetContainer > m_output
Definition JetRecAlg.h:49
StatusCode execute(const EventContext &ctx) const override
Definition JetRecAlg.cxx:58
ToolHandle< IJetProvider > m_jetprovider
Athena configured tools.
Definition JetRecAlg.h:47
ToolHandle< GenericMonitoringTool > m_monTool
Definition JetRecAlg.h:52
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
Helper class to create a scoped timer.
A monitored timer.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
Handle class for adding a decoration to an object.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Jet_v1 Jet
Definition of the current "jet version".
Extra patterns decribing particle interation process.