CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TrackCleaner Class Reference

#include <TrackCleaner.h>

Inheritance diagram for TrackCleaner:
PixelTrackCleaner

Public Member Functions

TracksWithRecHits cleanTracks (const TracksWithRecHits &tracksWithRecHits) const override
 
 TrackCleaner (const TrackerTopology *tTopo)
 
 ~TrackCleaner () override
 
- Public Member Functions inherited from PixelTrackCleaner
virtual void cleanTracks (TracksWithTTRHs &tracksWithRecHits) const
 
bool fast () const
 
virtual ~PixelTrackCleaner ()
 

Private Member Functions

bool areSame (const TrackingRecHit *a, const TrackingRecHit *b) const
 
bool canBeMerged (const std::vector< const TrackingRecHit * > &recHitsA, const std::vector< const TrackingRecHit * > &recHitsB) const
 
bool isCompatible (const DetId &i1, const DetId &i2) const
 
std::vector< const TrackingRecHit * > ttrhs (const SeedingHitSet &h) const
 

Private Attributes

const TrackerTopologytTopo_
 

Additional Inherited Members

- Public Types inherited from PixelTrackCleaner
using Record = TrajectoryFilter::Record
 
typedef pixeltrackfitting::TracksWithRecHits TracksWithRecHits
 
using TracksWithTTRHs = pixeltrackfitting::TracksWithTTRHs
 
- Protected Member Functions inherited from PixelTrackCleaner
 PixelTrackCleaner (bool fast=false)
 

Detailed Description

Definition at line 15 of file TrackCleaner.h.

Constructor & Destructor Documentation

TrackCleaner::TrackCleaner ( const TrackerTopology tTopo)
explicit

Definition at line 73 of file TrackCleaner.cc.

73 : tTopo_(tTopo) {}
const TrackerTopology * tTopo_
Definition: TrackCleaner.h:30
TrackCleaner::~TrackCleaner ( )
override

Definition at line 76 of file TrackCleaner.cc.

76 {}

Member Function Documentation

bool TrackCleaner::areSame ( const TrackingRecHit a,
const TrackingRecHit b 
) const
private

Definition at line 79 of file TrackCleaner.cc.

