ATLAS Offline Software
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 
19 using std::string;
20 
21 //**********************************************************************
22 
24 
26 
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 
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 
58 StatusCode 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 
et
Extra patterns decribing particle interation process.
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:18
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
JetRecAlg::initialize
StatusCode initialize() override
Athena algorithm's Hooks.
Definition: JetRecAlg.cxx:23
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
JetRecAlg::m_modifiers
ToolHandleArray< IJetModifier > m_modifiers
Definition: JetRecAlg.h:48
JetRecAlg::m_jetprovider
ToolHandle< IJetProvider > m_jetprovider
Athena configured tools.
Definition: JetRecAlg.h:47
test_pyathena.pt
pt
Definition: test_pyathena.py:11
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
JetRecAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: JetRecAlg.h:52
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
IJetExecuteTool.h
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:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
JetRecAlg::m_output
SG::WriteHandleKey< xAOD::JetContainer > m_output
Definition: JetRecAlg.h:49
JetRecAlg.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
JetRecAlg::m_parentKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_parentKey
Definition: JetRecAlg.h:50
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:66
JetAuxContainer.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Monitored::ScopedTimer
Helper class to create a scoped timer.
Definition: MonitoredTimer.h:95
JetRecAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: JetRecAlg.cxx:58
python.compressB64.c
def c
Definition: compressB64.py:93
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
invGeV
constexpr float invGeV
Definition: PFTrackSelector.cxx:10