CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

TrajectoryCleanerBySharedHits Class Reference

#include <TrajectoryCleanerBySharedHits.h>

Inheritance diagram for TrajectoryCleanerBySharedHits:
TrajectoryCleaner

List of all members.

Public Types

typedef std::vector< Trajectory * > TrajectoryPointerContainer

Public Member Functions

virtual void clean (TrajectoryPointerContainer &) const
 TrajectoryCleanerBySharedHits (const edm::ParameterSet &iConfig)
 TrajectoryCleanerBySharedHits ()
virtual ~TrajectoryCleanerBySharedHits ()

Private Attributes

bool allowSharedFirstHit
double missingHitPenalty_
double theFraction
double validHitBonus_

Detailed Description

A concrete TrajectoryCleaner that considers two trajectories to be mutually exclusive if they share more than some fraction of their hits. The "best" trajectory of each set of mutually exclusive ones is kept, the others are eliminated. The goodness of a track is defined in terms of Chi^2, number of reconstructed hits, and number of lost hits.

Definition at line 16 of file TrajectoryCleanerBySharedHits.h.


Member Typedef Documentation

Reimplemented from TrajectoryCleaner.

Definition at line 20 of file TrajectoryCleanerBySharedHits.h.


Constructor & Destructor Documentation

TrajectoryCleanerBySharedHits::TrajectoryCleanerBySharedHits ( ) [inline]

Definition at line 22 of file TrajectoryCleanerBySharedHits.h.

TrajectoryCleanerBySharedHits::TrajectoryCleanerBySharedHits ( const edm::ParameterSet iConfig) [inline]

Definition at line 27 of file TrajectoryCleanerBySharedHits.h.

                                                                 :
    theFraction(iConfig.getParameter<double>("fractionShared")),
    validHitBonus_(iConfig.getParameter<double>("ValidHitBonus")),
    missingHitPenalty_(iConfig.getParameter<double>("MissingHitPenalty")),
    allowSharedFirstHit(iConfig.getParameter<bool>("allowSharedFirstHit")){}
virtual TrajectoryCleanerBySharedHits::~TrajectoryCleanerBySharedHits ( ) [inline, virtual]

Definition at line 33 of file TrajectoryCleanerBySharedHits.h.

{};

Member Function Documentation

void TrajectoryCleanerBySharedHits::clean ( TrajectoryPointerContainer tc) const [virtual]

Implements TrajectoryCleaner.

Definition at line 30 of file TrajectoryCleanerBySharedHits.cc.

References alongMomentum, gather_cfg::cout, DEBUG_PRINT, TrackingRecHit::geographicalId(), TransientTrackingRecHit::hit(), Trajectory::invalidate(), TrackingRecHit::isValid(), Trajectory::lostHits(), min, TrackingRecHit::sharesInput(), and TrackingRecHit::some.

Referenced by RoadSearchTrackCandidateMakerAlgorithm::PrepareTrackCandidates(), RoadSearchTrackCandidateMakerAlgorithm::run(), InOutConversionTrackFinder::tracks(), and OutInConversionTrackFinder::tracks().

