CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoTracker/RoadSearchCloudCleaner/src/RoadSearchCloudCleanerAlgorithm.cc

Go to the documentation of this file.
00001 //
00002 // Package:         RecoTracker/RoadSearchCloudMaker
00003 // Class:           RoadSearchCloudCleanerAlgorithm
00004 // 
00005 // Description:     
00006 //
00007 // Original Author: Steve Wagner, stevew@pizero.colorado.edu
00008 // Created:         Sat Feb 19 22:00:00 UTC 2006
00009 //
00010 // $Author: gutsche $
00011 // $Date: 2007/07/10 03:14:44 $
00012 // $Revision: 1.7 $
00013 //
00014 
00015 #include <vector>
00016 
00017 #include "RecoTracker/RoadSearchCloudCleaner/interface/RoadSearchCloudCleanerAlgorithm.h"
00018 
00019 #include "DataFormats/RoadSearchCloud/interface/RoadSearchCloud.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 RoadSearchCloudCleanerAlgorithm::RoadSearchCloudCleanerAlgorithm(const edm::ParameterSet& conf) {
00024   
00025   // store parameter
00026   mergingFraction_ = conf.getParameter<double>("MergingFraction");
00027   maxRecHitsInCloud_ = conf.getParameter<int>("MaxRecHitsInCloud");
00028 
00029 }
00030 
00031 RoadSearchCloudCleanerAlgorithm::~RoadSearchCloudCleanerAlgorithm() {
00032 }
00033 
00034 void RoadSearchCloudCleanerAlgorithm::run(const RoadSearchCloudCollection* input,
00035                                           const edm::EventSetup& es,
00036                                           RoadSearchCloudCollection &output)
00037 {
00038 
00039   //
00040   //  right now cloud cleaning solely consist of merging clouds based on the number
00041   //  of shared hits (getting rid of obvious duplicates) - don't need roads and
00042   //  geometry for this - eventually this stage will become a sub-process (probably
00043   //  early on) of cloud cleaning
00044   //
00045 
00046   LogDebug("RoadSearch") << "Raw Clouds input size: " << input->size(); 
00047 
00048   //
00049   //  no raw clouds - nothing to try merging
00050   //
00051 
00052   if ( input->empty() ){
00053     LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
00054     return;  
00055   }
00056 
00057   //
00058   //  1 raw cloud - nothing to try merging, but one cloud to duplicate
00059   //
00060 
00061   if ( 1==input->size() ){
00062     output = *input;
00063     LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
00064     return;
00065   }  
00066 
00067   //
00068   //  got > 1 raw cloud - something to try merging
00069   //
00070   std::vector<bool> already_gone(input->size());
00071   for (unsigned int i=0; i<input->size(); ++i) {
00072     already_gone[i] = false; 
00073   }
00074 
00075   int raw_cloud_ctr=0;
00076   // loop over clouds
00077   for ( RoadSearchCloudCollection::const_iterator raw_cloud = input->begin(); raw_cloud != input->end(); ++raw_cloud) {
00078     ++raw_cloud_ctr;
00079 
00080     if (already_gone[raw_cloud_ctr-1])continue;
00081 
00082     // produce output cloud where other clouds are merged in
00083     RoadSearchCloud lone_cloud = *raw_cloud;
00084     int second_cloud_ctr=raw_cloud_ctr;
00085     for ( RoadSearchCloudCollection::const_iterator second_cloud = raw_cloud+1; second_cloud != input->end(); ++second_cloud) {
00086       second_cloud_ctr++;
00087 
00088       std::vector<const TrackingRecHit*> unshared_hits;
00089 
00090       if ( already_gone[second_cloud_ctr-1] )continue;
00091 
00092       for ( RoadSearchCloud::RecHitVector::const_iterator second_cloud_hit = second_cloud->begin_hits();
00093             second_cloud_hit != second_cloud->end_hits();
00094             ++ second_cloud_hit ) {
00095         bool is_shared = false;
00096         for ( RoadSearchCloud::RecHitVector::const_iterator lone_cloud_hit = lone_cloud.begin_hits();
00097               lone_cloud_hit != lone_cloud.end_hits();
00098               ++ lone_cloud_hit ) {
00099 
00100           if ((*lone_cloud_hit)->geographicalId().rawId() == (*second_cloud_hit)->geographicalId().rawId())
00101             if ((*lone_cloud_hit)->localPosition().x() == (*second_cloud_hit)->localPosition().x())
00102               if ((*lone_cloud_hit)->localPosition().y() == (*second_cloud_hit)->localPosition().y())
00103                 {is_shared=true; break;}
00104         }
00105         if (!is_shared)  unshared_hits.push_back(*second_cloud_hit);
00106 
00107         if ( ((float(unshared_hits.size())/float(lone_cloud.size())) > 
00108               ((float(second_cloud->size())/float(lone_cloud.size()))-mergingFraction_)) &&
00109              ((float(unshared_hits.size())/float(second_cloud->size())) > (1-mergingFraction_))){
00110           // You'll never merge these clouds..... Could quit now!
00111           break;
00112         }
00113 
00114       }
00115       
00116       double f_lone_shared=double(second_cloud->size()-unshared_hits.size())/double(lone_cloud.size());
00117       double f_second_shared=double(second_cloud->size()-unshared_hits.size())/double(second_cloud->size());
00118       
00119       if ( ( (static_cast<unsigned int>(f_lone_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9))||(static_cast<unsigned int>(f_second_shared*1E9) > static_cast<unsigned int>(mergingFraction_*1E9)) ) 
00120            && (lone_cloud.size()+unshared_hits.size() <= maxRecHitsInCloud_) ){
00121 
00122         LogDebug("RoadSearch") << " Merge CloudA: " << raw_cloud_ctr << " with  CloudB: " << second_cloud_ctr 
00123                                << " Shared fractions are " << f_lone_shared << " and " << f_second_shared;
00124 
00125         //
00126         //  got a cloud to merge
00127         //
00128         for (unsigned int k=0; k<unshared_hits.size(); ++k) {
00129           lone_cloud.addHit(unshared_hits[k]);
00130         }
00131 
00132         already_gone[second_cloud_ctr-1]=true;
00133 
00134         }//end got a cloud to merge
00135 
00136     }//interate over all second clouds
00137 
00138     output.push_back(lone_cloud);
00139     
00140   }//iterate over all raw clouds
00141 
00142   LogDebug("RoadSearch") << "Found " << output.size() << " clean clouds.";
00143 
00144 }
00145 
00146