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/TrackListMerger.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 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032
00033 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00034 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00035 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00036 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00037
00038 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00039 #include "DataFormats/TrackReco/interface/Track.h"
00040 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00041 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00042 #include "DataFormats/TrackReco/src/classes.h"
00043
00044 namespace cms
00045 {
00046
00047 TrackListMerger::TrackListMerger(edm::ParameterSet const& conf) :
00048 conf_(conf)
00049 {
00050 produces<reco::TrackCollection>();
00051
00052 }
00053
00054
00055
00056 TrackListMerger::~TrackListMerger() { }
00057
00058
00059 void TrackListMerger::produce(edm::Event& e, const edm::EventSetup& es)
00060 {
00061
00062 std::string trackProducer1 = conf_.getParameter<std::string>("TrackProducer1");
00063 std::string trackProducer2 = conf_.getParameter<std::string>("TrackProducer2");
00064
00065 double maxNormalizedChisq = conf_.getParameter<double>("MaxNormalizedChisq");
00066 double minPT = conf_.getParameter<double>("MinPT");
00067 unsigned int minFound = (unsigned int)conf_.getParameter<int>("MinFound");
00068 double epsilon = conf_.getParameter<double>("Epsilon");
00069 double shareFrac = conf_.getParameter<double>("ShareFrac");
00070
00071
00072
00073
00074 edm::ESHandle<TrackerGeometry> theG;
00075 es.get<TrackerDigiGeometryRecord>().get(theG);
00076
00077
00078
00079
00080
00081
00082
00083
00084 const reco::TrackCollection *TC1 = 0;
00085 try {
00086 edm::Handle<reco::TrackCollection> trackCollection1;
00087 e.getByLabel(trackProducer1, trackCollection1);
00088 TC1 = trackCollection1.product();
00089
00090 }
00091 catch (edm::Exception const& x) {
00092 if ( x.categoryCode() == edm::errors::ProductNotFound ) {
00093 if ( x.history().size() == 1 ) {
00094 static const reco::TrackCollection s_empty;
00095 TC1 = &s_empty;
00096 edm::LogWarning("TrackListMerger") << "1st TrackCollection " << trackProducer1 << " not found; will only clean 2nd TrackCollection " << trackProducer2 ;
00097 }
00098 }
00099 }
00100 const reco::TrackCollection tC1 = *TC1;
00101
00102 const reco::TrackCollection *TC2 = 0;
00103 try {
00104 edm::Handle<reco::TrackCollection> trackCollection2;
00105 e.getByLabel(trackProducer2, trackCollection2);
00106 TC2 = trackCollection2.product();
00107
00108 }
00109 catch (edm::Exception const& x) {
00110 if ( x.categoryCode() == edm::errors::ProductNotFound ) {
00111 if ( x.history().size() == 1 ) {
00112 static const reco::TrackCollection s_empty;
00113 TC2 = &s_empty;
00114 edm::LogWarning("TrackListMerger") << "2nd TrackCollection " << trackProducer2 << " not found; will only clean 1st TrackCollection " << trackProducer1 ;
00115 }
00116 }
00117 }
00118 const reco::TrackCollection tC2 = *TC2;
00119
00120
00121 std::auto_ptr<reco::TrackCollection> output(new reco::TrackCollection);
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 int i;
00137
00138 std::vector<int> selected1; for (unsigned int i=0; i<tC1.size(); ++i){selected1.push_back(1);}
00139
00140 if ( 0<tC1.size() ){
00141 i=-1;
00142 for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
00143 i++;
00144 if ((short unsigned)track->ndof() < 1){
00145 selected1[i]=0;
00146
00147 continue;
00148 }
00149 if (track->normalizedChi2() > maxNormalizedChisq){
00150 selected1[i]=0;
00151
00152 continue;
00153 }
00154 if (track->found() < minFound){
00155 selected1[i]=0;
00156
00157 continue;
00158 }
00159 if (track->pt() < minPT){
00160 selected1[i]=0;
00161
00162 continue;
00163 }
00164 }
00165 }
00166
00167
00168 std::vector<int> selected2; for (unsigned int i=0; i<tC2.size(); ++i){selected2.push_back(1);}
00169
00170 if ( 0<tC2.size() ){
00171 i=-1;
00172 for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
00173 i++;
00174 if ((short unsigned)track->ndof() < 1){
00175 selected2[i]=0;
00176
00177 continue;
00178 }
00179 if (track->normalizedChi2() > maxNormalizedChisq){
00180 selected2[i]=0;
00181
00182 continue;
00183 }
00184 if (track->found() < minFound){
00185 selected2[i]=0;
00186
00187 continue;
00188 }
00189 if (track->pt() < minPT){
00190 selected2[i]=0;
00191
00192 continue;
00193 }
00194 }
00195 }
00196
00197
00198
00199
00200 if ( 1<tC1.size() ){
00201 i=-1;
00202 for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
00203 i++;
00204
00205 if (!selected1[i])continue;
00206 int j=-1;
00207 for (reco::TrackCollection::const_iterator track2=tC1.begin(); track2!=tC1.end(); track2++){
00208 j++;
00209 if ((j<=i)||(!selected1[j])||(!selected1[i]))continue;
00210 int noverlap=0;
00211 for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
00212 if ((*it)->isValid()){
00213 for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
00214 if ((*jt)->isValid()){
00215 if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
00216 }
00217 }
00218 }
00219 }
00220 float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
00221
00222 if ((fi>shareFrac)||(fj>shareFrac)){
00223 if (fi<fj){
00224 selected1[j]=0;
00225
00226 }else{
00227 if (fi>fj){
00228 selected1[i]=0;
00229
00230 }else{
00231
00232 if (track->normalizedChi2() > track2->normalizedChi2()){selected1[i]=0;}else{selected1[j]=0;}
00233 }
00234 }
00235 }
00236 }
00237 }
00238 }
00239
00240
00241
00242
00243 if ( 1<tC2.size() ){
00244 int i=-1;
00245 for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
00246 i++;
00247
00248 if (!selected2[i])continue;
00249 int j=-1;
00250 for (reco::TrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); track2++){
00251 j++;
00252 if ((j<=i)||(!selected2[j])||(!selected2[i]))continue;
00253 int noverlap=0;
00254 for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
00255 if ((*it)->isValid()){
00256 for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
00257 if ((*jt)->isValid()){
00258 if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
00259 }
00260 }
00261 }
00262 }
00263 float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
00264
00265 if ((fi>shareFrac)||(fj>shareFrac)){
00266 if (fi<fj){
00267 selected2[j]=0;
00268
00269 }else{
00270 if (fi>fj){
00271 selected2[i]=0;
00272
00273 }else{
00274
00275 if (track->normalizedChi2() > track2->normalizedChi2()){selected2[i]=0;}else{selected2[j]=0;}
00276 }
00277 }
00278 }
00279 }
00280 }
00281 }
00282
00283
00284
00285
00286 if ( (0<tC1.size())&&(0<tC2.size()) ){
00287 i=-1;
00288 for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
00289 i++;
00290
00291 if (!selected1[i])continue;
00292 int j=-1;
00293 for (reco::TrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); track2++){
00294 j++;
00295 if ((!selected2[j])||(!selected1[i]))continue;
00296 int noverlap=0;
00297 for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
00298 if ((*it)->isValid()){
00299 for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
00300 if ((*jt)->isValid()){
00301 float delta = fabs ( (*it)->localPosition().x()-(*jt)->localPosition().x() );
00302 if (((*it)->geographicalId()==(*jt)->geographicalId())&&(delta<epsilon))noverlap++;
00303 }
00304 }
00305 }
00306 }
00307 float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
00308
00309 if ((fi>shareFrac)||(fj>shareFrac)){
00310 if (fi<fj){
00311 selected2[j]=0;
00312
00313 }else{
00314 if (fi>fj){
00315 selected1[i]=0;
00316
00317 }else{
00318
00319 if (track->normalizedChi2() > track2->normalizedChi2()){selected1[i]=0;}else{selected2[j]=0;}
00320 }
00321 }
00322 }
00323 }
00324 }
00325 }
00326
00327
00328
00329
00330 if ( 0<tC1.size() ){
00331 i=-1;
00332 for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
00333 i++; if (!selected1[i])continue;
00334 reco::Track * theTrack = new reco::Track(track->chi2(),
00335 (short unsigned)track->ndof(),
00336 track->innerPosition(),
00337 track->innerMomentum(),
00338 track->charge(),
00339 track->innerStateCovariance());
00340
00341 reco::TrackExtraRef theTrackExtraRef=track->extra();
00342 theTrack->setExtra(theTrackExtraRef);
00343 theTrack->setHitPattern((*theTrackExtraRef).recHits());
00344 output->push_back(*theTrack);
00345 delete theTrack;
00346 }
00347 }
00348 if ( 0<tC2.size() ){
00349 i=-1;
00350 for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
00351 i++; if (!selected2[i])continue;
00352 reco::Track * theTrack = new reco::Track(track->chi2(),
00353 (short unsigned)track->ndof(),
00354 track->innerPosition(),
00355 track->innerMomentum(),
00356 track->charge(),
00357 track->innerStateCovariance());
00358
00359 reco::TrackExtraRef theTrackExtraRef=track->extra();
00360 theTrack->setExtra(theTrackExtraRef);
00361 theTrack->setHitPattern((*theTrackExtraRef).recHits());
00362 output->push_back(*theTrack);
00363 delete theTrack;
00364 }
00365 }
00366
00367
00368 e.put(output);
00369 return;
00370
00371 }
00372
00373 }