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  //cout << "[DTSegmentCleaner] to ghostbuster: " << result.size() << endl;
43  result = ghostBuster(result);
44 
45  return result;
46 }
47 
48 vector<DTSegmentCand*> DTSegmentCleaner::solveConflict(const std::vector<DTSegmentCand*>& inputCands) const {
49  vector<DTSegmentCand*> result;
50 
51  vector<DTSegmentCand*> ghosts;
52 
53 
54  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
55  cand!=inputCands.end(); ++cand) {
56  for (vector<DTSegmentCand*>::const_iterator cand2 = cand+1 ; cand2!=inputCands.end() ; ++cand2) {
57 
58  DTSegmentCand::AssPointCont confHits=(*cand)->conflictingHitPairs(*(*cand2));
59 
60  if (confHits.size()) {
64  if((confHits.size())==((*cand)->nHits()) && (confHits.size())==((*cand2)->nHits())
65  && (fabs((*cand)->chi2()-(*cand2)->chi2())<0.1)) { // cannot choose on the basis of # of hits or chi2
66 
67  if(segmCleanerMode == 2) { // mode 2: choose on the basis of the angle
68 
69  DTSegmentCand* badCand = 0;
70  if((*cand)->superLayer()->id().superlayer() != 2) { // we are in the phi view
71 
72  LocalVector dir1 = (*cand)->direction();
73  LocalVector dir2 = (*cand2)->direction();
74  float phi1=(atan((dir1.x())/(dir1.z())));
75  float phi2=(atan((dir2.x())/(dir2.z())));
76 
77  badCand = (fabs(phi1) > fabs(phi2)) ? (*cand) : (*cand2);
78 
79  } else { // we are in the theta view: choose the most pointing one
80 
82 
83  GlobalVector cand1GlobDir = (*cand)->superLayer()->toGlobal((*cand)->direction());
84  GlobalPoint cand1GlobPos = (*cand)->superLayer()->toGlobal((*cand)->position());
85  GlobalVector cand1GlobVecIP = cand1GlobPos-IP;
86  float DAlpha1 = fabs(cand1GlobDir.theta()-cand1GlobVecIP.theta());
87 
88 
89  GlobalVector cand2GlobDir = (*cand2)->superLayer()->toGlobal((*cand2)->direction());
90  GlobalPoint cand2GlobPos = (*cand2)->superLayer()->toGlobal((*cand2)->position());
91  GlobalVector cand2GlobVecIP = cand2GlobPos-IP;
92  float DAlpha2 = fabs(cand2GlobDir.theta()-cand2GlobVecIP.theta());
93 
94  badCand = (DAlpha1 > DAlpha2) ? (*cand) : (*cand2);
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  //cout << " Choose based on hits/chi2. " << endl << (**cand) << " vs " << (**cand2) << endl;
108 
109  // if one segment is in-time and the other not then keep both
110  if (((*cand)->t0()*(*cand2)->t0()!=0) || ((*cand)->t0()==(*cand2)->t0())) {
111  DTSegmentCand* badCand = (**cand) < (**cand2) ? (*cand) : (*cand2);
112  //cout << " Remove hits in " << (*badCand) << endl;
113  for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
114  cHit!=confHits.end(); ++cHit) badCand->removeHit(*cHit);
115  }
116  }
117 
118  }
119  }
120  }
121 
122  vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
123  while ( cand < inputCands.end() ) {
124  if ((*cand)->good()) result.push_back(*cand);
125  else {
126  vector<DTSegmentCand*>::const_iterator badCand=cand;
127  delete *badCand;
128  }
129  ++cand;
130  }
131  return result;
132 }
133 
134 vector<DTSegmentCand*>
135 DTSegmentCleaner::ghostBuster(const std::vector<DTSegmentCand*>& inputCands) const {
136  vector<DTSegmentCand*> ghosts;
137  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
138  cand!=inputCands.end(); ++cand) {
139  for (vector<DTSegmentCand*>::const_iterator cand2=cand+1;
140  cand2!=inputCands.end(); ++cand2) {
141  unsigned int nSharedHits=(*cand)->nSharedHitPairs(*(*cand2));
143  // << " (first or second) " << ((**cand)<(**cand2)) << endl;
144  if ((nSharedHits==((*cand)->nHits())) && (nSharedHits==((*cand2)->nHits()))
145  &&(fabs((*cand)->chi2()-(*cand2)->chi2())<0.1)
146  &&(segmCleanerMode==3))
147  {
148  continue;
149  }
150 
151  if (((*cand)->nHits()==3 || (*cand2)->nHits()==3)
152  &&(fabs((*cand)->chi2()-(*cand2)->chi2())<0.0001))
153  {
154  continue;
155  }
156 
157  // if one segment is in-time and the other not then keep both
158  if (((*cand2)->nHits()==(*cand)->nHits()) && ((*cand)->t0()*(*cand2)->t0()==0) && ((*cand)->t0()!=(*cand2)->t0()))
159  {
160  continue;
161  }
162 
163  // remove the worst segment if too many shared hits or too few unshared
164  if ((int)nSharedHits >= nSharedHitsMax ||
165  (int)((*cand)->nHits()-nSharedHits)<=nUnSharedHitsMin ||
166  (int)((*cand2)->nHits()-nSharedHits)<=nUnSharedHitsMin) {
167 
168  if ((**cand)<(**cand2)) {
169  ghosts.push_back(*cand);
170  }
171  else {
172  ghosts.push_back(*cand2);
173  }
174  continue;
175  }
176 
177  }
178  }
179 
180  vector<DTSegmentCand*> result;
181  for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
182  cand!=inputCands.end(); ++cand) {
183  bool isGhost=false;
184  for (vector<DTSegmentCand*>::const_iterator ghost=ghosts.begin();
185  ghost!=ghosts.end(); ++ghost) {
186  if ((*cand)==(*ghost)) {
187  isGhost=true;
188  break;
189  }
190  }
191  if (!isGhost) result.push_back(*cand);
192  else delete *cand;
193  }
194  // cout << "No Ghosts ------" << endl;
195  // for (vector<DTSegmentCand*>::iterator cand=result.begin();
196  // cand!=result.end(); ++cand) {
197  // cout << "cand " << *cand << " nH " <<(*cand)->nHits() << " chi2 " << (*cand)->chi2() << endl;
198  // }
199  // cout << "----------------" << endl;
200 
201  return result;
202 }
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:40
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