ATLAS Offline Software
METJetAssocTool.cxx
Go to the documentation of this file.
1 
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
22 #include "xAODJet/JetContainer.h"
23 #include "xAODJet/JetAttributes.h"
24 #include "xAODJet/JetTypes.h"
25 
26 // Tracking EDM
27 #include "xAODTracking/Vertex.h"
28 
29 // Cluster EDM
31 
32 // DeltaR calculation
34 
35 namespace met {
36 
37  using namespace xAOD;
38 
39  // Constructors
41  METJetAssocTool::METJetAssocTool(const std::string& name) :
42  AsgTool(name),
44  {
45  }
46 
47  // Athena algtool's Hooks
50  {
52  ATH_MSG_VERBOSE ("Initializing " << name() << "...");
53  //Initialise ReadHandles
54  ATH_CHECK( m_jetContKey.initialize());
55 
56 
57  return StatusCode::SUCCESS;
58  }
59 
61  {
62  ATH_MSG_VERBOSE ("In execute: " << name() << "...");
63 
64  // Retrieve the jet container
66  if (!jetCont.isValid()) {
67  ATH_MSG_WARNING("Unable to retrieve input jet container " << m_jetContKey.key());
68  return StatusCode::FAILURE;
69  }
70 
71  ATH_MSG_DEBUG("Successfully retrieved jet collection");
72 
73  ConstitHolder constits;
74  if (retrieveConstituents(constits).isFailure()) {
75  ATH_MSG_WARNING("Unable to retrieve constituent containers");
76  return StatusCode::FAILURE;
77  }
78 
79  std::set<const xAOD::IParticle*> newConst;
80  if (m_skipconst) {
81  for (const auto *const clust : *constits.tcCont) newConst.insert(clust);
82  }
83 
84  // Create jet associations
85  for(const auto *const jet : *jetCont) {
86  std::vector<const IParticle*> selectedTracks;
87  bool mismatchedPFlow = m_pflow && (jet->rawConstituent(0)->type()!=xAOD::Type::ParticleFlow && jet->rawConstituent(0)->type()!=xAOD::Type::FlowElement);
88  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));
89  bool newConstVec = m_skipconst || mismatchedPFlow || mismatchedState;
90  if (m_pflow && !mismatchedPFlow) {
91  if(jet->rawConstituent(0)->type() == xAOD::Type::FlowElement){
92  for (size_t consti = 0; consti < jet->numConstituents(); consti++) {
93  const xAOD::FlowElement *pfo = static_cast<const xAOD::FlowElement*>(jet->rawConstituent(consti));
94  ATH_MSG_VERBOSE("Jet constituent PFO, pt :" << pfo->pt() << ", charge: " << pfo->charge());
95  if ((pfo->isCharged()) && (!m_cleanChargedPFO || isGoodEoverP(static_cast<const xAOD::TrackParticle*>(pfo->chargedObject(0))))) {
96  ATH_MSG_VERBOSE(" Accepted charged PFO, pt " << pfo->pt());
97  selectedTracks.push_back(pfo);
98  }
99  }
100  }
101  else{
102  // constituents are xAOD::PFO
103  for (size_t consti = 0; consti < jet->numConstituents(); consti++) {
104  const xAOD::PFO *pfo = static_cast<const xAOD::PFO*>(jet->rawConstituent(consti));
105  ATH_MSG_VERBOSE("Jet constituent PFO, pt :" << pfo->pt() << ", charge: " << pfo->charge());
106  if (pfo->isCharged() && (!m_cleanChargedPFO || isGoodEoverP(pfo->track(0)))) {
107  ATH_MSG_VERBOSE(" Accepted charged PFO, pt " << pfo->pt());
108  selectedTracks.push_back(pfo);
109  }
110  }
111  }
112  } else {
113  std::vector<const IParticle*> jettracks;
114  jet->getAssociatedObjects<IParticle>(JetAttribute::GhostTrack,jettracks);
115 
116  selectedTracks.reserve(jettracks.size());
117  for(const auto& trk : jettracks) {
118  const TrackParticle* pTrk = static_cast<const TrackParticle*>(trk);
119  if(acceptTrack(pTrk,constits.pv) && isGoodEoverP(pTrk)) {
120  selectedTracks.push_back(trk);
121  ATH_MSG_VERBOSE("Accept track " << trk << " px, py = " << trk->p4().Px() << ", " << trk->p4().Py());
122  }
123  }
124  }
125  std::vector<const IParticle*> consts;
126  std::map<const IParticle*,MissingETBase::Types::constvec_t> momenta;
127 
128  MissingETComposition::add(metMap,jet,selectedTracks);
129  if (mismatchedPFlow) getPFOs(jet,consts,constits,momenta);
130  else if (mismatchedState) getClus(jet,consts);
131  else if (newConstVec) getOther(jet,consts,&newConst);
132  if (newConstVec) MissingETComposition::setJetConstSum(metMap,jet,consts,momenta);
133  ATH_MSG_VERBOSE("Added association " << metMap->findIndex(jet) << " pointing to jet " << jet);
134  ATH_MSG_VERBOSE("Jet pt, eta, phi = " << jet->pt() << ", " << jet->eta() << "," << jet->phi() );
135 
136  }
138  ATH_MSG_DEBUG("Added miscellaneous association");
139 
140  return StatusCode::SUCCESS;
141  }
142 
144  std::vector<const xAOD::IParticle*> &consts,
145  const met::METAssociator::ConstitHolder& constits,
146  std::map<const xAOD::IParticle*,MissingETBase::Types::constvec_t> &momenta) {
147 
148  std::vector<const IParticle*> jettracks;
149  jet->getAssociatedObjects<IParticle>(JetAttribute::GhostTrack,jettracks);
150 
151  if(constits.feCont != nullptr){
152  // We have PFOs in FlowElement format
153  for(const xAOD::FlowElement* pfo : *constits.feCont) {
154  if (pfo->isCharged()) {
155  const TrackParticle* pfotrk = static_cast<const xAOD::TrackParticle*>(pfo->chargedObject(0));
156  for(const xAOD::IParticle* track : jettracks) {
157  const TrackParticle* jettrk = static_cast<const xAOD::TrackParticle*>(track);
158  if (jettrk==pfotrk) {
159  consts.push_back(pfo);
160  break;
161  }
162  }
163  }
164  else {
165  bool marked = false;
166  for (size_t consti = 0; consti < jet->numConstituents(); consti++){
167  if (pfo->p4().DeltaR(jet->rawConstituent(consti)->p4())<0.05) marked = true;
168  }
169  if (marked) {
170  consts.push_back(pfo);
171  TLorentzVector momentum = pfo->p4();
172  momenta[pfo] = MissingETBase::Types::constvec_t(momentum.Px(),momentum.Py(),momentum.Pz(),
173  momentum.E(),momentum.Pt());
174  }
175  }
176  }
177  }
178  else{
179  // No FlowElements, assume xAOD::PFO format
180  for(const auto *const pfo : *constits.pfoCont) {
181  if (pfo->isCharged()) {
182  const TrackParticle* pfotrk = pfo->track(0);
183  for(const auto& trk : jettracks) {
184  if (trk==pfotrk) {
185  consts.push_back(pfo);
186  break;
187  }
188  }
189  } else {
190  bool marked = false;
191  for (size_t consti = 0; consti < jet->numConstituents(); consti++) if (pfo->p4().DeltaR(jet->rawConstituent(consti)->p4())<0.05) marked = true;
192  if (marked) {
193  consts.push_back(pfo);
194  TLorentzVector momentum = pfo->p4();
195  momenta[pfo] = MissingETBase::Types::constvec_t(momentum.Px(),momentum.Py(),momentum.Pz(),
196  momentum.E(),momentum.Pt());
197  }
198  }
199  }
200  }
201  }
202 
204  std::vector<const xAOD::IParticle*> &consts) {
205  std::vector<ElementLink<IParticleContainer> > jetconst = jet->constituentLinks();
206  for(const auto& clus : jetconst) consts.push_back(*clus);
207  }
208 
210  std::vector<const xAOD::IParticle*> &consts,
211  std::set<const xAOD::IParticle*> *newConst) const {
212  std::vector<ElementLink<IParticleContainer> > jetconst = jet->constituentLinks();
213  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);
214  //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);
215  for(const auto& clusL : jetconst) {
216  const xAOD::IParticle *clus = *clusL;
217  if (newConst->count(clus)) consts.push_back(clus);
218  }
219  }
220 }
METJetAssocTool.h
xAOD::PFO_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition: PFO_v1.cxx:52
met::METJetAssocTool::getOther
void getOther(const xAOD::Jet *jet, std::vector< const xAOD::IParticle * > &consts, std::set< const xAOD::IParticle * > *newConst) const
Definition: METJetAssocTool.cxx:209
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
xAOD::MissingETComposition::addMiscAssociation
static bool addMiscAssociation(MissingETAssociationMap *pMap)
Add an association to hold objects not associated to any jet.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:227
xAOD::PFO_v1::track
const TrackParticle * track(unsigned int index) const
Retrieve a const pointer to a Rec::TrackParticle.
Definition: PFO_v1.cxx:691
met::METAssociator::retrieveConstituents
StatusCode retrieveConstituents(met::METAssociator::ConstitHolder &constits) const
Definition: METAssociator.cxx:161
JetAttributes.h
met::METAssociator::ConstitHolder::pfoCont
const xAOD::PFOContainer * pfoCont
Definition: METAssociator.h:66
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
met::METJetAssocTool::m_matchRadius
Gaudi::Property< double > m_matchRadius
Definition: METJetAssocTool.h:88
met::METAssociator::ConstitHolder::feCont
const xAOD::FlowElementContainer * feCont
Definition: METAssociator.h:67
xAOD::FlowElement_v1::pt
virtual double pt() const override
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
met::METAssociator::m_useRapidity
bool m_useRapidity
Definition: METAssociator.h:105
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::MissingETAssociationMap_v1
Definition: MissingETAssociationMap_v1.h:29
met::METAssociator::ConstitHolder::pv
const xAOD::Vertex * pv
Definition: METAssociator.h:68
xAOD::FlowElement_v1::isCharged
bool isCharged() const
Definition: FlowElement_v1.cxx:56
met::METJetAssocTool::getClus
static void getClus(const xAOD::Jet *jet, std::vector< const xAOD::IParticle * > &consts)
Definition: METJetAssocTool.cxx:203
met::METAssociator::ConstitHolder::tcCont
const xAOD::IParticleContainer * tcCont
Definition: METAssociator.h:65
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
met
Definition: IMETSignificance.h:24
met::METAssociator::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METAssociator.cxx:85
xAOD::MissingETAssociationMap_v1::findIndex
size_t findIndex(const Jet *pJet) const
Definition: MissingETAssociationMap_v1.cxx:60
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
xAOD::CaloCluster_v1::CALIBRATED
@ CALIBRATED
Definition: CaloCluster_v1.h:307
CaloCluster.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
xAOD::PFO_v1::charge
float charge() const
get charge of PFO
xAOD::FlowElement_v1::charge
float charge() const
MissingETBase::Types::constvec_t
xAOD::MissingETAssociation_v1::ConstVec constvec_t
Type for constituent vector.
Definition: MissingETAssociation_v1.h:457
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
xAOD::CalibratedJetConstituent
@ CalibratedJetConstituent
Definition: JetTypes.h:22
xAOD::MissingETComposition::setJetConstSum
static bool setJetConstSum(MissingETAssociationMap *metMap, const Jet *jet, const std::vector< const IParticle * > &altConsts, std::map< const IParticle *, MissingETBase::Types::constvec_t > pOverride)
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:296
Vertex.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::PFO_v1::isCharged
bool isCharged() const
is a charged PFO
Definition: PFO_v1.cxx:251
met::METAssociator
Definition: METAssociator.h:55
xAOD::CaloCluster_v1::UNCALIBRATED
@ UNCALIBRATED
Definition: CaloCluster_v1.h:306
xAOD::FlowElement_v1::chargedObject
const xAOD::IParticle * chargedObject(std::size_t i) const
Definition: FlowElement_v1.cxx:127
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
xAOD::MissingETComposition::add
static bool add(MissingETComponentMap *pMap, const MissingET *pMET, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Adding a MissingET object to the map.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:29
met::METAssociator::isGoodEoverP
bool isGoodEoverP(const xAOD::TrackParticle *trk) const
Definition: METAssociator.cxx:367
met::METAssociator::acceptTrack
bool acceptTrack(const xAOD::TrackParticle *trk, const xAOD::Vertex *pv) const
Definition: METAssociator.cxx:359
met::METJetAssocTool::executeTool
virtual StatusCode executeTool(xAOD::MissingETContainer *metCont, xAOD::MissingETAssociationMap *metMap) const override
Definition: METJetAssocTool.cxx:60
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::FlowElement_v1::p4
virtual FourMom_t p4() const override
The full 4-momentum of the particle.
Definition: FlowElement_v1.cxx:33
xAOD::UncalibratedJetConstituent
@ UncalibratedJetConstituent
Definition: JetTypes.h:21
JetContainer.h
met::METJetAssocTool::METJetAssocTool
METJetAssocTool()
Default constructor:
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
met::METAssociator::m_pflow
bool m_pflow
Definition: METAssociator.h:103
met::METJetAssocTool::getPFOs
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)
Definition: METJetAssocTool.cxx:143
met::METJetAssocTool::m_jetContKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetContKey
Definition: METJetAssocTool.h:78
met::METAssociator::m_skipconst
bool m_skipconst
Definition: METAssociator.h:111
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
xAOD::TrackParticle_v1::track
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
Definition: TrackParticle_v1.cxx:805
xAOD::P4Helpers::isInDeltaR
bool isInDeltaR(const xAOD::IParticle &p1, const xAOD::IParticle &p2, double dR, bool useRapidity=true)
Check if 2 xAOD::IParticle are in a cone.
Definition: xAODP4Helpers.h:174
JetTypes.h
xAOD::JetAttribute::GhostTrack
@ GhostTrack
Definition: JetAttributes.h:252
met::METAssociator::m_cleanChargedPFO
bool m_cleanChargedPFO
Definition: METAssociator.h:109
MissingETComposition.h
met::METAssociator::ConstitHolder
Definition: METAssociator.h:62
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25
met::METJetAssocTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: METJetAssocTool.cxx:49