CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
TrajectoryCleanerBySharedHits Class Reference

#include <TrajectoryCleanerBySharedHits.h>

Inheritance diagram for TrajectoryCleanerBySharedHits:
TrajectoryCleaner

Public Types

typedef std::vector< Trajectory * > TrajectoryPointerContainer
 
- Public Types inherited from TrajectoryCleaner
typedef TrackingComponentsRecord Record
 
typedef std::vector< TrajectoryTrajectoryContainer
 
typedef
TrajectoryContainer::iterator 
TrajectoryIterator
 
typedef std::vector< Trajectory * > TrajectoryPointerContainer
 
typedef
TrajectoryPointerContainer::iterator 
TrajectoryPointerIterator
 

Public Member Functions

virtual void clean (TrajectoryPointerContainer &) const
 
 TrajectoryCleanerBySharedHits ()
 
 TrajectoryCleanerBySharedHits (const edm::ParameterSet &iConfig)
 
virtual ~TrajectoryCleanerBySharedHits ()
 
- Public Member Functions inherited from TrajectoryCleaner
virtual void clean (TrajectoryContainer &) const
 
 TrajectoryCleaner ()
 
 TrajectoryCleaner (edm::ParameterSet &iConfig)
 
virtual ~TrajectoryCleaner ()
 

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

Definition at line 20 of file TrajectoryCleanerBySharedHits.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file TrajectoryCleanerBySharedHits.h.

27  :
28  theFraction(iConfig.getParameter<double>("fractionShared")),
29  validHitBonus_(iConfig.getParameter<double>("ValidHitBonus")),
30  missingHitPenalty_(iConfig.getParameter<double>("MissingHitPenalty")),
31  allowSharedFirstHit(iConfig.getParameter<bool>("allowSharedFirstHit")){}
T getParameter(std::string const &) const
virtual TrajectoryCleanerBySharedHits::~TrajectoryCleanerBySharedHits ( )
inlinevirtual

Definition at line 33 of file TrajectoryCleanerBySharedHits.h.

33 {};

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().

