ATLAS Offline Software
Loading...
Searching...
No Matches
PFUnifiedMatchingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "PFData.h"
7
8#include "eflowCaloObject.h"
12#include "eflowRecTrack.h"
15#include "PFClusterFiller.h"
16#include "PFTrackFiller.h"
17
23
24#include <sstream>
25
26using namespace eflowSubtract;
27
28PFUnifiedMatchingTool::PFUnifiedMatchingTool(const std::string &type, const std::string &name, const IInterface *parent) : base_class(type, name, parent),
30{
31}
32
34= default;
35
37{
38
39 ATH_CHECK(m_theEOverPTool.retrieve());
40
41 ATH_CHECK(m_theEOverPTool->fillBinnedParameters(m_binnedParameters.get()));
42
44 if (!m_trkpos)
45 {
46 ATH_MSG_ERROR("Failed to get TrackPositionProvider for cluster preselection!");
47 return StatusCode::FAILURE;
48 }
49
50 //Retrieve track-cluster matching tools
51 ATH_CHECK(m_theMatchingTool.retrieve());
54
55 return StatusCode::SUCCESS;
56
57}
58
60 const EventContext& ctx,
62) const
63{
64
65 if (!data.caloObjects) {
66 ATH_MSG_ERROR("PFData::caloObjects is null; caller must set it before invoking the matching tool");
67 return StatusCode::FAILURE;
68 }
69
70 ATH_MSG_DEBUG("Executing");
71
73 // reset tracks in data and refill only with those needed for split showers
74 data.tracks.clear();
76 }
77
79 // reset clusters in data and refill only with those needed for split showers
80 data.clusters.clear();
82 }
83
84 ATH_MSG_DEBUG("This event has " << data.tracks.size() << " tracks " << data.clusters.size() << " clusters ");
85
86 if (msgLvl(MSG::DEBUG)) printAllClusters(data.clusters);
87
88 unsigned int numMatches = matchAndCreateEflowCaloObj(ctx, data);
89
90 // store numMatches for later use in subtraction tool
91 if (m_recoverSplitShowers) data.nOrigCaloObj = numMatches;
92 else data.nMatches = numMatches;
93
94
95 return StatusCode::SUCCESS;
96}
97
98unsigned int PFUnifiedMatchingTool::matchAndCreateEflowCaloObj(const EventContext& ctx, PFData &data) const{
99
100 //Counts up how many tracks found at least 1 calorimeter cluster matched to it.
101 unsigned int nMatches(0);
102
103 /* Cache the original number of eflowCaloObjects, if there were any */
104 const unsigned int nCaloObj = data.caloObjects->size();
105
106 /* loop tracks in data.tracks and do matching */
107 for (auto *thisEfRecTrack : data.tracks)
108 {
110 if (!thisEfRecTrack->hasBin()) {
111 std::unique_ptr<eflowCaloObject> thisEflowCaloObject = std::make_unique<eflowCaloObject>();
112 thisEflowCaloObject->addTrack(thisEfRecTrack);
113 data.caloObjects->push_back(std::move(thisEflowCaloObject));
114 continue;
115 }
116
117 if (msgLvl(MSG::DEBUG))
118 {
119 const xAOD::TrackParticle *track = thisEfRecTrack->getTrack();
120 ATH_MSG_DEBUG("Matching track with e,pt, eta and phi " << track->e() << ", " << track->pt() << ", " << track->eta() << " and " << track->phi());
121 }
122
123 std::vector<eflowTrackClusterLink*> bestClusters;
124 std::vector<float> deltaRPrime;
125
131 std::vector<std::pair<eflowRecCluster *, float>> bestClusters_02 = m_theMatchingToolForPull_02->doMatches(thisEfRecTrack, data.clusters, -1);
132 for (auto &matchpair : bestClusters_02)
133 {
134 eflowRecCluster *theCluster = matchpair.first;
135 float distancesq = matchpair.second;
136 eflowTrackClusterLink *trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, theCluster, ctx);
137 if (distancesq < 0.15 * 0.15)
138 {
139 // Narrower cone is a subset of the selected clusters
140 // Distance returned is deltaR^2
141 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, "cone_015");
142 }
143 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, "cone_02");
144 }//loop over bestClusters_02
145
146 //This matching scheme is used to match the calorimeter cluster(s) to be used in the charged showers subtraction for this track.
147 std::vector<std::pair<eflowRecCluster *, float>> matchedClusters = m_theMatchingTool->doMatches(thisEfRecTrack, data.clusters,m_nClusterMatchesToUse);
148 for (auto thePair : matchedClusters) {
149 bestClusters.push_back(eflowTrackClusterLink::getInstance(thisEfRecTrack, thePair.first, ctx));
150 if (m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
151 }
152 }
153 else {
154 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches("cone_02");
155 if (!matchedClusters_02) continue;
156 else bestClusters = *matchedClusters_02;
157 }
158
159 if (bestClusters.empty()) continue;
160
161 if (msgLvl(MSG::DEBUG))
162 {
163 for (auto *thisClusterLink : bestClusters ) {
164 xAOD::CaloCluster* thisCluster = thisClusterLink->getCluster()->getCluster();
165 ATH_MSG_DEBUG("Matched this track to cluster with e,pt, eta and phi " << thisCluster->e() << ", " << thisCluster->pt() << ", " << thisCluster->eta() << " and " << thisCluster->phi());
166 }
167 }
168
169 nMatches++;
170
171 //loop over the matched calorimeter clusters and associate tracks and clusters to each other as needed.
172 unsigned int linkIndex = 0;
173 for (auto *trkClusLink : bestClusters){
174
175 eflowRecCluster *thisEFRecCluster = trkClusLink->getCluster();
176
178 // Look up whether this cluster is intended for recovery
179 if (std::find(data.clusters.begin(), data.clusters.end(), trkClusLink->getCluster()) == data.clusters.end()) {
180 linkIndex++;
181 continue;
182 }
183 }
184
185 eflowTrackClusterLink *trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, thisEFRecCluster, ctx);
186 thisEfRecTrack->addClusterMatch(trackClusterLink);
187 if (m_addCPData) {
188 thisEfRecTrack->addDeltaRPrime(deltaRPrime[linkIndex]);
189 }
190 thisEFRecCluster->addTrackMatch(trackClusterLink);
191 }
192 linkIndex++;
193 }
194
195 /* Create 3 types eflowCaloObjects: track-only, cluster-only, track-cluster-link */
196 std::vector<eflowRecCluster *> clusters(data.clusters.begin(), data.clusters.end());
197 if (m_recoverSplitShowers) std::sort(clusters.begin(), clusters.end(), eflowRecCluster::SortDescendingPt());
198 unsigned int nCaloObjects = eflowCaloObjectMaker::makeTrkCluCaloObjects(data.tracks, clusters, data.caloObjects);
199 ATH_MSG_DEBUG("Created " << nCaloObjects << " eflowCaloObjects.");
200 if (msgLvl(MSG::DEBUG)){
201 for (auto thisEFlowCaloObject : *(data.caloObjects)){
202 ATH_MSG_DEBUG("This eflowCaloObject has " << thisEFlowCaloObject->nTracks() << " tracks and " << thisEFlowCaloObject->nClusters() << " clusters ");
203 for (unsigned int count = 0; count < thisEFlowCaloObject->nTracks(); count++){
204 const xAOD::TrackParticle* thisTrack = thisEFlowCaloObject->efRecTrack(count)->getTrack();
205 ATH_MSG_DEBUG("Have track with e, pt, eta and phi of " << thisTrack->e() << ", " << thisTrack->pt() << ", " << thisTrack->eta() << " and " << thisTrack->phi());
206 }
207 for (unsigned int count = 0; count < thisEFlowCaloObject->nClusters(); count++){
208 const xAOD::CaloCluster* thisCluster = thisEFlowCaloObject->efRecCluster(count)->getCluster();
209 ATH_MSG_DEBUG("Have cluster with e, pt, eta and phi of " << thisCluster->e() << ", " << thisCluster->pt() << ", " << thisCluster->eta() << " and " << thisCluster->phi());
210 }
211 }
212 }
213
214 if (!m_recoverSplitShowers) return nMatches;
215 else return nCaloObj;
216}
217
218
220 std::stringstream result;
221 result << " track with E, eta and phi "<< track->e() << ", " << track->eta() << " and " << track->phi();
222 return result.str();
223}
224
226 std::stringstream result;
227 result << " cluster with E, eta and phi of " << cluster->e() << ", " << cluster->eta() << " and " << cluster->phi();
228 return result.str();
229}
230
231void PFUnifiedMatchingTool::printAllClusters(const std::vector<eflowRecCluster *>& recClusterVector) const {
232
233 for ( const auto *thisEFRecCluster : recClusterVector){
234 if (thisEFRecCluster->getTrackMatches().empty()) {
235 ATH_MSG_DEBUG("Isolated" << printCluster(thisEFRecCluster->getCluster()));
236 } else {
237 ATH_MSG_DEBUG("Matched" << printCluster(thisEFRecCluster->getCluster()));
238 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
239 for ( auto *thisTrack : theTrackLinks){
240 ATH_MSG_DEBUG("Matched" << printTrack(thisTrack->getTrack()->getTrack()));
241 }
242 }
243 }
244}
245
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Handle class for reading a decoration on an object.
static void fillClustersToRecover(PFData &data)
static std::unique_ptr< IPositionProvider > Get(const std::string &positionType)
static void fillTracksToRecover(PFData &data)
virtual StatusCode processPFlowData(const EventContext &ctx, PFData &thePFData) const override
static std::string printTrack(const xAOD::TrackParticle *track)
ToolHandle< PFTrackClusterMatchingTool > m_theMatchingToolForPull_015
PFUnifiedMatchingTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< bool > m_recoverSplitShowers
Toggle whether we are recovering split showers or not.
Gaudi::Property< int > m_nClusterMatchesToUse
Number of clusters to match to each track if not doing recover split shower subtraction.
void printAllClusters(const std::vector< eflowRecCluster * > &recClusterVector) const
ToolHandle< IEFlowCellEOverPTool > m_theEOverPTool
Tool for getting e/p values and hadronic shower cell ordering principle parameters.
ToolHandle< PFTrackClusterMatchingTool > m_theMatchingToolForPull_02
std::unique_ptr< eflowEEtaBinnedParameters > m_binnedParameters
static std::string printCluster(const xAOD::CaloCluster *cluster)
virtual StatusCode initialize() override
std::unique_ptr< PFMatch::TrackEtaPhiInFixedLayersProvider > m_trkpos
Track position provider to be used to preselect clusters.
ToolHandle< PFTrackClusterMatchingTool > m_theMatchingTool
Default track-cluster matching tool.
Gaudi::Property< bool > m_addCPData
Toggle whether to decorate eflowRecTrack with additional data for Combined Performance studies.
virtual unsigned int matchAndCreateEflowCaloObj(const EventContext &ctx, PFData &data) const
This matches ID tracks and CaloClusters, and then creates eflowCaloObjects.
static unsigned int makeTrkCluCaloObjects(eflowRecTrackContainer *eflowTrackContainer, eflowRecClusterContainer *eflowClusterContainer, eflowCaloObjectContainer *caloObjectContainer)
Inherits from eflowEEtaBinBase.
This class extends the information about a xAOD::CaloCluster.
void addTrackMatch(eflowTrackClusterLink *trackMatch)
xAOD::CaloCluster * getCluster()
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters).
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual double e() const override final
The total energy of the particle.
static std::string release
Definition computils.h:50
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version: