CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTracker/CkfPattern/src/CachingSeedCleanerBySharedInput.cc

Go to the documentation of this file.
00001 #include "RecoTracker/CkfPattern/interface/CachingSeedCleanerBySharedInput.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00006 
00007 #include<boost/bind.hpp>
00008 #include<algorithm>
00009 
00010 void CachingSeedCleanerBySharedInput::init(const std::vector<Trajectory> *vect) { 
00011     theVault.clear(); theCache.clear();
00012 }
00013 
00014 void CachingSeedCleanerBySharedInput::done() { 
00015     //edm::LogInfo("CachingSeedCleanerBySharedInput") << " Calls: " << calls_ << ", Tracks: " << tracks_ <<", Comps: " << comps_ << " Vault: " << theVault.size() << ".";
00016     //calls_ = comps_ = tracks_ = 0;
00017     theVault.clear(); theCache.clear();
00018 
00019     //don't, at least we'll not copy vector by value!
00020 
00021     //    std::vector<Trajectory::RecHitContainer> swapper;
00022     //swapper.swap(theVault); // this should clean the vault even more
00023 }
00024 
00025 
00026 
00027 void CachingSeedCleanerBySharedInput::add(const Trajectory *trj) {
00028     typedef Trajectory::RecHitContainer::const_iterator TI;
00029     unsigned short idx = theVault.size();
00030     theVault.resize(idx+1);
00031     // a vector of shared pointers....
00032     Trajectory::ConstRecHitContainer & hits = theVault.back();
00033     (*trj).validRecHits(hits);
00034     //    std::sort(hits.begin(),hits.end(),
00035     //        boost::bind(&TrackingRecHit::geographicalId(),_1));
00036     
00037     uint32_t detid;
00038     for (TI t = hits.begin(), te = hits.end(); t != te; ++t) {
00039       //    if ((*t)->isValid()) {   // they are valid!
00040       detid = (*t)->geographicalId().rawId();
00041       if (detid) theCache.insert(std::pair<uint32_t, unsigned short>(detid, idx));
00042     }
00043 }
00044 
00045 bool CachingSeedCleanerBySharedInput::good(const TrajectorySeed *seed) {
00046   if (seed->nHits()==0){    return true; }
00047 
00048     typedef TrajectorySeed::const_iterator SI;
00049     typedef Trajectory::RecHitContainer::const_iterator TI;
00050     TrajectorySeed::range range = seed->recHits();
00051 
00052     SI first = range.first, last = range.second, curr;
00053     uint32_t detid = first->geographicalId().rawId();
00054     
00055     //std::multimap<uint32_t, unsigned short>::const_iterator it, end = theCache.end();
00056     typedef boost::unordered_multimap<uint32_t, unsigned short>::const_iterator IT;
00057     IT it; std::pair<IT,IT> itrange;
00058     
00059 
00060     //calls_++;
00061     //for (it = theCache.find(detid); (it != end) && (it->first == detid); ++it) {
00062     for (itrange = theCache.equal_range(detid), it = itrange.first; it != itrange.second; ++it) {
00063       assert(it->first == detid);
00064       //tracks_++;
00065       
00066       // seeds are limited to the first 4 hits in trajectory...
00067       int ext = std::min(4,int(theVault[it->second].size()));
00068       TI te =  theVault[it->second].begin()+ext;
00069       //    TI  te = theVault[it->second].end();
00070       
00071       TI ts = theVault[it->second].begin();
00072       TI t = ts;
00073       for (curr = first; curr != last; ++curr) {
00074         bool found = false;
00075         // for (TI t = ts; t != te; ++t) {
00076         for (;t != te; ++t) {
00077           //comps_++;
00078           if ( curr->sharesInput((**t).hit(),TrackingRecHit::all) ) { found = true; ++t; break; }
00079         }
00080         if (!found) break;
00081       }
00082       if (curr == last) return false;
00083     }
00084     return true;
00085 }