{
  if (tc.size() <= 1) return; // nothing to clean

  //typedef boost::unordered_map<const TransientTrackingRecHit*, TIs, HashByDetId, EqualsBySharesInput> RecHitMap;
  typedef cmsutil::SimpleAllocHashMultiMap<const TransientTrackingRecHit*, Trajectory *, HashByDetId, EqualsBySharesInput> RecHitMap;

  //typedef boost::unordered_map<Trajectory*, int> TrajMap;  // for each Trajectory it stores the number of shared hits
  typedef cmsutil::UnsortedDumbVectorMap<Trajectory*, int> TrajMap;

  static RecHitMap theRecHitMap(128,256,1024);// allocate 128 buckets, one row for 256 keys and one row for 512 values
  theRecHitMap.clear(10*tc.size());           // set 10*tc.size() active buckets
                                              // numbers are not optimized

  DEBUG_PRINT(std::cout << "Filling RecHit map" << std::endl);
  for (TrajectoryPointerContainer::iterator
         it = tc.begin(); it != tc.end(); ++it) {
    DEBUG_PRINT(std::cout << "  Processing trajectory " << *it << " (" << (*it)->foundHits() << " valid hits)" << std::endl);
    const Trajectory::DataContainer & pd = (*it)->measurements();
    for (Trajectory::DataContainer::const_iterator im = pd.begin();
         im != pd.end(); im++) {
      const TransientTrackingRecHit* theRecHit = &(*(*im).recHit());
      if (theRecHit->isValid()) {
        DEBUG_PRINT(std::cout << "    Added hit " << theRecHit << " for trajectory " << *it << std::endl);
        theRecHitMap.insert(theRecHit, *it);
      }
    }
  }
  DEBUG_PRINT(theRecHitMap.dump());

  DEBUG_PRINT(std::cout << "Using RecHit map" << std::endl);
  // for each trajectory fill theTrajMap
  static TrajMap theTrajMap; 
  for (TrajectoryCleaner::TrajectoryPointerIterator
         itt = tc.begin(); itt != tc.end(); ++itt) {
    if((*itt)->isValid()){  
      DEBUG_PRINT(std::cout << "  Processing trajectory " << *itt << " (" << (*itt)->foundHits() << " valid hits)" << std::endl);
      theTrajMap.clear();
      const Trajectory::DataContainer & pd = (*itt)->measurements();
      for (Trajectory::DataContainer::const_iterator im = pd.begin();
           im != pd.end(); ++im) {
        //RC const TransientTrackingRecHit* theRecHit = ((*im).recHit());
        const TransientTrackingRecHit* theRecHit = &(*(*im).recHit());
        if (theRecHit->isValid()) {
          DEBUG_PRINT(std::cout << "    Searching for overlaps on hit " << theRecHit << " for trajectory " << *itt << std::endl);
          for (RecHitMap::value_iterator ivec = theRecHitMap.values(theRecHit);
                ivec.good(); ++ivec) {
              if (*ivec != *itt){
                if ((*ivec)->isValid()){
                    theTrajMap[*ivec]++;
                }
              }
          }
        }
      }
      //end filling theTrajMap

      // check for duplicated tracks
      if(!theTrajMap.empty() > 0){
        for(TrajMap::iterator imapp = theTrajMap.begin(); 
            imapp != theTrajMap.end(); ++imapp){
          if((*imapp).second > 0 ){
            int innerHit = 0;
            if ( allowSharedFirstHit ) {
              const TrajectoryMeasurement & innerMeasure1 = ( (*itt)->direction() == alongMomentum ) ? 
                (*itt)->firstMeasurement() : (*itt)->lastMeasurement();
              const TransientTrackingRecHit* h1 = &(*(innerMeasure1).recHit());
              const TrajectoryMeasurement & innerMeasure2 = ( (*imapp).first->direction() == alongMomentum ) ? 
                (*imapp).first->firstMeasurement() : (*imapp).first->lastMeasurement();
              const TransientTrackingRecHit* h2 = &(*(innerMeasure2).recHit());
              if ( (h1 == h2) || ((h1->geographicalId() == h2->geographicalId()) && 
                                  (h1->hit()->sharesInput(h2->hit(), TrackingRecHit::some))) ) {
                innerHit = 1;
              }
            }
            int nhit1 = (*itt)->foundHits();
            int nhit2 = (*imapp).first->foundHits();
            if( ((*imapp).second - innerHit) >= ( (min(nhit1, nhit2)-innerHit) * theFraction) ){
              Trajectory* badtraj;
              double score1 = validHitBonus_*nhit1 - missingHitPenalty_*(*itt)->lostHits() - (*itt)->chiSquared();
              double score2 = validHitBonus_*nhit2 - missingHitPenalty_*(*imapp).first->lostHits() - (*imapp).first->chiSquared();
              badtraj = (score1 > score2) ? (*imapp).first : *itt;
              badtraj->invalidate();  // invalidate this trajectory
            }
          }
        }
      } 
    }
  }
}

Member Data Documentation

Definition at line 42 of file TrajectoryCleanerBySharedHits.h.

Definition at line 41 of file TrajectoryCleanerBySharedHits.h.

Definition at line 39 of file TrajectoryCleanerBySharedHits.h.

Definition at line 40 of file TrajectoryCleanerBySharedHits.h.