Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:19

0001 #include "RecoTracker/CkfPattern/interface/CachingSeedCleanerBySharedInput.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0006 
0007 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0008 
0009 #include <algorithm>
0010 
0011 void CachingSeedCleanerBySharedInput::init(const std::vector<Trajectory> *vect) {
0012   theVault.clear();
0013   theCache.clear();
0014 }
0015 
0016 void CachingSeedCleanerBySharedInput::done() {
0017   //edm::LogInfo("CachingSeedCleanerBySharedInput") << " Calls: " << calls_ << ", Tracks: " << tracks_ <<", Comps: " << comps_ << " Vault: " << theVault.size() << ".";
0018   //calls_ = comps_ = tracks_ = 0;
0019   theVault.clear();
0020   theCache.clear();
0021 }
0022 
0023 void CachingSeedCleanerBySharedInput::add(const Trajectory *trj) {
0024   unsigned int idx = theVault.size();
0025   theVault.resize(idx + 1);
0026   // a vector of shared pointers....
0027   auto &hits = theVault.back();
0028   (*trj).validRecHits(hits);
0029 
0030   for (auto const &h : hits) {
0031     auto detid = h->geographicalId().rawId();
0032 
0033     //For seeds that are made only of pixel hits, it is pointless to store the
0034     //information about hits on other sub-detector of the trajectory.
0035     if (theOnlyPixelHits && h->geographicalId().subdetId() != PixelSubdetector::PixelBarrel &&
0036         h->geographicalId().subdetId() != PixelSubdetector::PixelEndcap)
0037       continue;
0038     if (detid)
0039       theCache.insert(std::pair<uint32_t, unsigned int>(detid, idx));
0040   }
0041 }
0042 
0043 bool CachingSeedCleanerBySharedInput::good(const TrajectorySeed *seed) {
0044   if (seed->nHits() == 0) {
0045     return true;
0046   }
0047 
0048   auto const &range = seed->recHits();
0049 
0050   auto first = range.begin();
0051   auto last = range.end();
0052   auto detid = first->geographicalId().rawId();
0053 
0054   //calls_++;
0055   auto itrange = theCache.equal_range(detid);
0056   for (auto it = itrange.first; it != itrange.second; ++it) {
0057     assert(it->first == detid);
0058     //tracks_++;
0059 
0060     // seeds are limited to the first "theNumHitsForSeedCleaner" hits in trajectory...
0061     int ext = std::min(theNumHitsForSeedCleaner, int(theVault[it->second].size()));
0062     auto ts = theVault[it->second].begin();
0063     auto te = ts + ext;
0064     auto t = ts;
0065     auto curr = first;
0066     for (; curr != last; ++curr) {
0067       bool found = false;
0068       for (; t != te; ++t) {
0069         //comps_++;
0070         if (curr->sharesInput((**t).hit(), TrackingRecHit::all)) {
0071           found = true;
0072           ++t;
0073           break;
0074         }
0075       }
0076       if (!found)
0077         break;
0078     }
0079     if (curr == last)
0080       return false;
0081   }
0082   return true;
0083 }