31 {
32  if (tc.size() <= 1) return; // nothing to clean
33 
34  //typedef boost::unordered_map<const TransientTrackingRecHit*, TIs, HashByDetId, EqualsBySharesInput> RecHitMap;
36 
37  //typedef boost::unordered_map<Trajectory*, int> TrajMap; // for each Trajectory it stores the number of shared hits
39 
40  static RecHitMap theRecHitMap(128,256,1024);// allocate 128 buckets, one row for 256 keys and one row for 512 values
41  theRecHitMap.clear(10*tc.size()); // set 10*tc.size() active buckets
42  // numbers are not optimized
43 
44  DEBUG_PRINT(std::cout << "Filling RecHit map" << std::endl);
45  for (TrajectoryPointerContainer::iterator
46  it = tc.begin(); it != tc.end(); ++it) {
47  DEBUG_PRINT(std::cout << " Processing trajectory " << *it << " (" << (*it)->foundHits() << " valid hits)" << std::endl);
48  const Trajectory::DataContainer & pd = (*it)->measurements();
49  for (Trajectory::DataContainer::const_iterator im = pd.begin();
50  im != pd.end(); im++) {
51  const TransientTrackingRecHit* theRecHit = &(*(*im).recHit());
52  if (theRecHit->isValid()) {
53  DEBUG_PRINT(std::cout << " Added hit " << theRecHit << " for trajectory " << *it << std::endl);
54  theRecHitMap.insert(theRecHit, *it);
55  }
56  }
57  }
58  DEBUG_PRINT(theRecHitMap.dump());
59 
60  DEBUG_PRINT(std::cout << "Using RecHit map" << std::endl);
61  // for each trajectory fill theTrajMap
62  static TrajMap theTrajMap;
64  itt = tc.begin(); itt != tc.end(); ++itt) {
65  if((*itt)->isValid()){
66  DEBUG_PRINT(std::cout << " Processing trajectory " << *itt << " (" << (*itt)->foundHits() << " valid hits)" << std::endl);
67  theTrajMap.clear();
68  const Trajectory::DataContainer & pd = (*itt)->measurements();
69  for (Trajectory::DataContainer::const_iterator im = pd.begin();
70  im != pd.end(); ++im) {
71  //RC const TransientTrackingRecHit* theRecHit = ((*im).recHit());
72  const TransientTrackingRecHit* theRecHit = &(*(*im).recHit());
73  if (theRecHit->isValid()) {
74  DEBUG_PRINT(std::cout << " Searching for overlaps on hit " << theRecHit << " for trajectory " << *itt << std::endl);
75  for (RecHitMap::value_iterator ivec = theRecHitMap.values(theRecHit);
76  ivec.good(); ++ivec) {
77  if (*ivec != *itt){
78  if ((*ivec)->isValid()){
79  theTrajMap[*ivec]++;
80  }
81  }
82  }
83  }
84  }
85  //end filling theTrajMap
86 
87  // check for duplicated tracks
88  if(!theTrajMap.empty() > 0){
89  for(TrajMap::iterator imapp = theTrajMap.begin();
90  imapp != theTrajMap.end(); ++imapp){
91  if((*imapp).second > 0 ){
92  int innerHit = 0;
93  if ( allowSharedFirstHit ) {
94  const TrajectoryMeasurement & innerMeasure1 = ( (*itt)->direction() == alongMomentum ) ?
95  (*itt)->firstMeasurement() : (*itt)->lastMeasurement();
96  const TransientTrackingRecHit* h1 = &(*(innerMeasure1).recHit());
97  const TrajectoryMeasurement & innerMeasure2 = ( (*imapp).first->direction() == alongMomentum ) ?
98  (*imapp).first->firstMeasurement() : (*imapp).first->lastMeasurement();
99  const TransientTrackingRecHit* h2 = &(*(innerMeasure2).recHit());
100  if ( (h1 == h2) || ((h1->geographicalId() == h2->geographicalId()) &&
101  (h1->hit()->sharesInput(h2->hit(), TrackingRecHit::some))) ) {
102  innerHit = 1;
103  }
104  }
105  int nhit1 = (*itt)->foundHits();
106  int nhit2 = (*imapp).first->foundHits();
107  if( ((*imapp).second - innerHit) >= ( (min(nhit1, nhit2)-innerHit) * theFraction) ){
108  Trajectory* badtraj;
109  double score1 = validHitBonus_*nhit1 - missingHitPenalty_*(*itt)->lostHits() - (*itt)->chiSquared();
110  double score2 = validHitBonus_*nhit2 - missingHitPenalty_*(*imapp).first->lostHits() - (*imapp).first->chiSquared();
111  badtraj = (score1 > score2) ? (*imapp).first : *itt;
112  badtraj->invalidate(); // invalidate this trajectory
113  }
114  }
115  }
116  }
117  }
118  }
119 }
TrajectoryPointerContainer::iterator TrajectoryPointerIterator
void invalidate()
Method to invalidate a trajectory. Useful during ambiguity resolution.
Definition: Trajectory.h:262
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
virtual const TrackingRecHit * hit() const =0
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
#define DEBUG_PRINT(X)
bool isValid() const
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const

Member Data Documentation

bool TrajectoryCleanerBySharedHits::allowSharedFirstHit
private

Definition at line 42 of file TrajectoryCleanerBySharedHits.h.

double TrajectoryCleanerBySharedHits::missingHitPenalty_
private

Definition at line 41 of file TrajectoryCleanerBySharedHits.h.

double TrajectoryCleanerBySharedHits::theFraction
private

Definition at line 39 of file TrajectoryCleanerBySharedHits.h.

double TrajectoryCleanerBySharedHits::validHitBonus_
private

Definition at line 40 of file TrajectoryCleanerBySharedHits.h.