ATLAS Offline Software
Loading...
Searching...
No Matches
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
10
11SubjetRecorderTool::SubjetRecorderTool(const std::string& name) :
13{
14 declareProperty("SubjetLabel", m_subjetlabel);
15 declareProperty("SubjetContainerName", m_subjetcontainername);
16}
17
18std::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
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}
#define ATH_MSG_ERROR(x)
static Double_t sc
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
value_type push_back(value_type pElem)
Add an element to the end of the collection.
std::string m_subjetcontainername
std::vector< xAOD::Jet * > recordSubjets(const std::vector< fastjet::PseudoJet > &subjets, xAOD::Jet &jet) const
SubjetRecorderTool(const std::string &name)
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
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...
void setAlgorithmType(JetAlgorithmType::ID a)
Definition Jet_v1.cxx:258
void setAttribute(const std::string &name, const T &v)
void setJetP4(const JetFourMom_t &p4)
Definition Jet_v1.cxx:171
void setSizeParameter(float p)
Definition Jet_v1.cxx:257
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Definition Jet_v1.cxx:76
ID algId(const std::string &n)
Converts a string into a JetAlgorithmType::ID.
ID
//////////////////////////////////////// JetAlgorithmType::ID defines most common physics jet finding...
Jet_v1 Jet
Definition of the current "jet version".
JetAuxContainer_v1 JetAuxContainer
Definition of the current jet auxiliary container.
@ JetConstitScaleMomentum
Definition JetTypes.h:29
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17