CMS 3D CMS Logo

TrackCleaner Class Reference

#include <RecoPixelVertexing/PixelLowPtUtilities/interface/TrackCleaner.h>

Inheritance diagram for TrackCleaner:

PixelTrackCleaner

List of all members.

Public Member Functions

virtual TracksWithRecHits cleanTracks (const TracksWithRecHits &tracksWithRecHits)
 TrackCleaner (const edm::ParameterSet &ps)
virtual ~TrackCleaner ()

Private Member Functions

int getLayer (const DetId &id)
bool hasCommonDetUnit (std::vector< const TrackingRecHit * > recHitsA, std::vector< const TrackingRecHit * > recHitsB, std::vector< DetId > detIds)
bool hasCommonLayer (std::vector< const TrackingRecHit * > recHitsA, std::vector< const TrackingRecHit * > recHitsB, std::vector< int > detLayers)


Detailed Description

Definition at line 14 of file TrackCleaner.h.


Constructor & Destructor Documentation

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

Definition at line 37 of file TrackCleaner.cc.

00038 {
00039 }

TrackCleaner::~TrackCleaner (  )  [virtual]

Definition at line 42 of file TrackCleaner.cc.

00043 {
00044 }


Member Function Documentation

TracksWithRecHits TrackCleaner::cleanTracks ( const TracksWithRecHits tracksWithRecHits  )  [virtual]

Definition at line 105 of file TrackCleaner.cc.

References find(), first, HitInfo::getInfo(), getLayer(), hasCommonLayer(), i, j, keep, LogTrace, min, edm::second(), and tracks.