References MillePedeFileConverter_cfg::e, TrackingRecHit::geographicalId(), TrackingRecHit::localPosition(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by canBeMerged(), and cleanTracks().

79  {
80  if (a->geographicalId() != b->geographicalId())
81  return false;
82 
83  if (fabs(a->localPosition().x() - b->localPosition().x()) < 1e-5 &&
84  fabs(a->localPosition().y() - b->localPosition().y()) < 1e-5)
85  return true;
86  else
87  return false;
88 }
T y() const
Definition: PV3DBase.h:60
virtual LocalPoint localPosition() const =0
DetId geographicalId() const
T x() const
Definition: PV3DBase.h:59
bool TrackCleaner::canBeMerged ( const std::vector< const TrackingRecHit * > &  recHitsA,
const std::vector< const TrackingRecHit * > &  recHitsB 
) const
private

Definition at line 135 of file TrackCleaner.cc.

References areSame(), isCompatible(), and convertSQLiteXML::ok.

Referenced by cleanTracks().

136  {
137  bool ok = true;
138 
139  for (vector<const TrackingRecHit *>::const_iterator recHitA = recHitsA.begin(); recHitA != recHitsA.end(); recHitA++)
140  for (vector<const TrackingRecHit *>::const_iterator recHitB = recHitsB.begin(); recHitB != recHitsB.end();
141  recHitB++)
142  if (!areSame(*recHitA, *recHitB))
143  if (!isCompatible((*recHitA)->geographicalId(), (*recHitB)->geographicalId()))
144  ok = false;
145 
146  return ok;
147 }
bool isCompatible(const DetId &i1, const DetId &i2) const
Definition: TrackCleaner.cc:91
bool areSame(const TrackingRecHit *a, const TrackingRecHit *b) const
Definition: TrackCleaner.cc:79
TracksWithRecHits TrackCleaner::cleanTracks ( const TracksWithRecHits tracksWithRecHits) const
overridevirtual

Reimplemented from PixelTrackCleaner.

Definition at line 150 of file TrackCleaner.cc.

References areSame(), canBeMerged(), dqmdumpme::first, HitInfo::getInfo(), mps_fire::i, dqmiolumiharvest::j, keep, LogTrace, min(), convertSQLiteXML::ok, rpcPointValidation_cfi::recHit, edm::second(), PDWG_EXOHSCP_cff::tracks, and tTopo_.

150  {
151  // Local copy
152  TracksWithRecHits tracks = tracks_;
153 
154  typedef map<const TrackingRecHit *, vector<unsigned int>, HitComparator> RecHitMap;
155 
156  vector<bool> keep(tracks.size(), true);
157 
158  int changes;
159 
160  LogTrace("MinBiasTracking") << " [TrackCleaner] initial tracks : " << tracks.size();
161 
162  for (unsigned int i = 0; i < tracks.size(); i++)
163  LogTrace("TrackCleaner") << " Track #" << i << " : " << HitInfo::getInfo(tracks[i].second, tTopo_);
164 
165  do {
166  changes = 0;
167 
168  RecHitMap recHitMap;
169 
170  /*
171  LogTrace("MinBiasTracking")
172  << " [TrackCleaner] fill rechit map";
173 */
174 
175  // Fill the rechit map
176  for (unsigned int i = 0; i < tracks.size(); i++)
177  if (keep[i]) {
178  for (vector<const TrackingRecHit *>::const_iterator recHit = tracks[i].second.begin();
179  recHit != tracks[i].second.end();
180  recHit++)
181  recHitMap[*recHit].push_back(i);
182  }
183 
184  // Look at each track
185  typedef map<unsigned int, int, less<unsigned int> > TrackMap;
186 
187  for (unsigned int i = 0; i < tracks.size(); i++) {
188  // Skip if 'i' already removed
189  if (!keep[i])
190  continue;
191 
192  /*
193 
194  bool addedNewHit = false;
195  do
196  {
197 */
198  TrackMap trackMap;
199 
200  // Go trough all rechits of this track
201  for (vector<const TrackingRecHit *>::const_iterator recHit = tracks[i].second.begin();
202  recHit != tracks[i].second.end();
203  recHit++) {
204  // Get tracks sharing this rechit
205  vector<unsigned int> sharing = recHitMap[*recHit];
206 
207  for (vector<unsigned int>::iterator j = sharing.begin(); j != sharing.end(); j++)
208  if (i < *j)
209  trackMap[*j]++;
210  }
211 
212  // Check for tracks with shared rechits
213  for (TrackMap::iterator sharing = trackMap.begin(); sharing != trackMap.end(); sharing++) {
214  unsigned int j = (*sharing).first;
215  if (!keep[i] || !keep[j])
216  continue;
217 
218  if (tracks[i].second.size() >= 3) { // triplet tracks
219  if ((*sharing).second > min(int(tracks[i].second.size()),
220  int(tracks[j].second.size())) /
221  2) { // more than min(hits1,hits2)/2 rechits are shared
222  if (canBeMerged(tracks[i].second, tracks[j].second)) { // no common layer
223  // merge tracks, add separate hits of the second to the first one
224  for (vector<const TrackingRecHit *>::const_iterator recHit = tracks[j].second.begin();
225  recHit != tracks[j].second.end();
226  recHit++) {
227  bool ok = true;
228  for (vector<const TrackingRecHit *>::const_iterator recHitA = tracks[i].second.begin();
229  recHitA != tracks[i].second.end();
230  recHitA++)
231  if (areSame(*recHit, *recHitA))
232  ok = false;
233 
234  if (ok) {
235  tracks[i].second.push_back(*recHit);
236  recHitMap[*recHit].push_back(i);
237 
238  sort(tracks[i].second.begin(), tracks[i].second.end(), HitComparatorByRadius(tTopo_));
239 
240  //addedNewHit = true;
241  }
242  }
243 
244  LogTrace("TrackCleaner") << " Merge #" << i << " #" << j << ", first now has "
245  << tracks[i].second.size();
246 
247  // Remove second track
248  keep[j] = false;
249 
250  changes++;
251  } else { // there is a common layer, keep smaller impact
252  if (fabs(tracks[i].first->d0()) < fabs(tracks[j].first->d0()))
253  keep[j] = false;
254  else
255  keep[i] = false;
256 
257  LogTrace("TrackCleaner") << " Clash #" << i << " #" << j << " keep lower d0 " << tracks[i].first->d0()
258  << " " << tracks[j].first->d0() << ", keep #"
259  << (keep[i] ? i : (keep[j] ? j : 9999));
260 
261  changes++;
262  }
263  } else { // note more than 50%, but at least two are shared
264  if ((*sharing).second > 1) {
265  if (tracks[i].second.size() != tracks[j].second.size()) { // keep longer
266  if (tracks[i].second.size() > tracks[j].second.size())
267  keep[j] = false;
268  else
269  keep[i] = false;
270  changes++;
271 
272  LogTrace("TrackCleaner") << " Sharing " << (*sharing).second << " remove by size";
273  } else { // keep smaller impact
274  if (fabs(tracks[i].first->d0()) < fabs(tracks[j].first->d0()))
275  keep[j] = false;
276  else
277  keep[i] = false;
278  changes++;
279 
280  LogTrace("TrackCleaner") << " Sharing " << (*sharing).second << " remove by d0";
281  }
282  }
283  }
284  } else { // pair tracks
285  if ((*sharing).second > 0) {
286  // Remove second track
287  keep[j] = false;
288 
289  changes++;
290  }
291  }
292  }
293  /*
294  }
295  while(addedNewHit);
296 */
297  }
298  } while (changes > 0);
299 
300  // Final copy
301  TracksWithRecHits cleaned;
302 
303  for (unsigned int i = 0; i < tracks.size(); i++)
304  if (keep[i])
305  cleaned.push_back(tracks[i]);
306  else
307  delete tracks_[i].first;
308 
309  LogTrace("MinBiasTracking") << " [TrackCleaner] cleaned tracks : " << cleaned.size();
310 
311  for (unsigned int i = 0; i < cleaned.size(); i++)
312  LogTrace("TrackCleaner") << " Track #" << i << " : " << HitInfo::getInfo(cleaned[i].second, tTopo_);
313 
314  return cleaned;
315 }
bool canBeMerged(const std::vector< const TrackingRecHit * > &recHitsA, const std::vector< const TrackingRecHit * > &recHitsB) const
U second(std::pair< T, U > const &p)
const int keep
T min(T a, T b)
Definition: MathUtil.h:58
#define LogTrace(id)
const TrackerTopology * tTopo_
Definition: TrackCleaner.h:30
std::vector< TrackWithRecHits > TracksWithRecHits
bool areSame(const TrackingRecHit *a, const TrackingRecHit *b) const
Definition: TrackCleaner.cc:79
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:19
bool TrackCleaner::isCompatible ( const DetId i1,
const DetId i2 
) const
private

Definition at line 91 of file TrackCleaner.cc.

References funct::abs(), constexpr, flavorHistoryFilter_cfi::dr, PVValHelper::dz, createfilelist::int, SiStripPI::max, PixelSubdetector::PixelBarrel, TrackerTopology::pxbLadder(), TrackerTopology::pxbLayer(), TrackerTopology::pxbModule(), TrackerTopology::pxfBlade(), TrackerTopology::pxfDisk(), TrackerTopology::pxfModule(), TrackerTopology::pxfPanel(), TrackerTopology::pxfSide(), DetId::subdetId(), and tTopo_.

Referenced by canBeMerged().

91  {
92  // different subdet
93  if (i1.subdetId() != i2.subdetId())
94  return true;
95 
96  if (i1.subdetId() == int(PixelSubdetector::PixelBarrel)) { // barrel
97 
98  if (tTopo_->pxbLayer(i1) != tTopo_->pxbLayer(i2))
99  return true;
100 
101  int dphi = abs(int(tTopo_->pxbLadder(i1) - tTopo_->pxbLadder(i2)));
102  //FIXME: non-phase-0 wrap-around is wrong (sh/be 12, 28, 44, 64 in phase-1)
103  // the harm is somewhat minimal with some excess of duplicates.
104  constexpr int max[4] = {20, 32, 44, 64};
105  auto aLayer = tTopo_->pxbLayer(i1) - 1;
106  assert(aLayer < 4);
107  if (dphi > max[aLayer] / 2)
108  dphi = max[aLayer] - dphi;
109 
110  int dz = abs(int(tTopo_->pxbModule(i1) - tTopo_->pxbModule(i2)));
111 
112  if (dphi == 1 && dz <= 1)
113  return true;
114  } else { // endcap
115 
116  if (tTopo_->pxfSide(i1) != tTopo_->pxfSide(i2) || tTopo_->pxfDisk(i1) != tTopo_->pxfDisk(i2))
117  return true;
118 
119  int dphi = abs(int(tTopo_->pxfBlade(i1) - tTopo_->pxfBlade(i2)));
120  constexpr int max = 24; //FIXME: non-phase-0 wrap-around is wrong
121  if (dphi > max / 2)
122  dphi = max - dphi;
123 
124  int dr = abs(int(((tTopo_->pxfModule(i1) - 1) * 2 + (tTopo_->pxfPanel(i1) - 1)) -
125  ((tTopo_->pxfModule(i2) - 1) * 2 + (tTopo_->pxfPanel(i2) - 1))));
126 
127  if (dphi <= 1 && dr <= 1 && !(dphi == 0 && dr == 0))
128  return true;
129  }
130 
131  return false;
132 }
unsigned int pxfDisk(const DetId &id) const
unsigned int pxbLadder(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int pxfModule(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
const TrackerTopology * tTopo_
Definition: TrackCleaner.h:30
unsigned int pxfSide(const DetId &id) const
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
#define constexpr
std::vector<const TrackingRecHit *> TrackCleaner::ttrhs ( const SeedingHitSet h) const
private

Member Data Documentation

const TrackerTopology* TrackCleaner::tTopo_
private

Definition at line 30 of file TrackCleaner.h.

Referenced by cleanTracks(), and isCompatible().