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 for (vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00055 cand!=inputCands.end(); ++cand) {
00056 for (vector<DTSegmentCand*>::iterator cand2=cand+1;
00057 cand2!=inputCands.end(); ++cand2) {
00058
00059 DTSegmentCand::AssPointCont confHits=(*cand)->conflictingHitPairs(*(*cand2));
00060
00061 if ( segmCleanerMode != 1
00062 && (confHits.size())==((*cand)->nHits()) && (confHits.size())==((*cand2)->nHits())
00063 && (fabs((*cand)->chi2()-(*cand2)->chi2())<0.1))
00064 {
00065 if(segmCleanerMode==2)
00066 {
00067 LocalVector dir1 = (*cand)->direction();
00068 LocalVector dir2 = (*cand2)->direction();
00069 float phi1=(atan((dir1.x())/(dir1.z())));
00070 float phi2=(atan((dir2.x())/(dir2.z())));
00071
00072 if(fabs(phi1)>fabs(phi2))
00073 for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
00074 cHit!=confHits.end(); ++cHit) {
00075 (*cand)->removeHit(*cHit);
00076 }
00077 else
00078 for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
00079 cHit!=confHits.end(); ++cHit) {
00080 (*cand2)->removeHit(*cHit);
00081 }
00082 }
00083 else
00084 LogDebug("Muon|RecoLocalMuon|DTSegmentCleaner")
00085 << "keep both segment candidates "<<*(*cand)<<" and "<<*(*cand2)<<endl;
00086 }
00087 else if (confHits.size()) {
00088 for (DTSegmentCand::AssPointCont::const_iterator cHit=confHits.begin() ;
00089 cHit!=confHits.end(); ++cHit) {
00090 if ((**cand)<(**cand2))
00091 (*cand)->removeHit(*cHit);
00092 else
00093 (*cand2)->removeHit(*cHit);
00094 }
00095 }
00096 }
00097 }
00098
00099 vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00100 while ( cand < inputCands.end() ) {
00101 if ((*cand)->good())
00102 result.push_back(*cand);
00103 else {
00104 vector<DTSegmentCand*>::iterator badCand=cand;
00105 delete *badCand;
00106 }
00107 ++cand;
00108 }
00109 return result;
00110 }
00111
00112 vector<DTSegmentCand*>
00113 DTSegmentCleaner::ghostBuster(vector<DTSegmentCand*> inputCands) const {
00114 vector<DTSegmentCand*> ghosts;
00115 for (vector<DTSegmentCand*>::iterator cand=inputCands.begin();
00116 cand!=inputCands.end(); ++cand) {
00117 for (vector<DTSegmentCand*>::iterator cand2=cand+1;
00118 cand2!=inputCands.end(); ++cand2) {
00119 unsigned int nSharedHits=(*cand)->nSharedHitPairs(*(*cand2));
00120
00121
00122 if ((nSharedHits==((*cand)->nHits())) && (nSharedHits==((*cand2)->nHits()))
00123 &&(fabs((*cand)->chi2()-(*cand2)->chi2())<0.1)
00124 &&(segmCleanerMode==3))
00125 {
00126 continue;
00127 }
00128
00129
00130 if ((int)nSharedHits >= nSharedHitsMax ||
00131 (int)((*cand)->nHits()-nSharedHits)<=nUnSharedHitsMin ||
00132 (int)((*cand2)->nHits()-nSharedHits)<=nUnSharedHitsMin) {
00133 if ((**cand)<(**cand2)) {
00134
00135 ghosts.push_back(*cand);
00136 }
00137 else {
00138
00139 ghosts.push_back(*cand2);
00140 }
00141 continue;
00142 }
00143
00144 }
00145 }
00146
00147 vector<DTSegmentCand*> result;
00148 for (vector<DTSegmentCand*>::const_iterator cand=inputCands.begin();
00149 cand!=inputCands.end(); ++cand) {
00150 bool isGhost=false;
00151 for (vector<DTSegmentCand*>::const_iterator ghost=ghosts.begin();
00152 ghost!=ghosts.end(); ++ghost) {
00153 if ((*cand)==(*ghost)) {
00154 isGhost=true;
00155 break;
00156 }
00157 }
00158 if (!isGhost) result.push_back(*cand);
00159 else delete *cand;
00160 }
00161
00162
00163
00164
00165
00166
00167
00168 return result;
00169 }