ATLAS Offline Software
Loading...
Searching...
No Matches
JetConstitFourMomTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetConstitFourMomTool.cxx
6
8
10#include "xAODJet/JetTypes.h"
11
12//**********************************************************************
13
15 : asg::AsgTool(myname)
16{
17#ifndef XAOD_STANDALONE
18 declareInterface<IJetModifier>(this);
19#endif
20}
21
22//**********************************************************************
23
25
26 // Workaround because configuring DataHandleKeyArray directly sneakily removes empty strings
27 for(const auto& dhn : m_altColls){
29 }
30
31 for(auto& dh : m_altColls_keys){ATH_CHECK(dh.initialize(!(dh.key().empty())));}
32
33 // Check configuration consistency
34 if( m_jetScaleNames.empty() ||
35 (m_jetScaleNames.size() != m_altConstitScales.size()) ||
36 (m_jetScaleNames.size() != m_altJetScales.size()) ||
37 (m_jetScaleNames.size() != m_altColls_keys.size())
38 ) {
39 ATH_MSG_FATAL("Inconsistency in configuration -- all vector properties must have the same (nonzero) length! Sizes: "
40 << m_jetScaleNames.size() << " "
41 << m_altConstitScales.size() << " "
42 << m_altJetScales.size() << " "
43 << m_altColls_keys.size());
44 return StatusCode::FAILURE;
45 }
46
48 for(size_t iScale=0; iScale<m_jetScaleNames.size(); ++iScale) {
49 if(m_jetScaleNames[iScale]=="DetectorEtaPhi") {
50 m_isDetectorEtaPhi[iScale] = true;
51 }
52 if(!m_altJetScales[iScale].empty() && !m_altColls_keys[iScale].key().empty()) {
53 ATH_MSG_FATAL("Inconsistency in configuration -- Both AltJetScale and AltConstitColl set for scale "
54 << m_jetScaleNames[iScale] << "!");
55 return StatusCode::FAILURE;
56 }
57 }
58
59
60 return StatusCode::SUCCESS;
61}
62
64 if(jets.empty()) return StatusCode::SUCCESS;
65
66 const size_t nScales=m_jetScaleNames.size();
67 // This only really makes sense for clusters now, as signal states don't exist for other types
68 std::vector<const xAOD::CaloClusterContainer*> altCollections(nScales,nullptr);
69 // Do some setup that doesn't have to be repeated for each jet
70 for(size_t iScale=0; iScale<nScales; ++iScale) {
71 if(!m_altColls_keys[iScale].key().empty()) { // retrieve alternate constituent collections
72 const xAOD::Jet& leadjet = *jets.front();
73 if(isValidConstitType(leadjet.getInputType())) {
74
75 auto handle = SG::makeHandle(m_altColls_keys[iScale]);
76 if(!handle.isValid()){
77 ATH_MSG_WARNING("Failed to retrieve alt cluster collection "
78 << m_altColls_keys[iScale].key());
79 return StatusCode::FAILURE;
80 }
81
82 altCollections[iScale] = handle.cptr();
83 } else {
84 ATH_MSG_WARNING("Alt collection " << m_altColls_keys[iScale].key() << " and jet type " << leadjet.getInputType() << " not supported yet!");
85 return StatusCode::FAILURE;
86 } // check that jet type/alt collection are implemented
87 } // have an alt collection for this scale
88 }
89
90 // Limit ourselves to one loop over the constituents
91 for(xAOD::Jet *jet : jets) {
92 std::vector<xAOD::JetFourMom_t> constitFourVecs(nScales);
93 // Get the constituents of the jet
94 const xAOD::JetConstituentVector constituents = jet->getConstituents();
95 // Gets the constituent iter at the appropriate scale
97 for (auto citer = constituents.begin(constscale);
98 citer != constituents.end(constscale); ++citer) {
99 for (size_t iScale=0; iScale<nScales; ++iScale) {
100 // If altJetScales is set, do nothing in the constituent loop.
101 if(m_altJetScales[iScale].empty()) {
102 if(altCollections[iScale]) { // get the index-parallel alternative constituent
103 const xAOD::CaloCluster* cluster = static_cast<const xAOD::CaloCluster*>((*altCollections[iScale])[(*citer)->rawConstituent()->index()]);
104 xAOD::CaloCluster::State currentState= static_cast<xAOD::CaloCluster::State> (m_altConstitScales[iScale]);
105 constitFourVecs[iScale] += xAOD::JetFourMom_t( cluster->pt(currentState), cluster->eta(currentState),
106 cluster->phi(currentState), cluster->m(currentState) );
107 ATH_MSG_VERBOSE("Add cluster with pt " << cluster->pt() << " to constit fourvec for scale " << m_jetScaleNames[iScale] );
108 } else { // add the constituent 4-mom
109 ATH_MSG_VERBOSE("Add raw constituent with pt " << (*citer)->pt() << " to constit fourvec for scale " << m_jetScaleNames[iScale] );
110 constitFourVecs[iScale] += **citer;
111 }
112 }
113 } // loop over scales
114 } // loop over clusters
115
116 // Now we can set the scales from the various four-vecs we have calculated
117 ATH_MSG_VERBOSE("Jet has "
118 << " pt: " << jet->pt()
119 << ", eta: " << jet->eta()
120 << ", phi: " << jet->phi());
121 for (size_t iScale=0; iScale<nScales; ++iScale) {
122 if(!m_altJetScales[iScale].empty()) {
123 // Easy case first -- just copy the momentum state
124 constitFourVecs[iScale] = jet->jetP4(m_altJetScales[iScale]);
125 }
126 ATH_MSG_VERBOSE("Scale " << m_jetScaleNames[iScale] << " has "
127 << " pt: " << constitFourVecs[iScale].Pt()
128 << ", eta: " << constitFourVecs[iScale].Eta()
129 << ", phi: " << constitFourVecs[iScale].Phi());
130 if(m_isDetectorEtaPhi[iScale]) {
131 const static SG::AuxElement::Accessor<float> acc_modEta("DetectorEta");
132 const static SG::AuxElement::Accessor<float> acc_modPhi("DetectorPhi");
133 const static SG::AuxElement::Accessor<float> acc_modY("DetectorY");
134 acc_modEta(*jet) = constitFourVecs[iScale].Eta();
135 acc_modPhi(*jet) = constitFourVecs[iScale].Phi();
136 acc_modY(*jet) = constitFourVecs[iScale].Rapidity();
137 ATH_MSG_VERBOSE("Detector eta: " << constitFourVecs[iScale].Eta()
138 << ", phi: " << constitFourVecs[iScale].Phi()
139 << ", rapidity: " << constitFourVecs[iScale].Rapidity());
140 } else {
141 jet->setJetP4(m_jetScaleNames[iScale], constitFourVecs[iScale]);
142 }
143 } // loop over scales
144 } // loop over jets
145
146 return StatusCode::SUCCESS;
147}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This file defines helper classes to deal with jet constituents.
@ Phi
Definition RPCdef.h:8
@ Eta
Definition RPCdef.h:8
static const Attributes_t empty
std::vector< bool > m_isDetectorEtaPhi
Gaudi::Property< std::vector< int > > m_altConstitScales
Gaudi::Property< std::vector< std::string > > m_altJetScales
Gaudi::Property< std::vector< std::string > > m_altColls
SG::ReadHandleKeyArray< xAOD::CaloClusterContainer > m_altColls_keys
Gaudi::Property< std::vector< std::string > > m_jetScaleNames
JetConstitFourMomTool(const std::string &myname)
StatusCode modify(xAOD::JetContainer &jets) const
Method to modify a jet collection.
StatusCode initialize()
Dummy implementation of the initialisation function.
Gaudi::Property< int > m_constitScale
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
Property holding a SG store/key/clid from which a ReadHandle is made.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
State
enum of possible signal states.
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
virtual double m() const
The invariant mass of the particle.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
A vector of jet constituents at the scale used during jet finding.
iterator begin() const
iterator on the first constituent
iterator end() const
iterator after the last constituent
JetInput::Type getInputType() const
Definition Jet_v1.cxx:253
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition index.py:1
Jet_v1 Jet
Definition of the current "jet version".
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
JetConstitScale
Definition JetTypes.h:20
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17