CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions
TrackCleaner Class Reference

#include <TrackCleaner.h>

Inheritance diagram for TrackCleaner:
PixelTrackCleaner

Public Member Functions

virtual TracksWithRecHits cleanTracks (const TracksWithRecHits &tracksWithRecHits, const TrackerTopology *tTopo)
 
 TrackCleaner (const edm::ParameterSet &ps)
 
virtual ~TrackCleaner ()
 
- Public Member Functions inherited from PixelTrackCleaner
virtual void cleanTracks (TracksWithTTRHs &tracksWithRecHits, const TrackerTopology *tTopo) const
 
virtual ~PixelTrackCleaner ()
 

Private Member Functions

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

Additional Inherited Members

- Public Types inherited from PixelTrackCleaner
typedef
pixeltrackfitting::TracksWithRecHits 
TracksWithRecHits
 
using TracksWithTTRHs = pixeltrackfitting::TracksWithTTRHs
 
- Public Attributes inherited from PixelTrackCleaner
bool fast =false
 

Detailed Description

Definition at line 15 of file TrackCleaner.h.

Constructor & Destructor Documentation

TrackCleaner::TrackCleaner ( const edm::ParameterSet ps)

Definition at line 76 of file TrackCleaner.cc.

77 {
78 }
TrackCleaner::~TrackCleaner ( )
virtual

Definition at line 81 of file TrackCleaner.cc.

82 {
83 }

Member Function Documentation

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

Definition at line 86 of file TrackCleaner.cc.

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

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

Definition at line 141 of file TrackCleaner.cc.

References convertSQLiteXML::ok.

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

Reimplemented from PixelTrackCleaner.

Definition at line 162 of file TrackCleaner.cc.

References plotBeamSpotDB::first, HitInfo::getInfo(), i, j, keep, LogTrace, min(), convertSQLiteXML::ok, edm::second(), testEve_cfg::tracks, and tracks_.

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,tTopo))
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(),
264  HitComparatorByRadius(tTopo));
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 }
int i
Definition: DBlmapReader.cc:9
const std::vector< reco::PFCandidatePtr > & tracks_
bool areSame(const TrackingRecHit *a, const TrackingRecHit *b)
Definition: TrackCleaner.cc:86
bool canBeMerged(const std::vector< const TrackingRecHit * > &recHitsA, const std::vector< const TrackingRecHit * > &recHitsB, const TrackerTopology *tTopo)
U second(std::pair< T, U > const &p)
const int keep
int j
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58
#define LogTrace(id)
tuple tracks
Definition: testEve_cfg.py:39
std::vector< TrackWithRecHits > TracksWithRecHits
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:23
bool TrackCleaner::isCompatible ( const DetId i1,
const DetId i2,
const TrackerTopology tTopo 
)
private

Definition at line 100 of file TrackCleaner.cc.

References funct::abs(), constexpr, bookConverter::max, PixelSubdetector::PixelBarrel, TrackerTopology::pxbLadder(), TrackerTopology::pxbLayer(), TrackerTopology::pxbModule(), TrackerTopology::pxfBlade(), TrackerTopology::pxfDisk(), TrackerTopology::pxfModule(), TrackerTopology::pxfPanel(), TrackerTopology::pxfSide(), and DetId::subdetId().

103 {
104  // different subdet
105  if(i1.subdetId() != i2.subdetId()) return true;
106 
107  if(i1.subdetId() == int(PixelSubdetector::PixelBarrel))
108  { // barrel
109 
110  if(tTopo->pxbLayer(i1) != tTopo->pxbLayer(i2)) return true;
111 
112  int dphi = abs(int(tTopo->pxbLadder(i1) - tTopo->pxbLadder(i2)));
113  constexpr int max[3] = {20, 32, 44};
114  if(dphi > max[tTopo->pxbLayer(i1)-1] / 2) dphi = max[tTopo->pxbLayer(i1)-1] - dphi;
115 
116  int dz = abs(int(tTopo->pxbModule(i1) - tTopo->pxbModule(i2)));
117 
118  if(dphi == 1 && dz <= 1) return true;
119  }
120  else
121  { // endcap
122 
123  if(tTopo->pxfSide(i1) != tTopo->pxfSide(i2) ||
124  tTopo->pxfDisk(i1) != tTopo->pxfDisk(i2)) return true;
125 
126  int dphi = abs(int(tTopo->pxfBlade(i1) - tTopo->pxfBlade(i2)));
127  constexpr int max = 24;
128  if(dphi > max / 2) dphi = max - dphi;
129 
130  int dr = abs(int( ((tTopo->pxfModule(i1)-1) * 2 + (tTopo->pxfPanel(i1)-1)) -
131  ((tTopo->pxfModule(i2)-1) * 2 + (tTopo->pxfPanel(i2)-1)) ));
132 
133  if(dphi <= 1 && dr <= 1 && !(dphi == 0 && dr == 0)) return true;
134  }
135 
136  return false;
137 }
unsigned int pxfDisk(const DetId &id) const
unsigned int pxbLadder(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
#define constexpr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
unsigned int pxfModule(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
unsigned int pxfSide(const DetId &id) const
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
std::vector<const TrackingRecHit*> TrackCleaner::ttrhs ( const SeedingHitSet h) const
private