00106 {
00107   LogTrace("MinBiasTracking")
00108     << " [TrackCleaner]";
00109 
00110   // Local copy
00111   TracksWithRecHits tracks = tracks_;
00112 
00113   typedef map<const TrackingRecHit*,vector<unsigned int>,HitComparator>
00114     RecHitMap;
00115 
00116   vector<bool> keep(tracks.size(),true);
00117 
00118   int changes;
00119 
00120   LogTrace("MinBiasTracking")
00121     << " [TrackCleaner ] initial tracks : " << tracks.size();
00122 
00123   for(unsigned int i = 0; i < tracks.size(); i++)
00124   LogTrace("MinBiasTracking")
00125     << "   Track #" << i << " : " << HitInfo::getInfo(tracks[i].second);
00126 
00127   do
00128   {
00129   changes = 0;
00130 
00131   RecHitMap recHitMap;
00132 
00133   // Fill the rechit map
00134   for(unsigned int i = 0; i < tracks.size(); i++)
00135   if(keep[i])
00136   {
00137     for(vector<const TrackingRecHit *>::const_iterator
00138         recHit = tracks[i].second.begin();
00139         recHit!= tracks[i].second.end(); recHit++)
00140       recHitMap[*recHit].push_back(i);
00141   }
00142 
00143   // Look at each track
00144   typedef map<unsigned int,int,less<unsigned int> > TrackMap; 
00145 
00146   for(unsigned int i = 0; i < tracks.size(); i++)
00147   {
00148     // Skip if 'i' already removed
00149     if(!keep[i]) continue;
00150 
00151     TrackMap trackMap;
00152     vector<DetId> detIds;
00153     vector<int> detLayers;
00154 
00155     // Go trough all rechits of this track
00156     for(vector<const TrackingRecHit *>::const_iterator
00157         recHit = tracks[i].second.begin();
00158         recHit!= tracks[i].second.end(); recHit++)
00159     {
00160       // Get tracks sharing this rechit
00161       vector<unsigned int> sharing = recHitMap[*recHit];
00162 
00163       for(vector<unsigned int>::iterator j = sharing.begin();
00164                                          j!= sharing.end(); j++)
00165         if(i < *j) trackMap[*j]++;
00166 
00167       // Fill detLayers vector
00168       detIds.push_back((*recHit)->geographicalId());
00169       detLayers.push_back(getLayer((*recHit)->geographicalId()));
00170     }
00171 
00172     // Check for tracks with shared rechits
00173     for(TrackMap::iterator sharing = trackMap.begin();
00174                            sharing!= trackMap.end(); sharing++)
00175     {
00176       unsigned int j = (*sharing).first;
00177       if(!keep[i] || !keep[j]) continue;
00178 
00179       if(tracks[i].second.size() >=3) 
00180       { // triplet tracks
00181         if((*sharing).second > min(tracks[i].second.size(),
00182                                    tracks[j].second.size())/2)
00183         { // more than min(hits1,hits2)/2 rechits are shared
00184 
00185           if(!hasCommonLayer(tracks[i].second,tracks[j].second,detLayers))
00186           { 
00187             // merge tracks, add separate hits of the second to the first one
00188             for(vector<const TrackingRecHit *>::const_iterator
00189                 recHit = tracks[j].second.begin();
00190                 recHit!= tracks[j].second.end(); recHit++)
00191               if(find(tracks[i].second.begin(),
00192                       tracks[i].second.end(),*recHit) == tracks[i].second.end())
00193                 tracks[i].second.push_back(*recHit);
00194 
00195             LogTrace("MinBiasTracking") << " merge " << i << " " << j;
00196   
00197             // Remove second track
00198             keep[j] = false;
00199   
00200            changes++;
00201           }
00202           else
00203           { // remove track with higher impact / chi2
00204             if(tracks[i].first->chi2() < tracks[j].first->chi2())
00205               keep[j] = false;
00206             else
00207               keep[i] = false;
00208 
00209             LogTrace("MinBiasTracking") << " merge + keep lower chi2 " << i << " " << j;
00210   
00211             changes++;
00212           }
00213         }
00214         else
00215         {
00216           if((*sharing).second > 1)
00217           {
00218             if(tracks[i].second.size() != tracks[j].second.size())
00219             {
00220               if(tracks[i].second.size() > tracks[j].second.size()) 
00221                 keep[j] = false; else keep[i] = false; 
00222               changes++;
00223             LogTrace("MinBiasTracking") << " sharing " << (*sharing).second << " remove by size";
00224             }
00225             else
00226             { 
00227               if(tracks[i].first->chi2() < tracks[j].first->chi2())
00228                 keep[j] = false; else keep[i] = false; 
00229               changes++;
00230             LogTrace("MinBiasTracking") << " sharing " << (*sharing).second << " remove by chi2";
00231             } 
00232           }
00233         }
00234       }
00235       else
00236       { // pair tracks
00237         if((*sharing).second > 0)
00238         {
00239           // Remove second track
00240           keep[j] = false;
00241   
00242           changes++;
00243         }
00244       }
00245     }
00246   }
00247   }
00248   while(changes > 0);
00249 
00250   // Final copy
00251   TracksWithRecHits cleaned;
00252   
00253   for(unsigned int i = 0; i < tracks.size(); i++)
00254     if(keep[i]) 
00255       cleaned.push_back(tracks[i]);
00256     else delete tracks_[i].first;
00257 
00258   LogTrace("MinBiasTracking")
00259     << " [TrackCleaner ] cleaned tracks : " << cleaned.size();
00260 
00261   for(unsigned int i = 0; i < cleaned.size(); i++)
00262   LogTrace("MinBiasTracking")
00263     << "   Track #" << i << " : " << HitInfo::getInfo(cleaned[i].second);
00264 
00265   return cleaned;
00266 }

int TrackCleaner::getLayer ( const DetId id  )  [private]

Definition at line 47 of file TrackCleaner.cc.

References PXFDetId::disk(), PXBDetId::ladder(), PXBDetId::layer(), PXFDetId::panel(), and PixelSubdetector::PixelBarrel.

Referenced by cleanTracks().

00048 {
00049   if(id.subdetId() == int(PixelSubdetector::PixelBarrel))
00050   {
00051     PXBDetId pid(id);
00052     return 0 + ((pid.layer() - 1)*2) + ((pid.ladder() - 1)%2);
00053   } 
00054   else
00055   {
00056     PXFDetId pid(id);
00057     return 6 + ((pid.disk()  - 1)*2) + ((pid.panel()  - 1)%2);
00058   } 
00059 }

bool TrackCleaner::hasCommonDetUnit ( std::vector< const TrackingRecHit * >  recHitsA,
std::vector< const TrackingRecHit * >  recHitsB,
std::vector< DetId detIds 
) [private]

bool TrackCleaner::hasCommonLayer ( std::vector< const TrackingRecHit * >  recHitsA,
std::vector< const TrackingRecHit * >  recHitsB,
std::vector< int detLayers 
) [private]

Referenced by cleanTracks().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:34:00 2009 for CMSSW by  doxygen 1.5.4