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),
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,
61 PFData &data
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 static const std::string cone15Str{"cone_015"};
142 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone15Str);
143 }
144 static const std::string cone2Str{"cone_02"};
145 thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink, cone2Str);
146 }//loop over bestClusters_02
147
148 //This matching scheme is used to match the calorimeter cluster(s) to be used in the charged showers subtraction for this track.
149 std::vector<std::pair<eflowRecCluster *, float>> matchedClusters = m_theMatchingTool->doMatches(thisEfRecTrack, data.clusters,m_nClusterMatchesToUse);
150 for (auto thePair : matchedClusters) {
151 bestClusters.push_back(eflowTrackClusterLink::getInstance(thisEfRecTrack, thePair.first, ctx));
152 if (m_addCPData) deltaRPrime.push_back(std::sqrt(thePair.second));
153 }
154 }
155 else {
156 const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches("cone_02");
157 if (!matchedClusters_02) continue;
158 else bestClusters = *matchedClusters_02;
159 }
160
161 if (bestClusters.empty()) continue;
162
163 if (msgLvl(MSG::DEBUG))
164 {
165 for (auto *thisClusterLink : bestClusters ) {
166 xAOD::CaloCluster* thisCluster = thisClusterLink->getCluster()->getCluster();
167 ATH_MSG_DEBUG("Matched this track to cluster with e,pt, eta and phi " << thisCluster->e() << ", " << thisCluster->pt() << ", " << thisCluster->eta() << " and " << thisCluster->phi());
168 }
169 }
170
171 nMatches++;
172
173 //loop over the matched calorimeter clusters and associate tracks and clusters to each other as needed.
174 unsigned int linkIndex = 0;
175 for (auto *trkClusLink : bestClusters){
176
177 eflowRecCluster *thisEFRecCluster = trkClusLink->getCluster();
178
180 // Look up whether this cluster is intended for recovery
181 if (std::find(data.clusters.begin(), data.clusters.end(), trkClusLink->getCluster()) == data.clusters.end()) {
182 linkIndex++;
183 continue;
184 }
185 }
186
187 eflowTrackClusterLink *trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, thisEFRecCluster, ctx);
188 thisEfRecTrack->addClusterMatch(trackClusterLink);
189 if (m_addCPData) {
190 thisEfRecTrack->addDeltaRPrime(deltaRPrime[linkIndex]);
191 }
192 thisEFRecCluster->addTrackMatch(trackClusterLink);
193 }
194 linkIndex++;
195 }
196
197 /* Create 3 types eflowCaloObjects: track-only, cluster-only, track-cluster-link */
198 std::vector<eflowRecCluster *> clusters(data.clusters.begin(), data.clusters.end());
199 if (m_recoverSplitShowers) std::sort(clusters.begin(), clusters.end(), eflowRecCluster::SortDescendingPt());
200 unsigned int nCaloObjects = eflowCaloObjectMaker::makeTrkCluCaloObjects(data.tracks, clusters, data.caloObjects);
201 ATH_MSG_DEBUG("Created " << nCaloObjects << " eflowCaloObjects.");
202 if (msgLvl(MSG::DEBUG)){
203 for (auto thisEFlowCaloObject : *(data.caloObjects)){
204 ATH_MSG_DEBUG("This eflowCaloObject has " << thisEFlowCaloObject->nTracks() << " tracks and " << thisEFlowCaloObject->nClusters() << " clusters ");
205 for (unsigned int count = 0; count < thisEFlowCaloObject->nTracks(); count++){
206 const xAOD::TrackParticle* thisTrack = thisEFlowCaloObject->efRecTrack(count)->getTrack();
207 ATH_MSG_DEBUG("Have track with e, pt, eta and phi of " << thisTrack->e() << ", " << thisTrack->pt() << ", " << thisTrack->eta() << " and " << thisTrack->phi());
208 }
209 for (unsigned int count = 0; count < thisEFlowCaloObject->nClusters(); count++){
210 const xAOD::CaloCluster* thisCluster = thisEFlowCaloObject->efRecCluster(count)->getCluster();
211 ATH_MSG_DEBUG("Have cluster with e, pt, eta and phi of " << thisCluster->e() << ", " << thisCluster->pt() << ", " << thisCluster->eta() << " and " << thisCluster->phi());
212 }
213 }
214 }
215
216 if (!m_recoverSplitShowers) return nMatches;
217 else return nCaloObj;
218}
219
220
222 std::stringstream result;
223 result << " track with E, eta and phi "<< track->e() << ", " << track->eta() << " and " << track->phi();
224 return result.str();
225}
226
228 std::stringstream result;
229 result << " cluster with E, eta and phi of " << cluster->e() << ", " << cluster->eta() << " and " << cluster->phi();
230 return result.str();
231}
232
233void PFUnifiedMatchingTool::printAllClusters(const std::vector<eflowRecCluster *>& recClusterVector) const {
234
235 for ( const auto *thisEFRecCluster : recClusterVector){
236 if (thisEFRecCluster->getTrackMatches().empty()) {
237 ATH_MSG_DEBUG("Isolated" << printCluster(thisEFRecCluster->getCluster()));
238 } else {
239 ATH_MSG_DEBUG("Matched" << printCluster(thisEFRecCluster->getCluster()));
240 std::vector<eflowTrackClusterLink*> theTrackLinks = thisEFRecCluster->getTrackMatches();
241 for ( auto *thisTrack : theTrackLinks){
242 ATH_MSG_DEBUG("Matched" << printTrack(thisTrack->getTrack()->getTrack()));
243 }
244 }
245 }
246}
247
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
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: