CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelTrackCleanerBySharedHits.cc
Go to the documentation of this file.
2 
7 #include <cassert>
8 #include <cstdint>
9 
10 using namespace std;
11 using namespace reco;
12 using namespace pixeltrackfitting;
13 
15  : PixelTrackCleaner(true), // to mark this as fast algo
16  useQuadrupletAlgo_(useQuadrupletAlgo) {}
17 
19 
21  LogDebug("PixelTrackCleanerBySharedHits") << "Cleanering tracks"
22  << "\n";
23  unsigned int size = trackHitPairs.size();
24  if (size <= 1)
25  return;
26 
27  // sort (stabilize cleaning)
28  uint16_t score[size];
29  unsigned int ind[size];
30  for (auto i = 0U; i < size; ++i) {
31  ind[i] = i;
32  score[i] = 32000 - std::min(32000, int(trackHitPairs[i].first->chi2() * 100.f)); // chi2: smaller is better
33  if (trackHitPairs[i].second.size() == 4)
34  score[i] += 32001; // s4 always better than s3
35  }
36  std::sort(ind, ind + size, [&](unsigned int i, unsigned int j) { return score[i] > score[j]; });
37 
38  auto kill = [&](unsigned int k) {
39  delete trackHitPairs[k].first;
40  trackHitPairs[k].first = nullptr;
41  };
42 
43  // sorted: first is always better!
44 
45  // first loop: only first two hits....
46  for (auto i = 0U; i < size; ++i) {
47  auto iTrack1 = ind[i];
48  auto track1 = trackHitPairs[iTrack1].first;
49  if (!track1)
50  continue;
51  auto const& recHits1 = trackHitPairs[iTrack1].second;
52  for (auto j = i + 1; j < size; ++j) {
53  auto iTrack2 = ind[j];
54  auto track2 = trackHitPairs[iTrack2].first;
55  if (!track2)
56  continue;
57  auto const& recHits2 = trackHitPairs[iTrack2].second;
58  if (recHits1[0] != recHits2[0])
59  continue;
60  if (recHits1[1] != recHits2[1])
61  continue;
62  kill(iTrack2);
63  } // tk2
64  } // tk1
65 
66  // second loop: first and third hits....
67  for (auto i = 0U; i < size; ++i) {
68  auto iTrack1 = ind[i];
69  auto track1 = trackHitPairs[iTrack1].first;
70  if (!track1)
71  continue;
72  auto const& recHits1 = trackHitPairs[iTrack1].second;
73  if (recHits1.size() < 3)
74  continue;
75  for (auto j = i + 1; j < size; ++j) {
76  auto iTrack2 = ind[j];
77  auto track2 = trackHitPairs[iTrack2].first;
78  if (!track2)
79  continue;
80  auto const& recHits2 = trackHitPairs[iTrack2].second;
81  if (recHits2.size() < 3)
82  continue;
83  if (recHits1[0] != recHits2[0])
84  continue;
85  if (recHits1[2] != recHits2[2])
86  continue;
87  kill(iTrack2);
88  } // tk2
89  } // tk1
90 
91  // final loop: all the rest
92  for (auto i = 0U; i < size; ++i) {
93  auto iTrack1 = ind[i];
94  auto track1 = trackHitPairs[iTrack1].first;
95  if (!track1)
96  continue;
97  auto const& recHits1 = trackHitPairs[iTrack1].second;
98  auto s1 = recHits1.size();
99  for (auto j = i + 1; j < size; ++j) {
100  auto iTrack2 = ind[j];
101  auto track2 = trackHitPairs[iTrack2].first;
102  if (!track2)
103  continue;
104  auto const& recHits2 = trackHitPairs[iTrack2].second;
105  auto s2 = recHits2.size();
106  auto commonRecHits = 0U;
107  auto f2 = 0U;
108  for (auto iRecHit1 = 0U; iRecHit1 < s1; ++iRecHit1) {
109  for (auto iRecHit2 = f2; iRecHit2 < s2; ++iRecHit2) {
110  if (recHits1[iRecHit1] == recHits2[iRecHit2]) {
111  ++commonRecHits;
112  f2 = iRecHit2 + 1;
113  break;
114  } // if a hit is common, no other can be the same!
115  }
116  if (commonRecHits > 1)
117  break;
118  }
119  if (useQuadrupletAlgo_) {
120  if (commonRecHits >= 1) {
121  if (s1 == 3 || commonRecHits > 1) {
122  kill(iTrack2);
123  }
124  }
125  } else if (commonRecHits > 1) {
126  kill(iTrack2);
127  }
128  } // tk2
129  } //tk1
130 
131  trackHitPairs.erase(
132  std::remove_if(trackHitPairs.begin(), trackHitPairs.end(), [&](TrackWithTTRHs& v) { return nullptr == v.first; }),
133  trackHitPairs.end());
134 }
PixelTrackCleanerBySharedHits(bool useQuadrupletAlgo)
U second(std::pair< T, U > const &p)
T min(T a, T b)
Definition: MathUtil.h:58
tuple useQuadrupletAlgo
void cleanTracks(TracksWithTTRHs &tracksWithRecHits) const override
pixeltrackfitting::TrackWithTTRHs TrackWithTTRHs
pixeltrackfitting::TracksWithTTRHs TracksWithTTRHs
tuple size
Write out results.
#define LogDebug(id)