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