CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoMuon/MuonSeedGenerator/src/RPCSeedOverlapper.cc

Go to the documentation of this file.
00001 
00007 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedOverlapper.h"
00008 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00009 #include <Geometry/CommonDetUnit/interface/GeomDetUnit.h>
00010 
00011 using namespace std;
00012 using namespace edm;
00013 
00014 RPCSeedOverlapper::RPCSeedOverlapper() {
00015 
00016     isConfigured = false; 
00017     isIOset = false;
00018     isEventSetupset = false;
00019 }
00020 
00021 RPCSeedOverlapper::~RPCSeedOverlapper() {
00022 
00023 }
00024 
00025 void RPCSeedOverlapper::configure(const edm::ParameterSet& iConfig) {
00026 
00027     isCheckgoodOverlap = iConfig.getParameter<bool>("isCheckgoodOverlap");
00028     isCheckcandidateOverlap = iConfig.getParameter<bool>("isCheckcandidateOverlap");
00029     ShareRecHitsNumberThreshold = iConfig.getParameter<unsigned int>("ShareRecHitsNumberThreshold");
00030     isConfigured = true;
00031 }
00032 
00033 void RPCSeedOverlapper::setIO(std::vector<weightedTrajectorySeed> *goodweightedRef, std::vector<weightedTrajectorySeed> *candidateweightedRef) {
00034 
00035     goodweightedSeedsRef = goodweightedRef;
00036     candidateweightedSeedsRef = candidateweightedRef;
00037     isIOset = true;
00038 }
00039 
00040 void RPCSeedOverlapper::unsetIO() {
00041 
00042     isIOset = false;
00043 }
00044 
00045 void RPCSeedOverlapper::setEventSetup(const edm::EventSetup& iSetup) {
00046 
00047     eSetup = &iSetup;
00048     isEventSetupset = true;
00049 }
00050 
00051 void RPCSeedOverlapper::run() {
00052 
00053     if(isConfigured == false || isIOset == false || isEventSetupset == false) {
00054         cout << "Configuration or IO is not set yet" << endl;
00055         return;
00056     }
00057     if(isCheckgoodOverlap == true)
00058         CheckOverlap(*eSetup, goodweightedSeedsRef);
00059     if(isCheckcandidateOverlap == true)
00060         CheckOverlap(*eSetup, candidateweightedSeedsRef);
00061 }
00062 
00063 void RPCSeedOverlapper::CheckOverlap(const edm::EventSetup& iSetup, std::vector<weightedTrajectorySeed> *weightedSeedsRef) {
00064 
00065     std::vector<weightedTrajectorySeed> sortweightedSeeds;
00066     std::vector<weightedTrajectorySeed> tempweightedSeeds;
00067     edm::OwnVector<TrackingRecHit> tempRecHits;
00068 
00069     edm::ESHandle<RPCGeometry> rpcGeometry;
00070     iSetup.get<MuonGeometryRecord>().get(rpcGeometry);
00071 
00072     while(weightedSeedsRef->size() != 0) {
00073         cout << "Finding the weighted seeds group from " << weightedSeedsRef->size() << " seeds which share some recHits" << endl; 
00074         // Take 1st seed in SeedsRef as referrence and find a collection which always share some recHits with some other
00075         tempRecHits.clear();
00076         tempweightedSeeds.clear();
00077         int N = 0;
00078         for(vector<weightedTrajectorySeed>::iterator itweightedseed = weightedSeedsRef->begin(); itweightedseed != weightedSeedsRef->end(); N++) {
00079             TrajectorySeed::range RecHitsRange = itweightedseed->first.recHits();
00080             if(N == 0) {
00081                 cout << "Always take the 1st weighted seed to be the referrence." << endl;
00082                 for(TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
00083                     cout << "Put its recHits to tempRecHits" << endl;
00084                     tempRecHits.push_back(it->clone());
00085                 }
00086                 cout << "Put it to tempweightedSeeds" << endl;
00087                 tempweightedSeeds.push_back(*itweightedseed);
00088                 cout << "Then erase from weightedSeedsRef->" << endl;
00089                 itweightedseed = weightedSeedsRef->erase(itweightedseed);
00090             }
00091             else {
00092                 cout << "Come to other weighted seed for checking " << itweightedseed->first.nHits() << " recHits from " << tempRecHits.size() << " temp recHits" << endl;
00093                 unsigned int ShareRecHitsNumber = 0;
00094                 for(TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
00095                     if(isShareHit(tempRecHits, *it, rpcGeometry))
00096                         ShareRecHitsNumber++;
00097                 }
00098                 if(ShareRecHitsNumber >= ShareRecHitsNumberThreshold) {
00099                     cout <<"This seed is found to belong to current share group" << endl;
00100                     for(TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++) {
00101                         if(!isShareHit(tempRecHits, *it, rpcGeometry)) {
00102                             cout << "Put its extra recHits to tempRecHits" << endl;
00103                             tempRecHits.push_back(it->clone());
00104                         }
00105                     }
00106                     cout << "Put it to tempSeeds" << endl;
00107                     tempweightedSeeds.push_back(*itweightedseed);
00108                     cout << "Then erase from SeedsRef" << endl;
00109                     itweightedseed = weightedSeedsRef->erase(itweightedseed);
00110                 }
00111                 else
00112                     itweightedseed++;
00113             }
00114         }
00115         // Find the best weighted seed and kick out those share recHits with it
00116         // The best weighted seed save in sortweightedSeeds, those don't share recHits with it will be push back to weightedSeedsRef for next while loop
00117         weightedTrajectorySeed bestweightedSeed;
00118         vector<weightedTrajectorySeed>::iterator bestweightediter;
00119         // Find the min Spt wrt Pt as the best Seed
00120         double Quality = 1000000;
00121         unsigned NumberofHits = 0;
00122         cout << "Find " << tempweightedSeeds.size() << " seeds into one trajectory group" << endl;
00123         for(vector<weightedTrajectorySeed>::iterator itweightedseed = tempweightedSeeds.begin(); itweightedseed != tempweightedSeeds.end(); itweightedseed++) {
00124             unsigned int nHits = itweightedseed->first.nHits();
00125             //std::vector<float> seed_error = itweightedseed->first.startingState().errorMatrix();
00126             //double Spt = seed_error[1];
00127             double weightedQuality = itweightedseed->second;
00128             cout << "Find a weighted seed with quality " << weightedQuality << endl;
00129             if((NumberofHits < nHits) || (NumberofHits == nHits && weightedQuality < Quality)) {
00130                 NumberofHits = nHits;
00131                 Quality = weightedQuality;
00132                 bestweightedSeed = *itweightedseed;
00133                 bestweightediter = itweightedseed;
00134             }
00135         }
00136         cout << "Best good temp seed's quality is " << Quality <<endl;
00137         sortweightedSeeds.push_back(bestweightedSeed);
00138         tempweightedSeeds.erase(bestweightediter);
00139         tempRecHits.clear();
00140 
00141         for(TrajectorySeed::const_iterator it = bestweightedSeed.first.recHits().first; it != bestweightedSeed.first.recHits().second; it++)
00142             tempRecHits.push_back(it->clone());
00143 
00144         for(vector<weightedTrajectorySeed>::iterator itweightedseed = tempweightedSeeds.begin(); itweightedseed != tempweightedSeeds.end(); ) {
00145             cout << "Checking the temp weighted seed's " << itweightedseed->first.nHits() << " hits to " << tempRecHits.size() << " temp recHits" << endl;
00146             TrajectorySeed::range RecHitsRange = itweightedseed->first.recHits();
00147             bool isShare = false;
00148             for(TrajectorySeed::const_iterator it = RecHitsRange.first; it != RecHitsRange.second; it++)
00149                 if(isShareHit(tempRecHits, *it, rpcGeometry))
00150                     isShare = true;
00151 
00152             if(isShare == true) {
00153                 cout << "Find one temp seed share some recHits with best weighted seed" << endl;
00154                 itweightedseed = tempweightedSeeds.erase(itweightedseed);
00155             }
00156             else {
00157                 cout << "This seed has no relation with best weighted seed" << endl;
00158                 weightedSeedsRef->push_back(*itweightedseed);
00159                 itweightedseed = tempweightedSeeds.erase(itweightedseed);
00160             }
00161         }
00162     }
00163     // At the end exchange SeedsRef with sortSeeds
00164     weightedSeedsRef->clear();
00165     *weightedSeedsRef = sortweightedSeeds;
00166 }
00167 
00168 bool RPCSeedOverlapper::isShareHit(const edm::OwnVector<TrackingRecHit> &RecHits, const TrackingRecHit& hit, edm::ESHandle<RPCGeometry> rpcGeometry) {
00169 
00170     bool istheSame = false;
00171     unsigned int n = 1;
00172     cout << "Checking from " << RecHits.size() << " temp recHits" << endl;
00173 
00174     LocalPoint lpos1 = hit.localPosition();
00175     DetId RPCId1 = hit.geographicalId();
00176     const GeomDetUnit *rpcroll1 = rpcGeometry->idToDetUnit(RPCId1);
00177     GlobalPoint gpos1 = rpcroll1->toGlobal(lpos1);
00178     cout << "The hit's position: " << gpos1.x() << ", " << gpos1.y() << ", " << gpos1.z() << endl;
00179     for(edm::OwnVector<TrackingRecHit>::const_iterator it = RecHits.begin(); it !=RecHits.end(); it++, n++) {
00180         cout << "Checking the " << n << " th recHit from tempRecHits" << endl;
00181         LocalPoint lpos2 = it->localPosition();
00182         DetId RPCId2 = it->geographicalId();
00183         const GeomDetUnit *rpcroll2 = rpcGeometry->idToDetUnit(RPCId2);
00184         GlobalPoint gpos2 = rpcroll2->toGlobal(lpos2);
00185         cout << "The temp hit's position: " << gpos2.x() << ", " << gpos2.y() << ", " << gpos2.z() << endl;
00186 
00187         if((gpos1.x() == gpos2.x()) && (gpos1.y() == gpos2.y()) && (gpos1.z() == gpos2.z())) {
00188             cout << "This hit is found to be the same" << endl;
00189             istheSame = true;
00190         }
00191     }
00192     return istheSame;
00193 }