#include <TrackingTools/TrajectoryCleaning/interface/TrajectoryCleanerMerger.h>
Public Member Functions | |
void | clean (TrajectoryContainer &trajs) const |
virtual void | clean (TrajectoryPointerContainer &) const |
TrajectoryCleanerMerger () | |
virtual | ~TrajectoryCleanerMerger () |
Private Member Functions | |
int | getLayer (const DetId &id) const |
void | reOrderMeasurements (Trajectory &traj) const |
bool | sameSeed (const TrajectorySeed &s1, const TrajectorySeed &s2) const |
Definition at line 6 of file TrajectoryCleanerMerger.h.
TrajectoryCleanerMerger::TrajectoryCleanerMerger | ( | ) | [inline] |
virtual TrajectoryCleanerMerger::~TrajectoryCleanerMerger | ( | ) | [inline, virtual] |
void TrajectoryCleanerMerger::clean | ( | TrajectoryContainer & | trajs | ) | const |
Definition at line 227 of file TrajectoryCleanerMerger.cc.
References TestMuL1L2Filter_cff::cerr, lat::endl(), getLayer(), i, TrackingRecHit::isValid(), j, keep, edm::match(), min, reOrderMeasurements(), sameSeed(), and true.
00228 { 00229 if(trajs.size() == 0) return; 00230 00231 // Fill the rechit map 00232 typedef map<const TransientTrackingRecHit*, 00233 vector<unsigned int>, HitComparator> RecHitMap; 00234 RecHitMap recHitMap; 00235 00236 vector<bool> keep(trajs.size(),true); 00237 00238 for(unsigned int i = 0; i < trajs.size(); i++) 00239 { 00240 vector<TrajectoryMeasurement> meas = trajs[i].measurements(); 00241 00242 for(vector<TrajectoryMeasurement>::iterator im = meas.begin(); 00243 im!= meas.end(); im++) 00244 if(im->recHit()->isValid()) 00245 { 00246 const TransientTrackingRecHit* recHit = &(*(im->recHit())); 00247 if(recHit->isValid()) 00248 recHitMap[recHit].push_back(i); 00249 } 00250 } 00251 00252 // Look at each track 00253 typedef map<unsigned int,int,less<unsigned int> > TrajMap; 00254 00255 for(unsigned int i = 0; i < trajs.size(); i++) 00256 if(keep[i]) 00257 { 00258 TrajMap trajMap; 00259 vector<DetId> detIds; 00260 vector<int> detLayers; 00261 00262 // Go trough all rechits of this track 00263 vector<TrajectoryMeasurement> meas = trajs[i].measurements(); 00264 for(vector<TrajectoryMeasurement>::iterator im = meas.begin(); 00265 im!= meas.end(); im++) 00266 { 00267 if(im->recHit()->isValid()) 00268 { 00269 // Get trajs sharing this rechit 00270 const TransientTrackingRecHit* recHit = &(*(im->recHit())); 00271 const vector<unsigned int>& sharing(recHitMap[recHit]); 00272 00273 for(vector<unsigned int>::const_iterator j = sharing.begin(); 00274 j!= sharing.end(); j++) 00275 if(i < *j) trajMap[*j]++; 00276 00277 // Fill detLayers vector 00278 detIds.push_back(recHit->geographicalId()); 00279 detLayers.push_back(getLayer(recHit->geographicalId())); 00280 } 00281 } 00282 00283 // Check for trajs with shared rechits 00284 for(TrajMap::iterator sharing = trajMap.begin(); 00285 sharing!= trajMap.end(); sharing++) 00286 { 00287 unsigned int j = (*sharing).first; 00288 if(!keep[i] || !keep[j]) continue; 00289 00290 // More than 50% shared 00291 if((*sharing).second > min(trajs[i].foundHits(), 00292 trajs[j].foundHits())/2) 00293 { 00294 if( sameSeed(trajs[i].seed(), trajs[j].seed()) ) 00295 { 00296 bool hasCommonLayer = false; 00297 00298 /* 00299 vector<TrajectoryMeasurement> measi = trajs[i].measurements(); 00300 vector<TrajectoryMeasurement> measj = trajs[j].measurements(); 00301 for(vector<TrajectoryMeasurement>::iterator 00302 tmj = measj.begin(); tmj!= measj.end(); tmj++) 00303 if(find(measi.begin(), measi.end(), tmj) == measi.end()) 00304 if(find(detLayers.begin(),detLayers.end(), 00305 getLayer(tmj->recHit()->geographicalId())) 00306 != detLayers.end()) 00307 hasCommonLayer = true; 00308 */ 00309 00310 if(hasCommonLayer == false) 00311 { // merge tracks, add separate hits of the second to the first one 00312 vector<TrajectoryMeasurement> measj = trajs[j].measurements(); 00313 for(vector<TrajectoryMeasurement>::iterator 00314 tmj = measj.begin(); tmj!= measj.end(); tmj++) 00315 if(tmj->recHit()->isValid()) 00316 { 00317 bool match = false; 00318 00319 vector<TrajectoryMeasurement> measi = trajs[i].measurements(); 00320 for(vector<TrajectoryMeasurement>::iterator 00321 tmi = measi.begin(); tmi!= measi.end(); tmi++) 00322 if(tmi->recHit()->isValid()) 00323 if(!HitComparator()(&(*(tmi->recHit())), 00324 &(*(tmj->recHit()))) && 00325 !HitComparator()(&(*(tmj->recHit())), 00326 &(*(tmi->recHit())))) 00327 { match = true ; break; } 00328 00329 if(!match) 00330 trajs[i].push(*tmj); 00331 } 00332 00333 // Remove second track 00334 keep[j] = false; 00335 } 00336 else 00337 { 00338 // remove track with higher impact / chi2 00339 if(trajs[i].chiSquared() < trajs[j].chiSquared()) 00340 keep[j] = false; 00341 else 00342 keep[i] = false; 00343 } 00344 } 00345 } 00346 } 00347 } 00348 00349 // Final copy 00350 int ok = 0; 00351 for(unsigned int i = 0; i < trajs.size(); i++) 00352 if(keep[i]) 00353 { 00354 reOrderMeasurements(trajs[i]); 00355 ok++; 00356 } 00357 else 00358 trajs[i].invalidate(); 00359 00360 cerr << " [TrajecCleaner] cleaned trajs : " << ok << "/" << trajs.size() << 00361 " (with " << trajs[0].measurements().size() << "/" << recHitMap.size() << " hits)" << endl; 00362 }
void TrajectoryCleanerMerger::clean | ( | TrajectoryPointerContainer & | ) | const [virtual] |
Definition at line 196 of file TrajectoryCleanerMerger.cc.
References PXFDetId::disk(), PXBDetId::ladder(), TIBDetId::layer(), TOBDetId::layer(), PXBDetId::layer(), TOBDetId::module(), TIBDetId::module(), PXFDetId::panel(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, TIDDetId::ring(), TECDetId::ring(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, StripSubdetector::TOB, TIDDetId::wheel(), and TECDetId::wheel().
Referenced by clean().
00197 { 00198 // PXB layer, ladder -> (layer - 1)<<2 + (ladder-1)%2 00199 // PXF disk , panel 00200 // TIB layer, module 00201 // TOB layer, module 00202 // TID wheel, ring 00203 // TEC wheel, ring 00204 00205 if(id.subdetId() == PixelSubdetector::PixelBarrel) 00206 { PXBDetId pid(id); return (100 * id.subdetId()+ (pid.layer() - 1)<<1 + (pid.ladder() - 1)%2); } 00207 00208 if(id.subdetId() == PixelSubdetector::PixelEndcap) 00209 { PXFDetId pid(id); return (100 * id.subdetId()+ (pid.disk() - 1)<<1 + (pid.panel() - 1)%2); } 00210 00211 if(id.subdetId() == StripSubdetector::TIB) 00212 { TIBDetId pid(id); return (100 * id.subdetId()+ (pid.layer() - 1)<<1 + (pid.module() - 1)%2); } 00213 if(id.subdetId() == StripSubdetector::TOB) 00214 { TOBDetId pid(id); return (100 * id.subdetId()+ (pid.layer() - 1)<<1 + (pid.module() - 1)%2); } 00215 00216 if(id.subdetId() == StripSubdetector::TID) 00217 { TIDDetId pid(id); return (100 * id.subdetId()+ (pid.wheel() - 1)<<1 + (pid.ring() - 1)%2); } 00218 if(id.subdetId() == StripSubdetector::TEC) 00219 { TECDetId pid(id); return (100 * id.subdetId()+ (pid.wheel() - 1)<<1 + (pid.ring() - 1)%2); } 00220 00221 return 0; 00222 }
void TrajectoryCleanerMerger::reOrderMeasurements | ( | Trajectory & | traj | ) | const [private] |
Definition at line 136 of file TrajectoryCleanerMerger.cc.
References e, i, Trajectory::measurements(), Trajectory::pop(), Trajectory::push(), and swap().
Referenced by clean().
00137 { 00138 vector<TrajectoryMeasurement> meas_ = traj.measurements(); 00139 vector<TrajectoryMeasurement> meas; 00140 00141 for(vector<TrajectoryMeasurement>::iterator 00142 im = meas_.begin(); 00143 im!= meas_.end(); im++) 00144 if(im->recHit()->isValid()) 00145 meas.push_back(*im); 00146 00147 bool changed; 00148 00149 do 00150 { 00151 changed = false; 00152 00153 for(vector<TrajectoryMeasurement>::iterator im = meas.begin(); 00154 im!= meas.end()-1; im++) 00155 if( (*im).recHit()->globalPosition().mag2() > 00156 (*(im+1)).recHit()->globalPosition().mag2() + 1e-6) 00157 { 00158 swap(*im,*(im+1)); 00159 changed = true; 00160 } 00161 } 00162 while(changed); 00163 00164 for(unsigned int i = 0 ; i < meas.size(); i++) 00165 traj.pop(); 00166 00167 for(vector<TrajectoryMeasurement>::iterator im = meas.begin(); 00168 im!= meas.end(); im++) 00169 traj.push(*im); 00170 }
bool TrajectoryCleanerMerger::sameSeed | ( | const TrajectorySeed & | s1, | |
const TrajectorySeed & | s2 | |||
) | const [private] |
Definition at line 172 of file TrajectoryCleanerMerger.cc.
References TrackingRecHit::all, h1, h2, TrajectorySeed::nHits(), r1, r2, and TrajectorySeed::recHits().
Referenced by clean().
00173 { 00174 if(s1.nHits() != s2.nHits()) return false; 00175 00176 TrajectorySeed::range r1 = s1.recHits(); 00177 TrajectorySeed::range r2 = s2.recHits(); 00178 00179 TrajectorySeed::const_iterator h1 = r1.first; 00180 TrajectorySeed::const_iterator h2 = r2.first; 00181 00182 do 00183 { 00184 if(!(h1->sharesInput(&(*h2),TrackingRecHit::all))) 00185 return false; 00186 00187 h1++; h2++; 00188 } 00189 while(h1 != s1.recHits().second && 00190 h2 != s2.recHits().second); 00191 00192 return true; 00193 }