Go to the documentation of this file.00001
00009
00010 #include "RecoLocalMuon/DTSegment/src/DTSegmentCleaner.h"
00011
00012
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016
00017 using namespace std;
00018
00019
00020
00021
00022 DTSegmentCleaner::DTSegmentCleaner(const edm::ParameterSet& pset) {
00023 nSharedHitsMax = pset.getParameter<int>("nSharedHitsMax");
00024
00025 nUnSharedHitsMin = pset.getParameter<int>("nUnSharedHitsMin");
00026
00027 segmCleanerMode = pset.getParameter<int>("segmCleanerMode");
00028
00029 if((segmCleanerMode!=1)&&(segmCleanerMode!=2)&&(segmCleanerMode!=3))
00030 edm::LogError("Muon|RecoLocalMuon|DTSegmentCleaner")
00031 << "Wrong segmCleanerMode! It must be 1,2 or 3. The default is 1";
00032 }
00033
00034
00035 DTSegmentCleaner::~DTSegmentCleaner() {
00036 }
00037
00038
00039 vector<DTSegmentCand*> DTSegmentCleaner::clean(vector<DTSegmentCand*> inputCands) const {
00040 if (inputCands.size()<2) return inputCands;
00041
00042 vector<DTSegmentCand*> result = solveConflict(inputCands);
00043
00044 result = ghostBuster(result);
00045
00046 return result;
00047 }
00048
00049 vector<DTSegmentCand*> DTSegmentCleaner::solveConflict(vector<DTSegmentCand*> inputCands) const {
00050 vector<DTSegmentCand*> result;
00051
00052 vector<DTSegmentCand*> ghosts;
00053
00054
00055 for (vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00056 cand!=inputCands.end(); ++cand) {
00057 for (vector<DTSegmentCand*>::iterator cand2 = cand+1 ; cand2!=inputCands.end() ; ++cand2) {
00058
00059 DTSegmentCand::AssPointCont confHits=(*cand)->conflictingHitPairs(*(*cand2));
00060
00061 if (confHits.size()) {
00065 if((confHits.size())==((*cand)->nHits()) && (confHits.size())==((*cand2)->nHits())
00066 && (fabs((*cand)->chi2()-(*cand2)->chi2())<0.1) ) {
00067
00068 if(segmCleanerMode == 2) {
00069
00070 DTSegmentCand* badCand = 0;
00071 if((*cand)->superLayer()->id().superlayer() != 2) {
00072
00073 LocalVector dir1 = (*cand)->direction();
00074 LocalVector dir2 = (*cand2)->direction();
00075 float phi1=(atan((dir1.x())/(dir1.z())));
00076 float phi2=(atan((dir2.x())/(dir2.z())));
00077
00078 badCand = (fabs(phi1) > fabs(phi2)) ? (*cand) : (*cand2);
00079
00080 } else {
00081
00082 GlobalPoint IP;
00083
00084 GlobalVector cand1GlobDir = (*cand)->superLayer()->toGlobal((*cand)->direction());
00085 GlobalPoint cand1GlobPos = (*cand)->superLayer()->toGlobal((*cand)->position());
00086 GlobalVector cand1GlobVecIP = cand1GlobPos-IP;
00087 float DAlpha1 = fabs(cand1GlobDir.theta()-cand1GlobVecIP.theta());
00088
00089
00090 GlobalVector cand2GlobDir = (*cand2)->superLayer()->toGlobal((*cand2)->direction());
00091 GlobalPoint cand2GlobPos = (*cand2)->superLayer()->toGlobal((*cand2)->position());
00092 GlobalVector cand2GlobVecIP = cand2GlobPos-IP;
00093 float DAlpha2 = fabs(cand2GlobDir.theta()-cand2GlobVecIP.theta());
00094
00095 badCand = (DAlpha1 > DAlpha2) ? (*cand) : (*cand2);
00096
00097 }
00098
00099 for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
00100 cHit!=confHits.end(); ++cHit) {
00101 badCand->removeHit(*cHit);
00102 }
00103
00104 } else {
00105 continue;
00106 }
00107
00108 } else {
00109 DTSegmentCand* badCand = (**cand) < (**cand2) ? (*cand) : (*cand2);
00110 for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
00111 cHit!=confHits.end(); ++cHit) badCand->removeHit(*cHit);
00112 }
00113
00114 }
00115 }
00116 }
00117
00118
00119 vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00120 while ( cand < inputCands.end() ) {
00121 if ((*cand)->good()) result.push_back(*cand);
00122 else {
00123 vector<DTSegmentCand*>::iterator badCand=cand;
00124 delete *badCand;
00125 }
00126 ++cand;
00127 }
00128 return result;
00129 }
00130
00131 vector<DTSegmentCand*>
00132 DTSegmentCleaner::ghostBuster(vector<DTSegmentCand*> inputCands) const {
00133 vector<DTSegmentCand*> ghosts;
00134 for (vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00135 cand!=inputCands.end(); ++cand) {
00136 for (vector<DTSegmentCand*>::iterator cand2=cand+1;
00137 cand2!=inputCands.end(); ++cand2) {
00138 unsigned int nSharedHits=(*cand)->nSharedHitPairs(*(*cand2));
00139
00140
00141 if ((nSharedHits==((*cand)->nHits())) && (nSharedHits==((*cand2)->nHits()))
00142 &&(fabs((*cand)->chi2()-(*cand2)->chi2())<0.1)
00143 &&(segmCleanerMode==3))
00144 {
00145 continue;
00146 }
00147
00148
00149 if ((int)nSharedHits >= nSharedHitsMax ||
00150 (int)((*cand)->nHits()-nSharedHits)<=nUnSharedHitsMin ||
00151 (int)((*cand2)->nHits()-nSharedHits)<=nUnSharedHitsMin) {
00152
00153 if ((**cand)<(**cand2)) {
00154 ghosts.push_back(*cand);
00155 }
00156 else {
00157 ghosts.push_back(*cand2);
00158 }
00159 continue;
00160 }
00161
00162 }
00163 }
00164
00165 vector<DTSegmentCand*> result;
00166 for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
00167 cand!=inputCands.end(); ++cand) {
00168 bool isGhost=false;
00169 for (vector<DTSegmentCand*>::const_iterator ghost=ghosts.begin();
00170 ghost!=ghosts.end(); ++ghost) {
00171 if ((*cand)==(*ghost)) {
00172 isGhost=true;
00173 break;
00174 }
00175 }
00176 if (!isGhost) result.push_back(*cand);
00177 else delete *cand;
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 return result;
00187 }