ATLAS Offline Software
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 
20 class DistanceProvider;
21 
22 namespace PFMatch {
23 
24  typedef std::pair<ICluster*,double> MatchDistance;
25 
30 public:
31  TrackClusterMatcher( std::unique_ptr<IDistanceProvider> distanceProvider, double matchCut):
32  m_distanceProvider(std::move(distanceProvider)), m_matchCut(matchCut) { setDRParameters(); }
33 
34  virtual ~TrackClusterMatcher() {};
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;
47 private:
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 
60 template<class ClusterType>
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 
82 template<class ClusterType>
83 std::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_ */
PFMatch::MatchDistance
std::pair< ICluster *, double > MatchDistance
Definition: PFMatcher.h:24
PFMatchInterfaces.h
get_generator_info.result
result
Definition: get_generator_info.py:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
PFMatch::ICluster
Definition: PFMatchInterfaces.h:37
PFMatch::ITrack
Definition: PFMatchInterfaces.h:28
PFMatch::TrackClusterMatcher::m_matchCut
double m_matchCut
Definition: PFMatcher.h:50
PFMatch::TrackClusterMatcher
Checks if a cluster should be matched to a track or not, and has methods to return list of best match...
Definition: PFMatcher.h:29
PFMatch::TrackClusterMatcher::~TrackClusterMatcher
virtual ~TrackClusterMatcher()
Definition: PFMatcher.h:34
PFMatch::TrackClusterMatcher::bestMatchDRparametrized
MatchDistance bestMatchDRparametrized(ITrack *track, const std::vector< ClusterType * > &clusters) const
Definition: PFMatcher.h:61
PFMatch::TrackClusterMatcher::m_distanceProvider
std::unique_ptr< IDistanceProvider > m_distanceProvider
Definition: PFMatcher.h:49
PFMatch::TrackClusterMatcher::TrackClusterMatcher
TrackClusterMatcher(std::unique_ptr< IDistanceProvider > distanceProvider, double matchCut)
Definition: PFMatcher.h:31
PFMatch
Definition: PFMatchDistance.h:17
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
PFMatch::TrackClusterMatcher::match
MatchDistance match(ITrack *track, ICluster *cluster) const
Definition: PFMatcher.cxx:17
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
PFMatch::TrackClusterMatcher::bestMatches
std::vector< MatchDistance > bestMatches(ITrack *track, std::vector< ClusterType * > &clusters, int nMatches, double energyThreshold) const
Definition: PFMatcher.h:83
PFMatch::TrackClusterMatcher::setDRParameters
void setDRParameters()
This sets the parameters in the above array.
Definition: PFMatcher.cxx:21
PFMatch::TrackClusterMatcher::m_drcut_par
float m_drcut_par[9][3]
This stores the parameters to vary DR cut with Pt.
Definition: PFMatcher.h:52