ATLAS Offline Software
Loading...
Searching...
No Matches
JetViewAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetViewAlg.cxx
6
7#if !defined(XAOD_STANDALONE)
8// We do not compile JetViewAlg yet in AnalysisBase : need support for ShallowCopyDecorDeps
9
10#include <memory>
11#include "JetRec/JetViewAlg.h"
12
13//**********************************************************************
14
15// Called before event loop
17
18 // Initialise DataHandleKeys so that the scheduler is aware of
19 // data dependencies & products
20 if(m_input.key().empty() || m_output.key().empty()) {
21 ATH_MSG_ERROR("Input/output key(s) is/are blank!");
22 return StatusCode::FAILURE;
23 }
24
25 ATH_CHECK(m_input.initialize());
26 ATH_CHECK(m_output.initialize());
28
29 ATH_MSG_DEBUG("Will select jets from " << m_input.key()
30 << " and write them to " << m_output.key());
31 ATH_MSG_DEBUG("Selection criteria are: \n"
32 << " pT > " << m_ptmin << " MeV"
33 << " |eta| < " << m_absetamax
34 );
35
36 return StatusCode::SUCCESS;
37}
38
39//**********************************************************************
40
42
43 if(jet.pt() < m_ptmin) {return false;}
44 if(std::abs(jet.eta()) > m_absetamax) {return false;}
45
46 return true;
47}
48
49//**********************************************************************
50
51StatusCode JetViewAlg::execute(const EventContext& ctx) const {
52
54
55 // Need to place jets into a CDV because we can't put const objects in a DataVector
56 auto selected_jets = std::make_unique<ConstDataVector<xAOD::JetContainer> >( SG::VIEW_ELEMENTS );
57 for(const xAOD::Jet* jet : *inputHandle) {
58 ATH_MSG_VERBOSE("Jet " << jet->index() << std::setprecision(3)
59 << " with pt " << jet->pt()
60 << " eta " << jet->eta()
61 );
62 if( selected(*jet) ) {
63 selected_jets->push_back(jet);
64 ATH_MSG_VERBOSE(" Passed selection");
65 } else {
66 ATH_MSG_VERBOSE(" Failed selection");
67 }
68 }
69 ATH_MSG_DEBUG("Selected " << selected_jets->size() << " from input container of size " << inputHandle->size() );
70
71 // To use ShallowCopyDecorDeps, the input and output handle types have to be the same, i.e. JetContainer
72 // So create a new unique_ptr here using the pointer to the CDV converted to DV
73 std::unique_ptr<const xAOD::JetContainer> selected_jets_jetc(selected_jets.release()->asDataVector());
74
75 // Write out JetContainer and JetAuxContainer
77 // Can't record with const input ptr, hence put
78 if( jetContHandle.put( std::move(selected_jets_jetc) ) == nullptr) {
79 ATH_MSG_ERROR("Failed to record " << m_input.key() << " as const xAOD::JetContainer!");
80 return StatusCode::FAILURE;
81 }
82 ATH_CHECK( m_decorDeps.linkDecors (m_input,ctx) );
83
84 return StatusCode::SUCCESS;
85}
86
87//**********************************************************************
88#endif
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
SG::ReadHandleKey< xAOD::JetContainer > m_input
Definition JetViewAlg.h:53
SG::WriteHandleKey< xAOD::JetContainer > m_output
Definition JetViewAlg.h:54
StatusCode initialize() override
Athena algorithm's Hooks.
bool selected(const xAOD::Jet &) const
Method to select jets.
Gaudi::Property< float > m_absetamax
Definition JetViewAlg.h:51
StatusCode execute(const EventContext &) const override
Gaudi::Property< float > m_ptmin
Definition JetViewAlg.h:50
SG::ShallowCopyDecorDeps< xAOD::JetContainer > m_decorDeps
Definition JetViewAlg.h:58
const_pointer_type put(std::unique_ptr< T > data, bool returnExisting=false) const
Record an object to the store.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Jet_v1 Jet
Definition of the current "jet version".