CMS 3D CMS Logo

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 {}
18 
20 {}
21 
22 
24 {
25 
26  LogDebug("PixelTrackCleanerBySharedHits") << "Cleanering tracks" << "\n";
27  unsigned int size = trackHitPairs.size();
28  if (size <= 1) return;
29 
30  // sort (stabilize cleaning)
31  uint16_t score[size];
32  unsigned int ind[size];
33  for (auto i = 0U; i < size; ++i) {
34  ind[i]=i;
35  score[i]= 32000-std::min(32000, int(trackHitPairs[i].first->chi2()*100.f)); // chi2: smaller is better
36  if (trackHitPairs[i].second.size()==4) score[i]+=32001; // s4 always better than s3
37  }
38  std::sort(ind,ind+size,[&](unsigned int i, unsigned int j){return score[i]>score[j];});
39 
40  auto kill = [&](unsigned int k) {delete trackHitPairs[k].first; trackHitPairs[k].first=nullptr;};
41 
42  // sorted: first is always better!
43 
44  // first loop: only first two hits....
45  for (auto i = 0U; i < size; ++i) {
46  auto iTrack1 = ind[i];
47  auto track1 = trackHitPairs[iTrack1].first;
48  if (!track1) continue;
49  auto const & recHits1 = trackHitPairs[iTrack1].second;
50  for (auto j = i+1; j < size; ++j) {
51  auto iTrack2 = ind[j];
52  auto track2 = trackHitPairs[iTrack2].first;
53  if (!track2) continue;
54  auto const & recHits2 = trackHitPairs[iTrack2].second;
55  if (recHits1[0] != recHits2[0]) continue;
56  if (recHits1[1] != recHits2[1]) continue;
57  kill(iTrack2);
58  } // tk2
59  } // tk1
60 
61 
62  // second loop: first and third hits....
63  for (auto i = 0U; i < size; ++i) {
64  auto iTrack1 = ind[i];
65  auto track1 = trackHitPairs[iTrack1].first;
66  if (!track1) continue;
67  auto const & recHits1 = trackHitPairs[iTrack1].second;
68  if (recHits1.size()<3) continue;
69  for (auto j = i+1; j < size; ++j) {
70  auto iTrack2 = ind[j];
71  auto track2 = trackHitPairs[iTrack2].first;
72  if (!track2) continue;
73  auto const & recHits2 = trackHitPairs[iTrack2].second;
74  if (recHits2.size()<3) continue;
75  if (recHits1[0] != recHits2[0]) continue;
76  if (recHits1[2] != recHits2[2]) continue;
77  kill(iTrack2);
78  } // tk2
79  } // tk1
80 
81 
82  // final loop: all the rest
83  for (auto i = 0U; i < size; ++i) {
84  auto iTrack1 = ind[i];
85  auto track1 = trackHitPairs[iTrack1].first;
86  if (!track1) continue;
87  auto const & recHits1 = trackHitPairs[iTrack1].second;
88  auto s1 = recHits1.size();
89  for (auto j = i+1; j < size; ++j) {
90  auto iTrack2 = ind[j];
91  auto track2 = trackHitPairs[iTrack2].first;
92  if (!track2) continue;
93  auto const & recHits2 = trackHitPairs[iTrack2].second;
94  auto s2 = recHits2.size();
95  auto commonRecHits = 0U;
96  auto f2=0U;
97  for (auto iRecHit1 = 0U; iRecHit1 < s1; ++iRecHit1) {
98  for (auto iRecHit2 = f2; iRecHit2 < s2; ++iRecHit2) {
99  if (recHits1[iRecHit1] == recHits2[iRecHit2]) { ++commonRecHits; f2=iRecHit2+1; break;} // if a hit is common, no other can be the same!
100  }
101  if (commonRecHits > 1) break;
102  }
103  if(useQuadrupletAlgo_) {
104  if(commonRecHits >= 1) {
105  if(s1 == 3 || commonRecHits > 1) { kill(iTrack2); }
106  }
107  }
108  else if (commonRecHits > 1) {
109  kill(iTrack2);
110  }
111  } // tk2
112  } //tk1
113 
114  trackHitPairs.erase(std::remove_if(trackHitPairs.begin(),trackHitPairs.end(),[&](TrackWithTTRHs & v){ return nullptr==v.first;}),trackHitPairs.end());
115 }
#define LogDebug(id)
size
Write out results.
PixelTrackCleanerBySharedHits(bool useQuadrupletAlgo)
U second(std::pair< T, U > const &p)
T min(T a, T b)
Definition: MathUtil.h:58
int k[5][pyjets_maxn]
void cleanTracks(TracksWithTTRHs &tracksWithRecHits) const override
fixed size matrix
pixeltrackfitting::TrackWithTTRHs TrackWithTTRHs
pixeltrackfitting::TracksWithTTRHs TracksWithTTRHs