CMS 3D CMS Logo

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
 
using TempTrajectoryContainer = std::vector< TempTrajectory >
 
typedef std::vector< TrajectoryTrajectoryContainer
 
typedef TrajectoryContainer::iterator TrajectoryIterator
 
typedef std::vector< Trajectory * > TrajectoryPointerContainer
 
typedef TrajectoryPointerContainer::iterator TrajectoryPointerIterator
 

Public Member Functions

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

Private Attributes

bool allowSharedFirstHit
 
float missingHitPenalty_
 
float theFraction
 
float 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
TrajectoryCleanerBySharedHits::~TrajectoryCleanerBySharedHits ( )
inlineoverride

Definition at line 33 of file TrajectoryCleanerBySharedHits.h.

References TrajectoryCleaner::clean(), and clean().

33 {};

Member Function Documentation

void TrajectoryCleanerBySharedHits::clean ( TrajectoryPointerContainer tc) const
overridevirtual

Implements TrajectoryCleaner.

Definition at line 41 of file TrajectoryCleanerBySharedHits.cc.

References conversionTrackCandidates_cfi::allowSharedFirstHit, alongMomentum, gather_cfg::cout, DEBUG_PRINT, TrackingRecHit::geographicalId(), TrackingRecHit::hit(), Trajectory::invalidate(), min(), rpcPointValidation_cfi::recHit, offlineSlimmedPrimaryVertices_cfi::score, TrackingRecHit::sharesInput(), TrackingRecHit::some, and protons_cff::t.

Referenced by InOutConversionTrackFinder::tracks(), OutInConversionTrackFinder::tracks(), and ~TrajectoryCleanerBySharedHits().

42 {
43  if (tc.size() <= 1) return; // nothing to clean
44 
45  auto & theRecHitMap = theMaps.theRecHitMap;
46 
47  theRecHitMap.clear(10*tc.size()); // set 10*tc.size() active buckets
48  // numbers are not optimized
49 
50  DEBUG_PRINT(std::cout << "Filling RecHit map" << std::endl);
51  for (auto const & it : tc) {
52  DEBUG_PRINT(std::cout << " Processing trajectory " << it << " (" << it->foundHits() << " valid hits)" << std::endl);
53  auto const & pd = it->measurements();
54  for (auto const & im : pd) {
55  auto theRecHit = &(*im.recHit());
56  if (theRecHit->isValid()) {
57  DEBUG_PRINT(std::cout << " Added hit " << theRecHit << " for trajectory " << it << std::endl);
58  theRecHitMap.insert(theRecHit, it);
59  }
60  }
61  }
62  DEBUG_PRINT(theRecHitMap.dump());
63 
64  DEBUG_PRINT(std::cout << "Using RecHit map" << std::endl);
65  // for each trajectory fill theTrajMap
66  auto & theTrajMap = theMaps.theTrajMap;
67  for (auto const & itt : tc) {
68  if(itt->isValid()){
69  DEBUG_PRINT(std::cout << " Processing trajectory " << itt << " (" << itt->foundHits() << " valid hits)" << std::endl);
70  theTrajMap.clear();
71  const Trajectory::DataContainer & pd = itt->measurements();
72  for (auto const & im : pd) {
73  auto theRecHit = &(*im.recHit());
74  if (theRecHit->isValid()) {
75  DEBUG_PRINT(std::cout << " Searching for overlaps on hit " << theRecHit << " for trajectory " << itt << std::endl);
76  for (RecHitMap::value_iterator ivec = theRecHitMap.values(theRecHit);
77  ivec.good(); ++ivec) {
78  if (*ivec != itt){
79  if ((*ivec)->isValid()){
80  theTrajMap[*ivec]++;
81  }
82  }
83  }
84  }
85  }
86  //end filling theTrajMap
87 
88  auto score = [&](Trajectory const&t)->float {
89  // possible variant under study
90  // auto ns = t.foundHits()-t.trailingFoundHits();
91  //auto penalty = 0.8f*missingHitPenalty_;
92  // return validHitBonus_*(t.foundHits()-0.2f*t.cccBadHits()) - penalty*t.lostHits() - t.chiSquared();
93  // classical score
94  return validHitBonus_*t.foundHits() - missingHitPenalty_*t.lostHits() - t.chiSquared();
95  };
96 
97  // check for duplicated tracks
98  if(!theTrajMap.empty() > 0){
99  for(auto const & imapp : theTrajMap) {
100  if(imapp.second > 0 ){ // at least 1 hits in common!!!
101  int innerHit = 0;
102  if ( allowSharedFirstHit ) {
103  const TrajectoryMeasurement & innerMeasure1 = ( itt->direction() == alongMomentum ) ?
104  itt->firstMeasurement() : itt->lastMeasurement();
105  const TransientTrackingRecHit* h1 = &(*(innerMeasure1).recHit());
106  const TrajectoryMeasurement & innerMeasure2 = ( imapp.first->direction() == alongMomentum ) ?
107  imapp.first->firstMeasurement() : imapp.first->lastMeasurement();
108  const TransientTrackingRecHit* h2 = &(*(innerMeasure2).recHit());
109  if ( (h1 == h2) || ((h1->geographicalId() == h2->geographicalId()) &&
110  (h1->hit()->sharesInput(h2->hit(), TrackingRecHit::some))) ) {
111  innerHit = 1;
112  }
113  }
114  int nhit1 = itt->foundHits();
115  int nhit2 = imapp.first->foundHits();
116  if( (imapp.second - innerHit) >= ( (min(nhit1, nhit2)-innerHit) * theFraction) ){
117  Trajectory* badtraj;
118  auto score1 = score(*itt);
119  auto score2 = score(*imapp.first);
120  badtraj = (score1 > score2) ? imapp.first : itt;
121  badtraj->invalidate(); // invalidate this trajectory
122  }
123  }
124  }
125  }
126  }
127  }
128 }
void invalidate()
Method to invalidate a trajectory. Useful during ambiguity resolution.
Definition: Trajectory.h:282
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
#define DEBUG_PRINT(X)
T min(T a, T b)
Definition: MathUtil.h:58
virtual TrackingRecHit const * hit() const
DetId geographicalId() const

Member Data Documentation

bool TrajectoryCleanerBySharedHits::allowSharedFirstHit
private

Definition at line 42 of file TrajectoryCleanerBySharedHits.h.

float TrajectoryCleanerBySharedHits::missingHitPenalty_
private

Definition at line 41 of file TrajectoryCleanerBySharedHits.h.

float TrajectoryCleanerBySharedHits::theFraction
private

Definition at line 39 of file TrajectoryCleanerBySharedHits.h.

float TrajectoryCleanerBySharedHits::validHitBonus_
private

Definition at line 40 of file TrajectoryCleanerBySharedHits.h.