ATLAS Offline Software
Loading...
Searching...
No Matches
PFMatcher.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * PFMatcher.h
7 *
8 * Created on: 03.04.2014
9 * Author: tlodd
10 */
11
12#ifndef PFMATCHER_H_
13#define PFMATCHER_H_
14
16#include <algorithm>
17#include <utility>
18#include <cmath>
19
20class DistanceProvider;
21
22namespace PFMatch {
23
24 typedef std::pair<ICluster*,double> MatchDistance;
25
30public:
31 TrackClusterMatcher( std::unique_ptr<IDistanceProvider> distanceProvider, double matchCut):
32 m_distanceProvider(std::move(distanceProvider)), m_matchCut(matchCut) { setDRParameters(); }
33
35
36 MatchDistance match(ITrack* track, ICluster* cluster) const;
37
38 template<class ClusterType>
40 ITrack* track,
41 const std::vector<ClusterType*>& clusters) const;
42 template<class ClusterType>
43 std::vector<MatchDistance> bestMatches(ITrack* track,
44 std::vector<ClusterType*>& clusters,
45 int nMatches,
46 double energyThreshold) const;
47private:
48
49 std::unique_ptr<IDistanceProvider> m_distanceProvider;
50 double m_matchCut;
52 float m_drcut_par[9][3];
53
55 void setDRParameters();
56
57
58};
59
60template<class ClusterType>
61 MatchDistance TrackClusterMatcher::bestMatchDRparametrized(ITrack* track, const std::vector<ClusterType*>& clusters) const {
62 ClusterType* bestCluster = nullptr;
63 double bestDistance(m_matchCut);
64 unsigned int nClusters(clusters.size());
65 for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster){
66
67 ClusterType* thisCluster = clusters[iCluster];
68 double thisDistance(m_distanceProvider->distanceBetween(track, clusters[iCluster]));
69 double mybestdistance = getDRCutSquared(thisCluster);
70
71 if (thisDistance < mybestdistance){
72 if (thisDistance < bestDistance) {
73 bestDistance = thisDistance;
74 bestCluster = thisCluster;
75 }
76 }
77 }
78
79 return MatchDistance(bestCluster, bestDistance);
80 }
81
82template<class ClusterType>
83std::vector<MatchDistance> TrackClusterMatcher::bestMatches(ITrack* track, std::vector<ClusterType*>& clusters, int nMatches, double energyThreshold) const {
84
85 std::vector<MatchDistance> result;
86 unsigned const nClusters(clusters.size());
87
88 if (nMatches == -1) {
89 for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) {
90 ClusterType* thisCluster = clusters[iCluster];
91 double thisDistance(m_distanceProvider->distanceBetween(track, thisCluster));
92 if (thisDistance < m_matchCut) {
93 result.push_back(MatchDistance(thisCluster, thisDistance));
94 }
95 }
96 }
97
98 else{
99 int nLoops = nMatches;
100 std::vector<unsigned int> masked;
101 std::vector<int> maskedType;
102 for (int imatch = 0; imatch < nLoops; ++imatch) {
103 ClusterType* bestCluster = nullptr;
104 double bestDistance(m_matchCut);
105 int iMasked = -1;
106 for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) {
107 /* Do not consider matched ones. */
108 if (masked.size() != 0 && find(masked.begin(), masked.end(), iCluster) != masked.end()) {
109 continue;
110 }
111
112 ClusterType* thisCluster = clusters[iCluster];
113
114 /* Require that first matched cluster energy is above energyThreshold (10% of track energy). */
115 if(imatch == 0 && thisCluster->e() <= energyThreshold) {
116 continue;
117 }
118
119 /* Do not consider the same type (ECAL, HCAL or FCAL) ones. */
120 /* First we check if another ECAL, HCAL or FCAL cluster is found */
121 if ((maskedType.size() != 0 && find(maskedType.begin(), maskedType.end(),
122 thisCluster->getEfRecCluster()->getClusterType()) != maskedType.end())
123 || (thisCluster->getEfRecCluster()->getClusterType() == 4)) { /* then also veto if it is type 4, which means "unknown" type */
124 continue;
125 }
126
127 double thisDistance(m_distanceProvider->distanceBetween(track, thisCluster));
128
129 if (thisDistance < bestDistance) {
130 iMasked = iCluster;
131 bestDistance = thisDistance;
132 bestCluster = thisCluster;
133 }
134 }
135 if (iMasked == -1 || nullptr == bestCluster) break;
136
137 masked.push_back(iMasked);
138 maskedType.push_back(bestCluster->getEfRecCluster()->getClusterType());
139
140 result.push_back(MatchDistance(bestCluster, bestDistance));
141 }
142 assert(maskedType.size() == masked.size());
143 }
144
145 return result;
146
147 }
148
149}
150
151#endif /* PFMATCHER_H_ */
std::vector< MatchDistance > bestMatches(ITrack *track, std::vector< ClusterType * > &clusters, int nMatches, double energyThreshold) const
Definition PFMatcher.h:83
void setDRParameters()
This sets the parameters in the above array.
Definition PFMatcher.cxx:21
TrackClusterMatcher(std::unique_ptr< IDistanceProvider > distanceProvider, double matchCut)
Definition PFMatcher.h:31
std::unique_ptr< IDistanceProvider > m_distanceProvider
Definition PFMatcher.h:49
MatchDistance bestMatchDRparametrized(ITrack *track, const std::vector< ClusterType * > &clusters) const
Definition PFMatcher.h:61
MatchDistance match(ITrack *track, ICluster *cluster) const
Definition PFMatcher.cxx:17
float m_drcut_par[9][3]
This stores the parameters to vary DR cut with Pt.
Definition PFMatcher.h:52
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::pair< ICluster *, double > MatchDistance
Definition PFMatcher.h:24
STL namespace.