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 75 of file TrackCleaner.cc.

75  : tTopo_(tTopo)
76 {
77 }
const TrackerTopology * tTopo_
Definition: TrackCleaner.h:34
TrackCleaner::~TrackCleaner ( )
override

Definition at line 80 of file TrackCleaner.cc.

81 {
82 }

Member Function Documentation

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

Definition at line 85 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().

87 {
88  if(a->geographicalId() != b->geographicalId())
89  return false;
90 
91  if(fabs(a->localPosition().x() - b->localPosition().x()) < 1e-5 &&
92  fabs(a->localPosition().y() - b->localPosition().y()) < 1e-5)
93  return true;
94  else
95  return false;
96 }
T y() const
Definition: PV3DBase.h:63
virtual LocalPoint localPosition() const =0
DetId geographicalId() const
T x() const
Definition: PV3DBase.h:62
bool TrackCleaner::canBeMerged ( const std::vector< const TrackingRecHit * > &  recHitsA,
const std::vector< const TrackingRecHit * > &  recHitsB 
) const
private

Definition at line 143 of file TrackCleaner.cc.

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

Referenced by cleanTracks(), and isCompatible().

145 {
146  bool ok = true;
147 
148  for(vector<const TrackingRecHit *>::const_iterator
149  recHitA = recHitsA.begin(); recHitA!= recHitsA.end(); recHitA++)
150  for(vector<const TrackingRecHit *>::const_iterator
151  recHitB = recHitsB.begin(); recHitB!= recHitsB.end(); recHitB++)
152  if(!areSame(*recHitA,*recHitB))
153  if(!isCompatible((*recHitA)->geographicalId(),
154  (*recHitB)->geographicalId()))
155  ok = false;
156 
157  return ok;
158 }
bool isCompatible(const DetId &i1, const DetId &i2) const
Definition: TrackCleaner.cc:99
bool areSame(const TrackingRecHit *a, const TrackingRecHit *b) const
Definition: TrackCleaner.cc:85
TracksWithRecHits TrackCleaner::cleanTracks ( const TracksWithRecHits tracksWithRecHits) const
overridevirtual

Reimplemented from PixelTrackCleaner.

Definition at line 162 of file TrackCleaner.cc.

References areSame(), canBeMerged(), plotBeamSpotDB::first, HitInfo::getInfo(), mps_fire::i, keep, LogTrace, min(), convertSQLiteXML::ok, rpcPointValidation_cfi::recHit, edm::second(), jetUpdater_cfi::sort, l1t::tracks, tracks_, and tTopo_.

Referenced by canBeMerged().

