Go to the documentation of this file.00001 #include <iostream>
00002 #include <vector>
00003 #include <memory>
00004 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackPairFinder.h"
00005
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009
00010 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00011 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00012 #include "TrackingTools/TransientTrack/interface/GsfTransientTrack.h"
00013
00014 #include "DataFormats/EgammaTrackReco/interface/TrackCaloClusterAssociation.h"
00015
00016 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00017 #include <TMath.h>
00018 #include <vector>
00019 #include <map>
00020
00021
00022
00023
00024 ConversionTrackPairFinder::ConversionTrackPairFinder( ){
00025
00026 LogDebug("ConversionTrackPairFinder") << " CTOR " << "\n";
00027
00028 }
00029
00030 ConversionTrackPairFinder::~ConversionTrackPairFinder() {
00031
00032 LogDebug("ConversionTrackPairFinder") << " DTOR " << "\n";
00033
00034 }
00035
00036
00037
00038
00039 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr> ConversionTrackPairFinder::run(std::vector<reco::TransientTrack> outInTrk,
00040 const edm::Handle<reco::TrackCollection>& outInTrkHandle,
00041 const edm::Handle<reco::TrackCaloClusterPtrAssociation>& outInTrackSCAssH,
00042 std::vector<reco::TransientTrack> inOutTrk,
00043 const edm::Handle<reco::TrackCollection>& inOutTrkHandle,
00044 const edm::Handle<reco::TrackCaloClusterPtrAssociation>& inOutTrackSCAssH )
00045 {
00046
00047
00048 LogDebug("ConversionTrackPairFinder") << "ConversionTrackPairFinder::run " << "\n";
00049
00050 std::vector<reco::TransientTrack> selectedOutInTk;
00051 std::vector<reco::TransientTrack> selectedInOutTk;
00052 std::vector<reco::TransientTrack> allSelectedTk;
00053 std::map<reco::TransientTrack, reco::CaloClusterPtr> scTrkAssocMap;
00054 std::multimap<int,reco::TransientTrack,std::greater<int> > auxMap;
00055
00056 bool oneLeg=false;
00057 bool noTrack=false;
00058
00059
00060
00061 int iTrk=0;
00062 for( std::vector<reco::TransientTrack>::iterator iTk = outInTrk.begin(); iTk != outInTrk.end(); iTk++) {
00063 edm::Ref<reco::TrackCollection> trackRef(outInTrkHandle, iTrk );
00064 iTrk++;
00065
00066 if ( iTk->numberOfValidHits() <3 || iTk->normalizedChi2() > 5000 ) continue;
00067 if ( fabs(iTk->impactPointState().globalPosition().x()) > 110 ||
00068 fabs(iTk->impactPointState().globalPosition().y()) > 110 ||
00069 fabs(iTk->impactPointState().globalPosition().z()) > 280 ) continue;
00070
00071
00072 const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
00073 reco::TrackRef myTkRef= ttt->persistentTrackRef();
00074
00075
00076
00077 const reco::CaloClusterPtr aClus = (*outInTrackSCAssH)[trackRef];
00078
00079
00080
00081
00082 int nHits=iTk->recHitsSize();
00083 scTrkAssocMap[*iTk]= aClus;
00084 auxMap.insert(std::pair<int,reco::TransientTrack >(nHits,(*iTk)) );
00085 selectedOutInTk.push_back(*iTk);
00086 allSelectedTk.push_back(*iTk);
00087
00088
00089
00090 }
00091
00092
00093 iTrk=0;
00094 for( std::vector<reco::TransientTrack>::iterator iTk = inOutTrk.begin(); iTk != inOutTrk.end(); iTk++) {
00095 edm::Ref<reco::TrackCollection> trackRef(inOutTrkHandle, iTrk );
00096 iTrk++;
00097
00098 if ( iTk->numberOfValidHits() <3 || iTk->normalizedChi2() >5000 ) continue;
00099 if ( fabs(iTk->impactPointState().globalPosition().x()) > 110 ||
00100 fabs(iTk->impactPointState().globalPosition().y()) > 110 ||
00101 fabs(iTk->impactPointState().globalPosition().z()) > 280 ) continue;
00102
00103
00104 const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
00105 reco::TrackRef myTkRef= ttt->persistentTrackRef();
00106
00107
00108
00109 const reco::CaloClusterPtr aClus = (*inOutTrackSCAssH)[trackRef];
00110
00111
00112
00113
00114 scTrkAssocMap[*iTk]= aClus;
00115 int nHits=iTk->recHitsSize();
00116 auxMap.insert(std::pair<int,reco::TransientTrack >(nHits,(*iTk)) );
00117 selectedInOutTk.push_back(*iTk);
00118 allSelectedTk.push_back(*iTk);
00119
00120
00121
00122 }
00123
00124
00125
00126
00127
00128 if(selectedOutInTk.size() > 0)
00129 std::stable_sort(selectedOutInTk.begin(), selectedOutInTk.end(), ByNumOfHits());
00130 if(selectedInOutTk.size() > 0)
00131 std::stable_sort(selectedInOutTk.begin(), selectedInOutTk.end(), ByNumOfHits());
00132 if(allSelectedTk.size() > 0)
00133 std::stable_sort(allSelectedTk.begin(), allSelectedTk.end(), ByNumOfHits());
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 std::vector<reco::TransientTrack > thePair(2);
00151 std::vector<std::vector<reco::TransientTrack> > allPairs;
00152 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr > allPairSCAss;
00153 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr > allPairOrdInPtSCAss;
00154
00155 std::map<reco::TransientTrack, reco::CaloClusterPtr>::const_iterator iMap1;
00156 std::map<reco::TransientTrack, reco::CaloClusterPtr>::const_iterator iMap2;
00157
00158 for( iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
00159
00160
00161 }
00162
00163
00164 std::multimap<int, reco::TransientTrack>::const_iterator iAux;
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 if ( scTrkAssocMap.size() > 2 ){
00175
00176
00177 for( iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
00178 for( iMap2 = iMap1; iMap2 != scTrkAssocMap.end(); ++iMap2) {
00179
00180
00181 if ( (iMap1->second) != (iMap2->second) ) continue;
00182
00183 if ( ((iMap1->first)).charge() * ((iMap2->first)).charge() < 0 ) {
00184
00185
00186
00187
00188
00189
00190
00191 thePair.clear();
00192 thePair.push_back( iMap1->first );
00193 thePair.push_back( iMap2->first );
00194 allPairs.push_back ( thePair );
00195 allPairSCAss[thePair]= iMap1->second;
00196
00197 }
00198 }
00199 }
00200
00201
00202
00203 if ( allPairSCAss.size() == 0) {
00204
00205
00206 for( iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
00207
00208 thePair.clear();
00209 thePair.push_back(iMap1->first);
00210 allPairs.push_back ( thePair );
00211 allPairSCAss[thePair]= iMap1->second;
00212
00213 }
00214
00215 }
00216
00217
00218
00219
00220
00221 } else if ( (scTrkAssocMap.size() ==2) ) {
00222
00223 iMap1=scTrkAssocMap.begin();
00224 iMap2=iMap1;
00225 iMap2++;
00226 if ( (iMap1->second) == (iMap2->second) ) {
00227 if ( (iMap1->first).charge() * (iMap2->first).charge() < 0 ) {
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 thePair.clear();
00240 thePair.push_back( iMap1->first );
00241 thePair.push_back( iMap2->first );
00242 allPairs.push_back ( thePair );
00243
00244 allPairSCAss[thePair]= iMap1->second;
00245
00246
00247 } else {
00248
00249 if ( ((iMap1->first)).recHitsSize() > ((iMap2->first)).recHitsSize() ) {
00250 thePair.clear();
00251 thePair.push_back(iMap1->first);
00252 allPairs.push_back ( thePair );
00253 allPairSCAss[thePair]= iMap1->second;
00254 } else {
00255 thePair.clear();
00256 thePair.push_back(iMap2->first);
00257 allPairs.push_back ( thePair );
00258 allPairSCAss[thePair]= iMap2->second;
00259 }
00260 }
00261
00262 }
00263
00264 } else if (scTrkAssocMap.size() ==1 ) {
00265
00266 oneLeg=true;
00267 } else {
00268 noTrack=true;
00269 }
00270
00271
00272 if ( oneLeg ) {
00273 thePair.clear();
00274
00275
00276
00277 iMap1=scTrkAssocMap.begin();
00278
00279
00280
00281 thePair.push_back(iMap1->first);
00282 allPairs.push_back ( thePair );
00283 allPairSCAss[thePair]= iMap1->second;
00284
00285
00286 }
00287
00288 if ( noTrack) {
00289
00290 thePair.clear();
00291 allPairSCAss.clear();
00292 }
00293
00294
00295
00297 for( iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
00298
00299 int nFound=0;
00300 for ( std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair= allPairSCAss.begin(); iPair!= allPairSCAss.end(); ++iPair ) {
00301 if ( (iMap1->second) == (iPair->second) ) nFound++;
00302 }
00303
00304 if ( nFound == 0) {
00305
00306 int iList=0;
00307 for( iAux = auxMap.begin(); iAux!= auxMap.end(); ++iAux) {
00308 if ( (iMap1->first) == (iAux->second) && iList==0 ) {
00309 thePair.clear();
00310 thePair.push_back(iAux->second);
00311 allPairSCAss[thePair]= iMap1->second;
00312
00313 }
00314
00315 iList++;
00316 }
00317 }
00318
00319 }
00320
00321
00322
00323
00324
00325 for ( std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair= allPairSCAss.begin(); iPair!= allPairSCAss.end(); ++iPair ) {
00326 thePair.clear();
00327 if ( (iPair->first).size() ==2 ) {
00328 if ( sqrt((iPair->first)[0].track().innerMomentum().perp2()) > sqrt((iPair->first)[1].track().innerMomentum().perp2()) ) {
00329 thePair.push_back((iPair->first)[0]);
00330 thePair.push_back((iPair->first)[1]);
00331 } else {
00332 thePair.push_back((iPair->first)[1]);
00333 thePair.push_back((iPair->first)[0]);
00334 }
00335 } else {
00336 thePair.push_back((iPair->first)[0]);
00337 }
00338
00339 allPairOrdInPtSCAss[thePair]=iPair->second;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 return allPairOrdInPtSCAss;
00356
00357
00358 }
00359
00360
00361
00362
00363
00364
00365
00366