ATLAS Offline Software
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 
47  m_isDetectorEtaPhi.resize(m_jetScaleNames.size());
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 }
JetConstitFourMomTool::m_altColls
Gaudi::Property< std::vector< std::string > > m_altColls
Definition: JetConstitFourMomTool.h:41
xAOD::CaloCluster_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: CaloCluster_v1.cxx:256
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
JetConstitFourMomTool::m_altJetScales
Gaudi::Property< std::vector< std::string > > m_altJetScales
Definition: JetConstitFourMomTool.h:43
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
xAOD::JetConstituentVector::end
iterator end() const
iterator after the last constituent
Definition: JetConstituentVector.cxx:104
xAOD::CaloCluster_v1::State
State
enum of possible signal states.
Definition: CaloCluster_v1.h:304
asg
Definition: DataHandleTestTool.h:28
xAOD::CaloCluster_v1::m
virtual double m() const
The invariant mass of the particle.
Definition: CaloCluster_v1.cxx:261
Phi
@ Phi
Definition: RPCdef.h:8
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< xAOD::CaloClusterContainer >
JetConstituentVector.h
This file defines helper classes to deal with jet constituents.
xAOD::Jet_v1::getInputType
JetInput::Type getInputType() const
Definition: Jet_v1.cxx:253
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
xAOD::JetInput::isValidConstitType
bool isValidConstitType(Type t)
Definition: JetContainerInfo.cxx:193
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
JetConstitFourMomTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetConstitFourMomTool.cxx:24
xAOD::JetConstituentVector::begin
iterator begin() const
iterator on the first constituent
Definition: JetConstituentVector.cxx:103
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
JetConstitFourMomTool::m_altColls_keys
SG::ReadHandleKeyArray< xAOD::CaloClusterContainer > m_altColls_keys
Definition: JetConstitFourMomTool.h:47
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Definition: CaloCluster_v1.cxx:247
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
JetConstitFourMomTool.h
JetConstitFourMomTool::m_altConstitScales
Gaudi::Property< std::vector< int > > m_altConstitScales
Definition: JetConstitFourMomTool.h:42
xAOD::JetConstitScale
JetConstitScale
Definition: JetTypes.h:20
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
JetConstitFourMomTool::m_jetScaleNames
Gaudi::Property< std::vector< std::string > > m_jetScaleNames
Definition: JetConstitFourMomTool.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
JetConstitFourMomTool::m_isDetectorEtaPhi
std::vector< bool > m_isDetectorEtaPhi
Definition: JetConstitFourMomTool.h:45
JetConstitFourMomTool::modify
StatusCode modify(xAOD::JetContainer &jets) const
Method to modify a jet collection.
Definition: JetConstitFourMomTool.cxx:63
JetConstitFourMomTool::JetConstitFourMomTool
JetConstitFourMomTool(const std::string &myname)
Definition: JetConstitFourMomTool.cxx:14
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::JetConstituentVector
A vector of jet constituents at the scale used during jet finding.
Definition: JetConstituentVector.h:117
JetTypes.h
JetConstitFourMomTool::m_constitScale
Gaudi::Property< int > m_constitScale
Definition: JetConstitFourMomTool.h:39
Eta
@ Eta
Definition: RPCdef.h:8
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37