163 {
164  // Local copy
166 
167  typedef map<const TrackingRecHit*,vector<unsigned int>,HitComparator>
168  RecHitMap;
169 
170  vector<bool> keep(tracks.size(),true);
171 
172  int changes;
173 
174  LogTrace("MinBiasTracking")
175  << " [TrackCleaner] initial tracks : " << tracks.size();
176 
177  for(unsigned int i = 0; i < tracks.size(); i++)
178  LogTrace("TrackCleaner")
179  << " Track #" << i << " : " << HitInfo::getInfo(tracks[i].second, tTopo_);
180 
181  do
182  {
183  changes = 0;
184 
185  RecHitMap recHitMap;
186 
187 /*
188  LogTrace("MinBiasTracking")
189  << " [TrackCleaner] fill rechit map";
190 */
191 
192  // Fill the rechit map
193  for(unsigned int i = 0; i < tracks.size(); i++)
194  if(keep[i])
195  {
196  for(vector<const TrackingRecHit *>::const_iterator
197  recHit = tracks[i].second.begin();
198  recHit!= tracks[i].second.end(); recHit++)
199  recHitMap[*recHit].push_back(i);
200  }
201 
202  // Look at each track
203  typedef map<unsigned int,int,less<unsigned int> > TrackMap;
204 
205  for(unsigned int i = 0; i < tracks.size(); i++)
206  {
207  // Skip if 'i' already removed
208  if(!keep[i]) continue;
209 
210 /*
211 
212  bool addedNewHit = false;
213  do
214  {
215 */
216  TrackMap trackMap;
217 
218  // Go trough all rechits of this track
219  for(vector<const TrackingRecHit *>::const_iterator
220  recHit = tracks[i].second.begin();
221  recHit!= tracks[i].second.end(); recHit++)
222  {
223  // Get tracks sharing this rechit
224  vector<unsigned int> sharing = recHitMap[*recHit];
225 
226  for(vector<unsigned int>::iterator j = sharing.begin();
227  j!= sharing.end(); j++)
228  if(i < *j)
229  trackMap[*j]++;
230  }
231 
232  // Check for tracks with shared rechits
233  for(TrackMap::iterator sharing = trackMap.begin();
234  sharing!= trackMap.end(); sharing++)
235  {
236  unsigned int j = (*sharing).first;
237  if(!keep[i] || !keep[j]) continue;
238 
239  if(tracks[i].second.size() >=3)
240  { // triplet tracks
241  if((*sharing).second > min(int(tracks[i].second.size()),
242  int(tracks[j].second.size()))/2)
243  { // more than min(hits1,hits2)/2 rechits are shared
244  if(canBeMerged(tracks[i].second,tracks[j].second))
245  { // no common layer
246  // merge tracks, add separate hits of the second to the first one
247  for(vector<const TrackingRecHit *>::const_iterator
248  recHit = tracks[j].second.begin();
249  recHit!= tracks[j].second.end(); recHit++)
250  {
251  bool ok = true;
252  for(vector<const TrackingRecHit *>::const_iterator
253  recHitA = tracks[i].second.begin();
254  recHitA!= tracks[i].second.end(); recHitA++)
255  if(areSame(*recHit,*recHitA)) ok = false;
256 
257  if(ok)
258  {
259  tracks[i].second.push_back(*recHit);
260  recHitMap[*recHit].push_back(i);
261 
262  sort(tracks[i].second.begin(),
263  tracks[i].second.end(),
265 
266  //addedNewHit = true;
267  }
268  }
269 
270  LogTrace("TrackCleaner")
271  << " Merge #" << i << " #" << j
272  << ", first now has " << tracks[i].second.size();
273 
274  // Remove second track
275  keep[j] = false;
276 
277  changes++;
278  }
279  else
280  { // there is a common layer, keep smaller impact
281  if(fabs(tracks[i].first->d0())
282  < fabs(tracks[j].first->d0()))
283  keep[j] = false;
284  else
285  keep[i] = false;
286 
287  LogTrace("TrackCleaner")
288  << " Clash #" << i << " #" << j
289  << " keep lower d0 " << tracks[i].first->d0()
290  << " " << tracks[j].first->d0()
291  << ", keep #" << (keep[i] ? i : ( keep[j] ? j : 9999 ) );
292 
293  changes++;
294  }
295  }
296  else
297  { // note more than 50%, but at least two are shared
298  if((*sharing).second > 1)
299  {
300  if(tracks[i].second.size() != tracks[j].second.size())
301  { // keep longer
302  if(tracks[i].second.size() > tracks[j].second.size())
303  keep[j] = false; else keep[i] = false;
304  changes++;
305 
306  LogTrace("TrackCleaner")
307  << " Sharing " << (*sharing).second << " remove by size";
308  }
309  else
310  { // keep smaller impact
311  if(fabs(tracks[i].first->d0())
312  < fabs(tracks[j].first->d0()))
313  keep[j] = false; else keep[i] = false;
314  changes++;
315 
316  LogTrace("TrackCleaner")
317  << " Sharing " << (*sharing).second << " remove by d0";
318  }
319  }
320  }
321  }
322  else
323  { // pair tracks
324  if((*sharing).second > 0)
325  {
326  // Remove second track
327  keep[j] = false;
328 
329  changes++;
330  }
331  }
332  }
333 /*
334  }
335  while(addedNewHit);
336 */
337  }
338  }
339  while(changes > 0);
340 
341  // Final copy
342  TracksWithRecHits cleaned;
343 
344  for(unsigned int i = 0; i < tracks.size(); i++)
345  if(keep[i])
346  cleaned.push_back(tracks[i]);
347  else delete tracks_[i].first;
348 
349  LogTrace("MinBiasTracking")
350  << " [TrackCleaner] cleaned tracks : " << cleaned.size();
351 
352  for(unsigned int i = 0; i < cleaned.size(); i++)
353  LogTrace("TrackCleaner")
354  << " Track #" << i << " : " << HitInfo::getInfo(cleaned[i].second,tTopo_);
355 
356  return cleaned;
357 }
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:34
const std::vector< reco::CandidatePtr > & tracks_
std::vector< TrackWithRecHits > TracksWithRecHits
bool areSame(const TrackingRecHit *a, const TrackingRecHit *b) const
Definition: TrackCleaner.cc:85
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:23
bool TrackCleaner::isCompatible ( const DetId i1,
const DetId i2 
) const
private

Definition at line 99 of file TrackCleaner.cc.

References funct::abs(), canBeMerged(), constexpr, runTauDisplay::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().

101 {
102  // different subdet
103  if(i1.subdetId() != i2.subdetId()) return true;
104 
106  { // barrel
107 
108  if(tTopo_->pxbLayer(i1) != tTopo_->pxbLayer(i2)) return true;
109 
110  int dphi = abs(int(tTopo_->pxbLadder(i1) - tTopo_->pxbLadder(i2)));
111  //FIXME: non-phase-0 wrap-around is wrong (sh/be 12, 28, 44, 64 in phase-1)
112  // the harm is somewhat minimal with some excess of duplicates.
113  constexpr int max[4] = {20, 32, 44, 64};
114  auto aLayer = tTopo_->pxbLayer(i1)-1;
115  assert(aLayer < 4);
116  if(dphi > max[aLayer] / 2) dphi = max[aLayer] - dphi;
117 
118  int dz = abs(int(tTopo_->pxbModule(i1) - tTopo_->pxbModule(i2)));
119 
120  if(dphi == 1 && dz <= 1) return true;
121  }
122  else
123  { // endcap
124 
125  if(tTopo_->pxfSide(i1) != tTopo_->pxfSide(i2) ||
126  tTopo_->pxfDisk(i1) != tTopo_->pxfDisk(i2)) return true;
127 
128  int dphi = abs(int(tTopo_->pxfBlade(i1) - tTopo_->pxfBlade(i2)));
129  constexpr int max = 24; //FIXME: non-phase-0 wrap-around is wrong
130  if(dphi > max / 2) dphi = max - dphi;
131 
132  int dr = abs(int( ((tTopo_->pxfModule(i1)-1) * 2 + (tTopo_->pxfPanel(i1)-1)) -
133  ((tTopo_->pxfModule(i2)-1) * 2 + (tTopo_->pxfPanel(i2)-1)) ));
134 
135  if(dphi <= 1 && dr <= 1 && !(dphi == 0 && dr == 0)) return true;
136  }
137 
138  return false;
139 }
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:41
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:34
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 34 of file TrackCleaner.h.

Referenced by cleanTracks(), and isCompatible().