ATLAS Offline Software
Loading...
Searching...
No Matches
METJetAssocTool.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7// METJetAssocTool.cxx
8// Implementation file for class METJetAssocTool
9//
10// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11//
12// Author: P Loch, S Resconi, TJ Khoo, AS Mete
14
15// METReconstruction includes
17
18// MET EDM
20
21// Jet EDM
24#include "xAODJet/JetTypes.h"
25
26// Tracking EDM
27#include "xAODTracking/Vertex.h"
28
29// Cluster EDM
31
32// DeltaR calculation
34
35namespace met {
36
37 using namespace xAOD;
38
39 // Constructors
44 {
45 }
46
47 // Athena algtool's Hooks
50 {
52 ATH_MSG_VERBOSE ("Initializing " << name() << "...");
53 //Initialise ReadHandles
54 if(!m_jetContKey.empty())
55 ATH_CHECK( m_jetContKey.initialize());
56
57
58 return StatusCode::SUCCESS;
59 }
60
62 {
63 ATH_MSG_VERBOSE ("In execute: " << name() << "...");
64
65 //empty key -> dont write any jets into map
66 //just add misc assoc and be done with it
67 if(m_jetContKey.empty()){
69 return StatusCode::SUCCESS;
70 }
71
72 // Retrieve the jet container
74 if (!jetCont.isValid()) {
75 ATH_MSG_WARNING("Unable to retrieve input jet container " << m_jetContKey.key());
76 return StatusCode::FAILURE;
77 }
78
79 ATH_MSG_DEBUG("Successfully retrieved jet collection");
80
81 ConstitHolder constits;
82 if (retrieveConstituents(constits).isFailure()) {
83 ATH_MSG_WARNING("Unable to retrieve constituent containers");
84 return StatusCode::FAILURE;
85 }
86
87 std::set<const xAOD::IParticle*> newConst;
88 if (m_skipconst) {
89 for (const auto *const clust : *constits.tcCont) newConst.insert(clust);
90 }
91
92 // Create jet associations
93 for(const auto *const jet : *jetCont) {
94 std::vector<const IParticle*> selectedTracks;
95 bool mismatchedPFlow = m_pflow && (jet->rawConstituent(0)->type()!=xAOD::Type::ParticleFlow && jet->rawConstituent(0)->type()!=xAOD::Type::FlowElement);
96 bool mismatchedState = !m_skipconst && !m_pflow && jet->rawConstituent(0)->type()==xAOD::Type::CaloCluster && ((static_cast<const xAOD::CaloCluster*>(jet->rawConstituent(0))->signalState()==xAOD::CaloCluster::CALIBRATED && jet->getConstituentsSignalState()==xAOD::UncalibratedJetConstituent) || (static_cast<const xAOD::CaloCluster*>(jet->rawConstituent(0))->signalState()==xAOD::CaloCluster::UNCALIBRATED && jet->getConstituentsSignalState()==xAOD::CalibratedJetConstituent));
97 bool newConstVec = m_skipconst || mismatchedPFlow || mismatchedState;
98 if (m_pflow && !mismatchedPFlow) {
99 if(jet->rawConstituent(0)->type() == xAOD::Type::FlowElement){
100 for (size_t consti = 0; consti < jet->numConstituents(); consti++) {
101 const xAOD::FlowElement *pfo = static_cast<const xAOD::FlowElement*>(jet->rawConstituent(consti));
102 ATH_MSG_VERBOSE("Jet constituent PFO, pt :" << pfo->pt() << ", charge: " << pfo->charge());
103 if ((pfo->isCharged()) && (!m_cleanChargedPFO || isGoodEoverP(static_cast<const xAOD::TrackParticle*>(pfo->chargedObject(0))))) {
104 ATH_MSG_VERBOSE(" Accepted charged PFO, pt " << pfo->pt());
105 selectedTracks.push_back(pfo);
106 }
107 }
108 }
109 else{
110 // constituents are xAOD::PFO
111 for (size_t consti = 0; consti < jet->numConstituents(); consti++) {
112 const xAOD::PFO *pfo = static_cast<const xAOD::PFO*>(jet->rawConstituent(consti));
113 ATH_MSG_VERBOSE("Jet constituent PFO, pt :" << pfo->pt() << ", charge: " << pfo->charge());
114 if (pfo->isCharged() && (!m_cleanChargedPFO || isGoodEoverP(pfo->track(0)))) {
115 ATH_MSG_VERBOSE(" Accepted charged PFO, pt " << pfo->pt());
116 selectedTracks.push_back(pfo);
117 }
118 }
119 }
120 } else {
121 std::vector<const IParticle*> jettracks;
122 jet->getAssociatedObjects<IParticle>(JetAttribute::GhostTrack,jettracks);
123
124 selectedTracks.reserve(jettracks.size());
125 for(const auto& trk : jettracks) {
126 const TrackParticle* pTrk = static_cast<const TrackParticle*>(trk);
127 if(acceptTrack(pTrk,constits.pv) && isGoodEoverP(pTrk)) {
128 selectedTracks.push_back(trk);
129 ATH_MSG_VERBOSE("Accept track " << trk << " px, py = " << trk->p4().Px() << ", " << trk->p4().Py());
130 }
131 }
132 }
133 std::vector<const IParticle*> consts;
134 std::map<const IParticle*,MissingETBase::Types::constvec_t> momenta;
135
136 MissingETComposition::add(metMap,jet,selectedTracks);
137 if (mismatchedPFlow) getPFOs(jet,consts,constits,momenta);
138 else if (mismatchedState) getClus(jet,consts);
139 else if (newConstVec) getOther(jet,consts,&newConst);
140 if (newConstVec) MissingETComposition::setJetConstSum(metMap,jet,consts,momenta);
141 ATH_MSG_VERBOSE("Added association " << metMap->findIndex(jet) << " pointing to jet " << jet);
142 ATH_MSG_VERBOSE("Jet pt, eta, phi = " << jet->pt() << ", " << jet->eta() << "," << jet->phi() );
143
144 }
146 ATH_MSG_DEBUG("Added miscellaneous association");
147
148 return StatusCode::SUCCESS;
149 }
150
152 std::vector<const xAOD::IParticle*> &consts,
153 const met::METAssociator::ConstitHolder& constits,
154 std::map<const xAOD::IParticle*,MissingETBase::Types::constvec_t> &momenta) {
155
156 std::vector<const IParticle*> jettracks;
157 jet->getAssociatedObjects<IParticle>(JetAttribute::GhostTrack,jettracks);
158
159 if(constits.feCont != nullptr){
160 // We have PFOs in FlowElement format
161 for(const xAOD::FlowElement* pfo : *constits.feCont) {
162 if (pfo->isCharged()) {
163 const TrackParticle* pfotrk = static_cast<const xAOD::TrackParticle*>(pfo->chargedObject(0));
164 for(const xAOD::IParticle* track : jettracks) {
165 const TrackParticle* jettrk = static_cast<const xAOD::TrackParticle*>(track);
166 if (jettrk==pfotrk) {
167 consts.push_back(pfo);
168 break;
169 }
170 }
171 }
172 else {
173 bool marked = false;
174 for (size_t consti = 0; consti < jet->numConstituents(); consti++){
175 if (pfo->p4().DeltaR(jet->rawConstituent(consti)->p4())<0.05) marked = true;
176 }
177 if (marked) {
178 consts.push_back(pfo);
179 TLorentzVector momentum = pfo->p4();
180 momenta[pfo] = MissingETBase::Types::constvec_t(momentum.Px(),momentum.Py(),momentum.Pz(),
181 momentum.E(),momentum.Pt());
182 }
183 }
184 }
185 }
186 else{
187 // No FlowElements, assume xAOD::PFO format
188 for(const auto *const pfo : *constits.pfoCont) {
189 if (pfo->isCharged()) {
190 const TrackParticle* pfotrk = pfo->track(0);
191 for(const auto& trk : jettracks) {
192 if (trk==pfotrk) {
193 consts.push_back(pfo);
194 break;
195 }
196 }
197 } else {
198 bool marked = false;
199 for (size_t consti = 0; consti < jet->numConstituents(); consti++) if (pfo->p4().DeltaR(jet->rawConstituent(consti)->p4())<0.05) marked = true;
200 if (marked) {
201 consts.push_back(pfo);
202 TLorentzVector momentum = pfo->p4();
203 momenta[pfo] = MissingETBase::Types::constvec_t(momentum.Px(),momentum.Py(),momentum.Pz(),
204 momentum.E(),momentum.Pt());
205 }
206 }
207 }
208 }
209 }
210
212 std::vector<const xAOD::IParticle*> &consts) {
213 std::vector<ElementLink<IParticleContainer> > jetconst = jet->constituentLinks();
214 for(const auto& clus : jetconst) consts.push_back(*clus);
215 }
216
218 std::vector<const xAOD::IParticle*> &consts,
219 std::set<const xAOD::IParticle*> *newConst) const {
220 std::vector<ElementLink<IParticleContainer> > jetconst = jet->constituentLinks();
221 for(const auto& clus : *newConst) if (clus->container()!=jet->rawConstituent(0)->container() && clus->e()>0 && xAOD::P4Helpers::isInDeltaR(*jet,*clus,m_matchRadius,m_useRapidity)) consts.push_back(clus);
222 //for(const auto& clus : *newConst) if (clus->type()!=jet->rawConstituent(0)->type() && clus->e()>0 && xAOD::P4Helpers::isInDeltaR(*jet,*clus,m_matchRadius,m_useRapidity)) consts.push_back(clus);
223 for(const auto& clusL : jetconst) {
224 const xAOD::IParticle *clus = *clusL;
225 if (newConst->count(clus)) consts.push_back(clus);
226 }
227 }
228}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Defines enum to access jet attribute and associated particles/objects.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
METAssociator(const std::string &name)
bool isGoodEoverP(const xAOD::TrackParticle *trk) const
StatusCode retrieveConstituents(met::METAssociator::ConstitHolder &constits) const
bool acceptTrack(const xAOD::TrackParticle *trk, const xAOD::Vertex *pv) const
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::JetContainer > m_jetContKey
Gaudi::Property< double > m_matchRadius
static void getClus(const xAOD::Jet *jet, std::vector< const xAOD::IParticle * > &consts)
static void getPFOs(const xAOD::Jet *jet, std::vector< const xAOD::IParticle * > &consts, const met::METAssociator::ConstitHolder &constits, std::map< const xAOD::IParticle *, MissingETBase::Types::constvec_t > &momenta)
void getOther(const xAOD::Jet *jet, std::vector< const xAOD::IParticle * > &consts, std::set< const xAOD::IParticle * > *newConst) const
METJetAssocTool()
Default constructor:
virtual StatusCode executeTool(xAOD::MissingETContainer *metCont, xAOD::MissingETAssociationMap *metMap) const override
virtual double pt() const override
const xAOD::IParticle * chargedObject(std::size_t i) const
float charge() const
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Class providing the definition of the 4-vector interface.
bool isCharged() const
is a charged PFO
Definition PFO_v1.cxx:251
const TrackParticle * track(unsigned int index) const
Retrieve a const pointer to a Rec::TrackParticle.
Definition PFO_v1.cxx:691
float charge() const
get charge of PFO
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition PFO_v1.cxx:52
xAOD::MissingETAssociation_v1::ConstVec constvec_t
Type for constituent vector.
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
bool isInDeltaR(const xAOD::IParticle &p1, const xAOD::IParticle &p2, double dR, bool useRapidity=true)
Check if 2 xAOD::IParticle are in a cone.
Jet_v1 Jet
Definition of the current "jet version".
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
TrackParticle_v1 TrackParticle
Reference the current persistent version:
MissingETAssociationMap_v1 MissingETAssociationMap
Version control by type defintion.
@ UncalibratedJetConstituent
Definition JetTypes.h:21
@ CalibratedJetConstituent
Definition JetTypes.h:22
const xAOD::IParticleContainer * tcCont
const xAOD::FlowElementContainer * feCont
const xAOD::PFOContainer * pfoCont
static bool addMiscAssociation(MissingETAssociationMap *pMap)
Add an association to hold objects not associated to any jet.
static bool setJetConstSum(MissingETAssociationMap *metMap, const Jet *jet, const std::vector< const IParticle * > &altConsts, std::map< const IParticle *, MissingETBase::Types::constvec_t > pOverride)
static bool add(MissingETComponentMap *pMap, const MissingET *pMET, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Adding a MissingET object to the map.