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