CMS 3D CMS Logo

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 /* Operations */
36 vector<DTSegmentCand*> DTSegmentCleaner::clean(const std::vector<DTSegmentCand*>& inputCands) const {
37  if (inputCands.size() < 2)
38  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  for (vector<DTSegmentCand*>::const_iterator cand = inputCands.begin(); cand != inputCands.end(); ++cand) {
54  for (vector<DTSegmentCand*>::const_iterator cand2 = cand + 1; cand2 != inputCands.end(); ++cand2) {
55  DTSegmentCand::AssPointCont confHits = (*cand)->conflictingHitPairs(*(*cand2));
56 
57  if (!confHits.empty()) {
61  if ((confHits.size()) == ((*cand)->nHits()) && (confHits.size()) == ((*cand2)->nHits()) &&
62  (fabs((*cand)->chi2() - (*cand2)->chi2()) < 0.1)) { // cannot choose on the basis of # of hits or chi2
63 
64  if (segmCleanerMode == 2) { // mode 2: choose on the basis of the angle
65 
66  DTSegmentCand* badCand = nullptr;
67  if ((*cand)->superLayer()->id().superlayer() != 2) { // we are in the phi view
68 
69  LocalVector dir1 = (*cand)->direction();
70  LocalVector dir2 = (*cand2)->direction();
71  float phi1 = (atan((dir1.x()) / (dir1.z())));
72  float phi2 = (atan((dir2.x()) / (dir2.z())));
73 
74  badCand = (fabs(phi1) > fabs(phi2)) ? (*cand) : (*cand2);
75 
76  } else { // we are in the theta view: choose the most pointing one
77 
79 
80  GlobalVector cand1GlobDir = (*cand)->superLayer()->toGlobal((*cand)->direction());
81  GlobalPoint cand1GlobPos = (*cand)->superLayer()->toGlobal((*cand)->position());
82  GlobalVector cand1GlobVecIP = cand1GlobPos - IP;
83  float DAlpha1 = fabs(cand1GlobDir.theta() - cand1GlobVecIP.theta());
84 
85  GlobalVector cand2GlobDir = (*cand2)->superLayer()->toGlobal((*cand2)->direction());
86  GlobalPoint cand2GlobPos = (*cand2)->superLayer()->toGlobal((*cand2)->position());
87  GlobalVector cand2GlobVecIP = cand2GlobPos - IP;
88  float DAlpha2 = fabs(cand2GlobDir.theta() - cand2GlobVecIP.theta());
89 
90  badCand = (DAlpha1 > DAlpha2) ? (*cand) : (*cand2);
91  }
92 
93  for (DTSegmentCand::AssPointCont::const_iterator cHit = confHits.begin(); cHit != confHits.end(); ++cHit) {
94  badCand->removeHit(*cHit);
95  }
96 
97  } else { // mode 3: keep both candidates
98  continue;
99  }
100 
101  } else { // mode 1: take > # hits or best chi2
102  //cout << " Choose based on hits/chi2. " << endl << (**cand) << " vs " << (**cand2) << endl;
103 
104  // if one segment is in-time and the other not then keep both
105  if (((*cand)->t0() * (*cand2)->t0() != 0) || ((*cand)->t0() == (*cand2)->t0())) {
106  DTSegmentCand* badCand = (**cand) < (**cand2) ? (*cand) : (*cand2);
107  //cout << " Remove hits in " << (*badCand) << endl;
108  for (DTSegmentCand::AssPointCont::const_iterator cHit = confHits.begin(); cHit != confHits.end(); ++cHit)
109  badCand->removeHit(*cHit);
110  }
111  }
112  }
113  }
114  }
115 
116  vector<DTSegmentCand*>::const_iterator cand = inputCands.begin();
117  while (cand < inputCands.end()) {
118  if ((*cand)->good())
119  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*> DTSegmentCleaner::ghostBuster(const std::vector<DTSegmentCand*>& inputCands) const {
130  vector<DTSegmentCand*> ghosts;
131  for (vector<DTSegmentCand*>::const_iterator cand = inputCands.begin(); cand != inputCands.end(); ++cand) {
132  for (vector<DTSegmentCand*>::const_iterator cand2 = cand + 1; cand2 != inputCands.end(); ++cand2) {
133  unsigned int nSharedHits = (*cand)->nSharedHitPairs(*(*cand2));
135  // << " (first or second) " << ((**cand)<(**cand2)) << endl;
136  if ((nSharedHits == ((*cand)->nHits())) && (nSharedHits == ((*cand2)->nHits())) &&
137  (fabs((*cand)->chi2() - (*cand2)->chi2()) < 0.1) && (segmCleanerMode == 3)) {
138  continue;
139  }
140 
141  if (((*cand)->nHits() == 3 || (*cand2)->nHits() == 3) && (fabs((*cand)->chi2() - (*cand2)->chi2()) < 0.0001)) {
142  continue;
143  }
144 
145  // if one segment is in-time and the other not then keep both
146  if (((*cand2)->nHits() == (*cand)->nHits()) && ((*cand)->t0() * (*cand2)->t0() == 0) &&
147  ((*cand)->t0() != (*cand2)->t0())) {
148  continue;
149  }
150 
151  // remove the worst segment if too many shared hits or too few unshared
152  if ((int)nSharedHits >= nSharedHitsMax || (int)((*cand)->nHits() - nSharedHits) <= nUnSharedHitsMin ||
153  (int)((*cand2)->nHits() - nSharedHits) <= nUnSharedHitsMin) {
154  if ((**cand) < (**cand2)) {
155  ghosts.push_back(*cand);
156  } else {
157  ghosts.push_back(*cand2);
158  }
159  continue;
160  }
161  }
162  }
163 
164  vector<DTSegmentCand*> result;
165  for (vector<DTSegmentCand*>::const_iterator cand = inputCands.begin(); cand != inputCands.end(); ++cand) {
166  bool isGhost = false;
167  for (vector<DTSegmentCand*>::const_iterator ghost = ghosts.begin(); ghost != ghosts.end(); ++ghost) {
168  if ((*cand) == (*ghost)) {
169  isGhost = true;
170  break;
171  }
172  }
173  if (!isGhost)
174  result.push_back(*cand);
175  else
176  delete *cand;
177  }
178  // cout << "No Ghosts ------" << endl;
179  // for (vector<DTSegmentCand*>::iterator cand=result.begin();
180  // cand!=result.end(); ++cand) {
181  // cout << "cand " << *cand << " nH " <<(*cand)->nHits() << " chi2 " << (*cand)->chi2() << endl;
182  // }
183  // cout << "----------------" << endl;
184 
185  return result;
186 }
Vector3DBase< float, LocalTag >
DTSegmentCleaner::DTSegmentCleaner
DTSegmentCleaner(const edm::ParameterSet &pset)
Definition: DTSegmentCleaner.cc:20
L1TDiffHarvesting_cfi.dir2
dir2
Definition: L1TDiffHarvesting_cfi.py:12
DTSegmentCleaner::~DTSegmentCleaner
~DTSegmentCleaner()
Definition: DTSegmentCleaner.cc:33
MessageLogger.h
DTSegmentCleaner::solveConflict
std::vector< DTSegmentCand * > solveConflict(const std::vector< DTSegmentCand * > &inputCands) const
solve the conflicts
Definition: DTSegmentCleaner.cc:48
HLT_2018_cff.nSharedHitsMax
nSharedHitsMax
Definition: HLT_2018_cff.py:7687
DTSegmentCleaner.h
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
DTSegmentCand
Definition: DTSegmentCand.h:34
L1TDiffHarvesting_cfi.dir1
dir1
Definition: L1TDiffHarvesting_cfi.py:10
DTSegmentCleaner::ghostBuster
std::vector< DTSegmentCand * > ghostBuster(const std::vector< DTSegmentCand * > &inputCands) const
ghost suppression
Definition: DTSegmentCleaner.cc:129
Point3DBase< float, GlobalTag >
listHistos.IP
IP
Definition: listHistos.py:76
HLT_2018_cff.nUnSharedHitsMin
nUnSharedHitsMin
Definition: HLT_2018_cff.py:7686
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
cand
Definition: decayParser.h:34
createfilelist.int
int
Definition: createfilelist.py:10
HLT_2018_cff.segmCleanerMode
segmCleanerMode
Definition: HLT_2018_cff.py:7661
DTSegmentCand::AssPointCont
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:38
std
Definition: JetResolutionObject.h:76
DTSegmentCleaner::clean
std::vector< DTSegmentCand * > clean(const std::vector< DTSegmentCand * > &inputCands) const
do the cleaning
Definition: DTSegmentCleaner.cc:36
DTSegmentCand::removeHit
virtual void removeHit(AssPoint hit)
remove hit from the candidate
Definition: DTSegmentCand.cc:65
mps_fire.result
result
Definition: mps_fire.py:303
ParameterSet.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27