CMS 3D CMS Logo

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