CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/RecoTracker/RoadSearchHelixMaker/src/RoadSearchTrackListCleaner.cc

Go to the documentation of this file.
00001 //
00002 // Package:         RecoTracker/RoadSearchTrackListCleaner
00003 // Class:           RoadSearchHelixMaker
00004 // 
00005 // Description:     TrackListCleaner
00006 //
00007 // Original Author: Steve Wagner, stevew@pizero.colorado.edu
00008 // Created:         Sat Jan 14 22:00:00 UTC 2006
00009 //
00010 // $Author: slava77 $
00011 // $Date: 2012/11/23 16:33:12 $
00012 // $Revision: 1.7 $
00013 //
00014 
00015 #include <memory>
00016 #include <string>
00017 #include <iostream>
00018 #include <cmath>
00019 #include <vector>
00020 
00021 #include "RecoTracker/RoadSearchHelixMaker/interface/RoadSearchTrackListCleaner.h"
00022 
00023 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00024 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00025 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00026 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00027 
00028 #include "DataFormats/Common/interface/Handle.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/Framework/interface/EventSetup.h"
00031 
00032 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00033 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00034 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00035 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00036 
00037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00038 #include "DataFormats/TrackReco/interface/Track.h"
00039 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00040 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00041 
00042 namespace cms
00043 {
00044 
00045   RoadSearchTrackListCleaner::RoadSearchTrackListCleaner(edm::ParameterSet const& conf) : 
00046     conf_(conf)
00047   {
00048     produces<reco::TrackCollection>();
00049 //    produces<reco::TrackExtraCollection>();
00050   }
00051 
00052 
00053   // Virtual destructor needed.
00054   RoadSearchTrackListCleaner::~RoadSearchTrackListCleaner() { }  
00055 
00056   // Functions that gets called by framework every event
00057   void RoadSearchTrackListCleaner::produce(edm::Event& e, const edm::EventSetup& es)
00058   {
00059     // retrieve producer name of input SiStripRecHit2DCollection
00060     std::string trackProducer = conf_.getParameter<std::string>("TrackProducer");
00061     double maxNormalizedChisq =  conf_.getParameter<double>("MaxNormalizedChisq");
00062     double minPT =  conf_.getParameter<double>("MinPT");
00063     unsigned int minFound = (unsigned int)conf_.getParameter<int>("MinFound");
00064   
00065     //
00066     // extract tracker geometry
00067     //
00068     edm::ESHandle<TrackerGeometry> theG;
00069     es.get<TrackerDigiGeometryRecord>().get(theG);
00070 
00071 //    using namespace reco;
00072 
00073     // get Inputs 
00074     edm::Handle<reco::TrackCollection> trackCollection;
00075     e.getByLabel(trackProducer, trackCollection);
00076 
00077     const reco::TrackCollection tC = *(trackCollection.product());
00078 
00079     //std::cout << "Reconstructed "<< tC.size() << " tracks" << std::endl ;
00080 
00081     // Step B: create empty output collection
00082     std::auto_ptr<reco::TrackCollection> output(new reco::TrackCollection);
00083 
00084   //
00085   //  no input tracks
00086   //
00087 
00088     if ( tC.empty() ){
00089 //      LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
00090       e.put(output);
00091       return;  
00092     }
00093 
00094   //
00095   //  quality cuts first
00096   //
00097     std::vector<int> selected; for (unsigned int i=0; i<tC.size(); ++i){selected.push_back(1);}
00098 
00099       int i=-1;
00100       for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
00101         i++;
00102         if ((short unsigned)track->ndof() < 1){
00103           selected[i]=0; 
00104           //std::cout << "Track "<< i << " rejected in TrackListCleaner; ndof() < 1" << std::endl ;
00105           continue;
00106         }
00107         if (track->normalizedChi2() > maxNormalizedChisq){
00108           selected[i]=0; 
00109           //std::cout << "Track "<< i << " rejected in TrackListCleaner; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
00110           continue;
00111         }
00112         if (track->found() < minFound){
00113           selected[i]=0; 
00114           //std::cout << "Track "<< i << " rejected in TrackListCleaner; found() < minFound " << track->found() << " " << minFound << std::endl ;
00115           continue;
00116         }
00117         if (track->pt() < minPT){
00118           selected[i]=0; 
00119           //std::cout << "Track "<< i << " rejected in TrackListCleaner; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
00120           continue;
00121         }
00122       }//end loop over tracks
00123 
00124   //
00125   //  > 1 track - try merging
00126   //
00127    if ( 1<tC.size() ){
00128     int i=-1;
00129     for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
00130       i++; 
00131       //std::cout << "Track number "<< i << std::endl ; 
00132       if (!selected[i])continue;
00133       int j=-1;
00134       for (reco::TrackCollection::const_iterator track2=tC.begin(); track2!=tC.end(); track2++){
00135         j++;
00136         if ((j<=i)||(!selected[j])||(!selected[i]))continue;
00137         int noverlap=0;
00138         for (trackingRecHit_iterator it = track->recHitsBegin();  it != track->recHitsEnd(); it++){
00139           if ((*it)->isValid()){
00140             for (trackingRecHit_iterator jt = track2->recHitsBegin();  jt != track2->recHitsEnd(); jt++){
00141               if ((*jt)->isValid()){
00142                 if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
00143               }
00144             }
00145           }
00146         }
00147         float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
00148         //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->recHitsSize() << " "  << track2->recHitsSize() << " " << noverlap << " " << fi << " " << fj  <<std::endl;
00149         if ((fi>0.66)||(fj>0.66)){
00150           if (fi<fj){
00151             selected[j]=0; 
00152             //std::cout << " removing 2nd trk in pair " << std::endl;
00153           }else{
00154             if (fi>fj){
00155               selected[i]=0; 
00156               //std::cout << " removing 1st trk in pair " << std::endl;
00157             }else{
00158               //std::cout << " removing worst chisq in pair " << std::endl;
00159               if (track->chi2() > track2->chi2()){selected[i]=0;}else{selected[j]=0;}
00160             }//end fi > or = fj
00161           }//end fi < fj
00162         }//end got a duplicate
00163       }//end track2 loop
00164     }//end track loop
00165    }//end more than 1 track
00166 
00167   //
00168   //  output selected tracks - if any
00169   //
00170     i=-1;
00171     for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
00172       i++;  if (!selected[i])continue;
00173         reco::Track * theTrack = new reco::Track(track->chi2(),
00174                                                  (short unsigned)track->ndof(),
00175                                                  track->innerPosition(),
00176                                                  track->innerMomentum(),
00177                                                  track->charge(),
00178                                                  track->innerStateCovariance());    
00179       //fill the TrackCollection
00180       reco::TrackExtraRef theTrackExtraRef=track->extra();    
00181       theTrack->setExtra(theTrackExtraRef);    
00182       theTrack->setHitPattern((*theTrackExtraRef).recHits());
00183       output->push_back(*theTrack);
00184       delete theTrack;
00185     }//end faux loop over tracks
00186     e.put(output);
00187     return;
00188 
00189   }//end produce
00190 
00191 }