Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00050 }
00051
00052
00053
00054 RoadSearchTrackListCleaner::~RoadSearchTrackListCleaner() { }
00055
00056
00057 void RoadSearchTrackListCleaner::produce(edm::Event& e, const edm::EventSetup& es)
00058 {
00059
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
00067
00068 edm::ESHandle<TrackerGeometry> theG;
00069 es.get<TrackerDigiGeometryRecord>().get(theG);
00070
00071
00072
00073
00074 edm::Handle<reco::TrackCollection> trackCollection;
00075 e.getByLabel(trackProducer, trackCollection);
00076
00077 const reco::TrackCollection tC = *(trackCollection.product());
00078
00079
00080
00081
00082 std::auto_ptr<reco::TrackCollection> output(new reco::TrackCollection);
00083
00084
00085
00086
00087
00088 if ( tC.empty() ){
00089
00090 e.put(output);
00091 return;
00092 }
00093
00094
00095
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
00105 continue;
00106 }
00107 if (track->normalizedChi2() > maxNormalizedChisq){
00108 selected[i]=0;
00109
00110 continue;
00111 }
00112 if (track->found() < minFound){
00113 selected[i]=0;
00114
00115 continue;
00116 }
00117 if (track->pt() < minPT){
00118 selected[i]=0;
00119
00120 continue;
00121 }
00122 }
00123
00124
00125
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
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
00149 if ((fi>0.66)||(fj>0.66)){
00150 if (fi<fj){
00151 selected[j]=0;
00152
00153 }else{
00154 if (fi>fj){
00155 selected[i]=0;
00156
00157 }else{
00158
00159 if (track->chi2() > track2->chi2()){selected[i]=0;}else{selected[j]=0;}
00160 }
00161 }
00162 }
00163 }
00164 }
00165 }
00166
00167
00168
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
00180 reco::TrackExtraRef theTrackExtraRef=track->extra();
00181 theTrack->setExtra(theTrackExtraRef);
00182 theTrack->setHitPattern((*theTrackExtraRef).recHits());
00183 output->push_back(*theTrack);
00184 delete theTrack;
00185 }
00186 e.put(output);
00187 return;
00188
00189 }
00190
00191 }