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 
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 }
mps_fire.i
i
Definition: mps_fire.py:428
PixelTrackCleaner::TracksWithTTRHs
pixeltrackfitting::TracksWithTTRHs TracksWithTTRHs
Definition: PixelTrackCleaner.h:33
MessageLogger.h
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
indexGen.s2
s2
Definition: indexGen.py:107
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
PixelTrackCleanerBySharedHits::PixelTrackCleanerBySharedHits
PixelTrackCleanerBySharedHits(bool useQuadrupletAlgo)
Definition: PixelTrackCleanerBySharedHits.cc:14
PixelTrackCleanerBySharedHits::useQuadrupletAlgo_
const bool useQuadrupletAlgo_
Definition: PixelTrackCleanerBySharedHits.h:27
TrackerTopology.h
TrackingRecHit.h
Track.h
pixeltrackfitting
Definition: TracksWithHits.h:10
dqmdumpme.k
k
Definition: dqmdumpme.py:60
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
funct::true
true
Definition: Factorize.h:173
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
PixelTrackCleanerBySharedHits::cleanTracks
void cleanTracks(TracksWithTTRHs &tracksWithRecHits) const override
Definition: PixelTrackCleanerBySharedHits.cc:20
HLT_FULL_cff.useQuadrupletAlgo
useQuadrupletAlgo
Definition: HLT_FULL_cff.py:7957
PixelTrackCleaner
Definition: PixelTrackCleaner.h:14
PixelTrackCleanerBySharedHits::~PixelTrackCleanerBySharedHits
~PixelTrackCleanerBySharedHits() override
Definition: PixelTrackCleanerBySharedHits.cc:18
std
Definition: JetResolutionObject.h:76
PixelTrackCleanerBySharedHits::TrackWithTTRHs
pixeltrackfitting::TrackWithTTRHs TrackWithTTRHs
Definition: PixelTrackCleanerBySharedHits.h:22
PixelTrackCleanerBySharedHits.h
offlineSlimmedPrimaryVertices_cfi.score
score
Definition: offlineSlimmedPrimaryVertices_cfi.py:6
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443