ATLAS Offline Software
SubjetRecorderTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "xAODJet/JetContainer.h"
9 #include "JetEDM/FastJetUtils.h"
10 
12  AsgTool(name), m_subjetlabel(""), m_subjetcontainername("")
13 {
14  declareProperty("SubjetLabel", m_subjetlabel);
15  declareProperty("SubjetContainerName", m_subjetcontainername);
16 }
17 
18 std::vector<xAOD::Jet *> SubjetRecorderTool::recordSubjets(const std::vector<fastjet::PseudoJet>& subjets, xAOD::Jet &jet) const
19 {
20  // Retrieve or set up subjet container
21  std::string subjet_name = m_subjetlabel;
22  std::string subjet_container_name = m_subjetcontainername;
23  if(subjet_name.empty() || subjet_container_name.empty()) {
24  ATH_MSG_ERROR("Invalid subjet label or container name");
25  return {};
26  }
27  xAOD::JetContainer *subjet_container = nullptr;
28 #ifdef ROOTCORE
29  subjet_container = evtStore()->retrieve<xAOD::JetContainer>(subjet_container_name);
30 #else
31  // Need tryRetrieve to supress some Athena warning. Unfortuantely tryRetrieve isn't in RootCore
32  subjet_container = evtStore()->tryRetrieve<xAOD::JetContainer>(subjet_container_name);
33 #endif
34  if(subjet_container == nullptr) {
35  StatusCode sc;
36  subjet_container = new xAOD::JetContainer;
37  subjet_container->setStore(new xAOD::JetAuxContainer);
38  sc = evtStore()->record(subjet_container, subjet_container_name);
39  if(sc.isFailure()) {
40  ATH_MSG_ERROR("Error recording subjet container (" << subjet_container_name << ")");
41  return {};
42  }
43  sc = evtStore()->record(dynamic_cast<xAOD::JetAuxContainer*>(subjet_container->getStore()), subjet_container_name + "Aux.");
44  if(sc.isFailure()) {
45  ATH_MSG_ERROR("Error recording subjet aux container (" << subjet_container_name << "Aux.)");
46  return {};
47  }
48  }
49 
50  // Create xAOD::Jet's
51  std::vector<const xAOD::Jet *> subj_ptrs_const;
52  std::vector<xAOD::Jet *> subj_ptrs;
53  for(auto it = subjets.begin(); it != subjets.end(); it++) {
54  xAOD::Jet *subj = new xAOD::Jet();
55  subjet_container->push_back(subj);
56  subj_ptrs.push_back(subj);
57  subj_ptrs_const.push_back(subj);
58 
59  // Set 4-mom
60  subj->setJetP4(xAOD::JetFourMom_t(it->pt(), it->eta(), it->phi(), it->m()));
62 
63  // Set constituents
64  jet::JetConstituentFiller confiller;
65  confiller.extractConstituents(*subj, &(*it));
66 
67  // Set author/radius
68  double radius = it->associated_cluster_sequence()->jet_def().R();
69  subj->setSizeParameter(radius);
70  xAOD::JetAlgorithmType::ID alg = xAOD::JetAlgorithmType::algId(it->associated_cluster_sequence()->jet_def().jet_algorithm());
71  subj->setAlgorithmType(alg);
72 
73  // Set association to parent
74  const xAOD::JetContainer *parent_container = dynamic_cast<const xAOD::JetContainer*>(jet.container());
75  ElementLink<xAOD::JetContainer> el_parent(*parent_container, jet.index());
76  subj->setAttribute("Parent", el_parent);
77  }
78 
79  // Set association to subjets
80  jet.setAssociatedObjects(subjet_name, subj_ptrs_const);
81 
82  return subj_ptrs;
83 }
SGout2dot.alg
alg
Definition: SGout2dot.py:243
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
skel.it
it
Definition: skel.GENtoEVGEN.py:423
xAOD::Jet_v1::jetP4
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition: Jet_v1.cxx:76
jet::JetConstituentFiller::extractConstituents
int extractConstituents(xAOD::Jet &jet, const NameList *pghostlabs, const fastjet::PseudoJet *ppj=0)
Build and fill constituents of jet from its PseudoJet (or from ppj) Returns the number of pseudojet c...
Definition: JetConstituentFiller.cxx:41
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SubjetRecorderTool.h
xAOD::Jet_v1::setJetP4
void setJetP4(const JetFourMom_t &p4)
Definition: Jet_v1.cxx:171
SubjetRecorderTool::recordSubjets
std::vector< xAOD::Jet * > recordSubjets(const std::vector< fastjet::PseudoJet > &subjets, xAOD::Jet &jet) const
Definition: SubjetRecorderTool.cxx:18
xAOD::JetConstitScaleMomentum
@ JetConstitScaleMomentum
Definition: JetTypes.h:29
JetConstituentFiller.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
SubjetRecorderTool::SubjetRecorderTool
SubjetRecorderTool(const std::string &name)
Definition: SubjetRecorderTool.cxx:11
xAOD::JetAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: JetAuxContainer_v1.h:37
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::Jet_v1::setSizeParameter
void setSizeParameter(float p)
Definition: Jet_v1.cxx:257
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::JetAlgorithmType::ID
ID
//////////////////////////////////////// JetAlgorithmType::ID defines most common physics jet finding...
Definition: JetContainerInfo.h:29
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::Jet_v1::setAttribute
void setAttribute(const std::string &name, const T &v)
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
SubjetRecorderTool::m_subjetlabel
std::string m_subjetlabel
Definition: SubjetRecorderTool.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SubjetRecorderTool::m_subjetcontainername
std::string m_subjetcontainername
Definition: SubjetRecorderTool.h:29
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
jet::JetConstituentFiller
Definition: JetConstituentFiller.h:27
JetContainer.h
xAOD::JetAlgorithmType::algId
ID algId(const std::string &n)
Converts a string into a JetAlgorithmType::ID.
Definition: JetContainerInfo.cxx:76
JetAuxContainer.h
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition: JetContainer.h:17
FastJetUtils.h
xAOD::Jet_v1::setAlgorithmType
void setAlgorithmType(JetAlgorithmType::ID a)
Definition: Jet_v1.cxx:258
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17