CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTSegmentCleaner.cc
Go to the documentation of this file.
1 
7 /* This Class Header */
9 
10 /* Collaborating Class Header */
13 
14 /* C++ Headers */
15 using namespace std;
16 
17 /* ====================================================================== */
18 
19 /* Constructor */
21  nSharedHitsMax = pset.getParameter<int>("nSharedHitsMax");
22 
23  nUnSharedHitsMin = pset.getParameter<int>("nUnSharedHitsMin");
24 
25  segmCleanerMode = pset.getParameter<int>("segmCleanerMode");
26 
27  if((segmCleanerMode!=1)&&(segmCleanerMode!=2)&&(segmCleanerMode!=3))
28  edm::LogError("Muon|RecoLocalMuon|DTSegmentCleaner")
29  << "Wrong segmCleanerMode! It must be 1,2 or 3. The default is 1";
30 }
31 
32 /* Destructor */
34 }
35 
36 /* Operations */
37 vector<DTSegmentCand*> DTSegmentCleaner::clean(const std::vector<DTSegmentCand*>& inputCands) const {
38  if (inputCands.size()<2) return inputCands;
39  // cout << "[DTSegmentCleaner] # of candidates: " << inputCands.size() << endl;
40  vector<DTSegmentCand*> result = solveConflict(inputCands);
41 
42  result = ghostBuster(result);
43 
44  return result;
45 }
46 
47 vector<DTSegmentCand*> DTSegmentCleaner::solveConflict(const std::vector<DTSegmentCand*>& inputCands) const {
48  vector<DTSegmentCand*> result;
49 
50  vector<DTSegmentCand*> ghosts;
51 
52 
53  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
54  cand!=inputCands.end(); ++cand) {
55  for (vector<DTSegmentCand*>::const_iterator cand2 = cand+1 ; cand2!=inputCands.end() ; ++cand2) {
56 
57  DTSegmentCand::AssPointCont confHits=(*cand)->conflictingHitPairs(*(*cand2));
58 
59  if (confHits.size()) {
63  if((confHits.size())==((*cand)->nHits()) && (confHits.size())==((*cand2)->nHits())
64  && (fabs((*cand)->chi2()-(*cand2)->chi2())<0.1) ) { // cannot choose on the basis of # of hits or chi2
65 
66  if(segmCleanerMode == 2) { // mode 2: choose on the basis of the angle
67 
68  DTSegmentCand* badCand = 0;
69  if((*cand)->superLayer()->id().superlayer() != 2) { // we are in the phi view
70 
71  LocalVector dir1 = (*cand)->direction();
72  LocalVector dir2 = (*cand2)->direction();
73  float phi1=(atan((dir1.x())/(dir1.z())));
74  float phi2=(atan((dir2.x())/(dir2.z())));
75 
76  badCand = (fabs(phi1) > fabs(phi2)) ? (*cand) : (*cand2);
77 
78  } else { // we are in the theta view: choose the most pointing one
79 
81 
82  GlobalVector cand1GlobDir = (*cand)->superLayer()->toGlobal((*cand)->direction());
83  GlobalPoint cand1GlobPos = (*cand)->superLayer()->toGlobal((*cand)->position());
84  GlobalVector cand1GlobVecIP = cand1GlobPos-IP;
85  float DAlpha1 = fabs(cand1GlobDir.theta()-cand1GlobVecIP.theta());
86 
87 
88  GlobalVector cand2GlobDir = (*cand2)->superLayer()->toGlobal((*cand2)->direction());
89  GlobalPoint cand2GlobPos = (*cand2)->superLayer()->toGlobal((*cand2)->position());
90  GlobalVector cand2GlobVecIP = cand2GlobPos-IP;
91  float DAlpha2 = fabs(cand2GlobDir.theta()-cand2GlobVecIP.theta());
92 
93  badCand = (DAlpha1 > DAlpha2) ? (*cand) : (*cand2);
94 
95  }
96 
97  for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
98  cHit!=confHits.end(); ++cHit) {
99  badCand->removeHit(*cHit);
100  }
101 
102  } else { // mode 3: keep both candidates
103  continue;
104  }
105 
106  } else { // mode 1: take > # hits or best chi2
107  DTSegmentCand* badCand = (**cand) < (**cand2) ? (*cand) : (*cand2);
108  for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
109  cHit!=confHits.end(); ++cHit) badCand->removeHit(*cHit);
110  }
111 
112  }
113  }
114  }
115 
116 
117  vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
118  while ( cand < inputCands.end() ) {
119  if ((*cand)->good()) result.push_back(*cand);
120  else {
121  vector<DTSegmentCand*>::const_iterator badCand=cand;
122  delete *badCand;
123  }
124  ++cand;
125  }
126  return result;
127 }
128 
129 vector<DTSegmentCand*>
130 DTSegmentCleaner::ghostBuster(const std::vector<DTSegmentCand*>& inputCands) const {
131  vector<DTSegmentCand*> ghosts;
132  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
133  cand!=inputCands.end(); ++cand) {
134  for (vector<DTSegmentCand*>::const_iterator cand2=cand+1;
135  cand2!=inputCands.end(); ++cand2) {
136  unsigned int nSharedHits=(*cand)->nSharedHitPairs(*(*cand2));
137  // cout << "Sharing " << (**cand) << " " << (**cand2) << " " << nSharedHits
138  // << " (first or second) " << ((**cand)<(**cand2)) << endl;
139  if ((nSharedHits==((*cand)->nHits())) && (nSharedHits==((*cand2)->nHits()))
140  &&(fabs((*cand)->chi2()-(*cand2)->chi2())<0.1)
141  &&(segmCleanerMode==3))
142  {
143  continue;
144  }
145 
146  // remove the worst segment if too many shared hits or too few unshared
147  if ((int)nSharedHits >= nSharedHitsMax ||
148  (int)((*cand)->nHits()-nSharedHits)<=nUnSharedHitsMin ||
149  (int)((*cand2)->nHits()-nSharedHits)<=nUnSharedHitsMin) {
150 
151  if ((**cand)<(**cand2)) {
152  ghosts.push_back(*cand);
153  }
154  else {
155  ghosts.push_back(*cand2);
156  }
157  continue;
158  }
159 
160  }
161  }
162 
163  vector<DTSegmentCand*> result;
164  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
165  cand!=inputCands.end(); ++cand) {
166  bool isGhost=false;
167  for (vector<DTSegmentCand*>::const_iterator ghost=ghosts.begin();
168  ghost!=ghosts.end(); ++ghost) {
169  if ((*cand)==(*ghost)) {
170  isGhost=true;
171  break;
172  }
173  }
174  if (!isGhost) result.push_back(*cand);
175  else delete *cand;
176  }
177  // cout << "No Ghosts ------" << endl;
178  // for (vector<DTSegmentCand*>::iterator cand=result.begin();
179  // cand!=result.end(); ++cand) {
180  // cout << "cand " << *cand << " nH " <<(*cand)->nHits() << " chi2 " << (*cand)->chi2() << endl;
181  // }
182  // cout << "----------------" << endl;
183 
184  return result;
185 }
T getParameter(std::string const &) const
std::vector< DTSegmentCand * > solveConflict(const std::vector< DTSegmentCand * > &inputCands) const
solve the conflicts
std::vector< DTSegmentCand * > clean(const std::vector< DTSegmentCand * > &inputCands) const
do the cleaning
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
DTSegmentCleaner(const edm::ParameterSet &pset)
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
tuple IP
Definition: listHistos.py:76
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:39
std::vector< DTSegmentCand * > ghostBuster(const std::vector< DTSegmentCand * > &inputCands) const
ghost suppression
virtual void removeHit(AssPoint hit)
remove hit from the candidate
T x() const
Definition: PV3DBase.h:62