File indexing completed on 2024-04-06 12:24:57
0001 #include <iostream>
0002 #include <vector>
0003 #include <memory>
0004 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackPairFinder.h"
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007
0008
0009
0010 #include <vector>
0011 #include <map>
0012
0013
0014
0015 ConversionTrackPairFinder::ConversionTrackPairFinder() {
0016 LogDebug("ConversionTrackPairFinder") << " CTOR "
0017 << "\n";
0018 }
0019
0020 ConversionTrackPairFinder::~ConversionTrackPairFinder() {
0021 LogDebug("ConversionTrackPairFinder") << " DTOR "
0022 << "\n";
0023 }
0024
0025 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors>
0026 ConversionTrackPairFinder::run(const std::vector<reco::TransientTrack>& outInTrk,
0027 const edm::Handle<reco::TrackCollection>& outInTrkHandle,
0028 const edm::Handle<reco::TrackCaloClusterPtrAssociation>& outInTrackSCAssH,
0029 const std::vector<reco::TransientTrack>& _inOutTrk,
0030 const edm::Handle<reco::TrackCollection>& inOutTrkHandle,
0031 const edm::Handle<reco::TrackCaloClusterPtrAssociation>& inOutTrackSCAssH) {
0032 std::vector<reco::TransientTrack> inOutTrk = _inOutTrk;
0033
0034 LogDebug("ConversionTrackPairFinder") << "ConversionTrackPairFinder::run "
0035 << "\n";
0036
0037 std::vector<reco::TransientTrack> selectedOutInTk;
0038 std::vector<reco::TransientTrack> selectedInOutTk;
0039 std::vector<reco::TransientTrack> allSelectedTk;
0040 std::map<reco::TransientTrack, reco::CaloClusterPtr, CompareTwoTracks> scTrkAssocMap;
0041 std::multimap<int, reco::TransientTrack, std::greater<int> > auxMap;
0042
0043 bool oneLeg = false;
0044 bool noTrack = false;
0045
0046 int iTrk = 0;
0047 for (std::vector<reco::TransientTrack>::const_iterator iTk = outInTrk.begin(); iTk != outInTrk.end(); iTk++) {
0048 edm::Ref<reco::TrackCollection> trackRef(outInTrkHandle, iTrk);
0049 iTrk++;
0050
0051 if (iTk->numberOfValidHits() < 3 || iTk->normalizedChi2() > 5000)
0052 continue;
0053 if (fabs(iTk->impactPointState().globalPosition().x()) > 110 ||
0054 fabs(iTk->impactPointState().globalPosition().y()) > 110 ||
0055 fabs(iTk->impactPointState().globalPosition().z()) > 280)
0056 continue;
0057
0058
0059 const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
0060 reco::TrackRef myTkRef = ttt->persistentTrackRef();
0061
0062
0063
0064 const reco::CaloClusterPtr aClus = (*outInTrackSCAssH)[trackRef];
0065
0066
0067
0068
0069 int nHits = iTk->recHitsSize();
0070 scTrkAssocMap[*iTk] = aClus;
0071 auxMap.insert(std::pair<int, reco::TransientTrack>(nHits, (*iTk)));
0072 selectedOutInTk.push_back(*iTk);
0073 allSelectedTk.push_back(*iTk);
0074 }
0075
0076 iTrk = 0;
0077 for (std::vector<reco::TransientTrack>::const_iterator iTk = inOutTrk.begin(); iTk != inOutTrk.end(); iTk++) {
0078 edm::Ref<reco::TrackCollection> trackRef(inOutTrkHandle, iTrk);
0079 iTrk++;
0080
0081 if (iTk->numberOfValidHits() < 3 || iTk->normalizedChi2() > 5000)
0082 continue;
0083 if (fabs(iTk->impactPointState().globalPosition().x()) > 110 ||
0084 fabs(iTk->impactPointState().globalPosition().y()) > 110 ||
0085 fabs(iTk->impactPointState().globalPosition().z()) > 280)
0086 continue;
0087
0088
0089 const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
0090 reco::TrackRef myTkRef = ttt->persistentTrackRef();
0091
0092
0093
0094 const reco::CaloClusterPtr aClus = (*inOutTrackSCAssH)[trackRef];
0095
0096
0097
0098
0099 scTrkAssocMap[*iTk] = aClus;
0100 int nHits = iTk->recHitsSize();
0101 auxMap.insert(std::pair<int, reco::TransientTrack>(nHits, (*iTk)));
0102 selectedInOutTk.push_back(*iTk);
0103 allSelectedTk.push_back(*iTk);
0104 }
0105
0106
0107
0108
0109 if (!selectedOutInTk.empty())
0110 std::stable_sort(selectedOutInTk.begin(), selectedOutInTk.end(), ByNumOfHits());
0111 if (!selectedInOutTk.empty())
0112 std::stable_sort(selectedInOutTk.begin(), selectedInOutTk.end(), ByNumOfHits());
0113 if (!allSelectedTk.empty())
0114 std::stable_sort(allSelectedTk.begin(), allSelectedTk.end(), ByNumOfHits());
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 std::vector<reco::TransientTrack> thePair(2);
0127 std::vector<std::vector<reco::TransientTrack> > allPairs;
0128
0129 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors> allPairSCAss;
0130 std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors> allPairOrdInPtSCAss;
0131 std::map<reco::TransientTrack, reco::CaloClusterPtr>::const_iterator iMap1;
0132 std::map<reco::TransientTrack, reco::CaloClusterPtr>::const_iterator iMap2;
0133
0134 for (iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
0135
0136 }
0137
0138 std::multimap<int, reco::TransientTrack>::const_iterator iAux;
0139
0140
0141
0142
0143
0144
0145
0146
0147 if (scTrkAssocMap.size() > 2) {
0148 for (iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
0149 for (iMap2 = iMap1; iMap2 != scTrkAssocMap.end(); ++iMap2) {
0150
0151
0152 if ((iMap1->second) != (iMap2->second))
0153 continue;
0154
0155 if (((iMap1->first)).charge() * ((iMap2->first)).charge() < 0) {
0156
0157
0158
0159
0160 thePair.clear();
0161 thePair.push_back(iMap1->first);
0162 thePair.push_back(iMap2->first);
0163 allPairs.push_back(thePair);
0164 allPairSCAss[thePair] = iMap1->second;
0165 }
0166 }
0167 }
0168
0169
0170
0171 if (allPairSCAss.empty()) {
0172
0173
0174 for (iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
0175 thePair.clear();
0176 thePair.push_back(iMap1->first);
0177 allPairs.push_back(thePair);
0178 allPairSCAss[thePair] = iMap1->second;
0179 }
0180 }
0181
0182 } else if ((scTrkAssocMap.size() == 2)) {
0183 iMap1 = scTrkAssocMap.begin();
0184 iMap2 = iMap1;
0185 iMap2++;
0186 if ((iMap1->second) == (iMap2->second)) {
0187 if ((iMap1->first).charge() * (iMap2->first).charge() < 0) {
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 thePair.clear();
0199 thePair.push_back(iMap1->first);
0200 thePair.push_back(iMap2->first);
0201 allPairs.push_back(thePair);
0202
0203 allPairSCAss[thePair] = iMap1->second;
0204
0205 } else {
0206
0207 if (((iMap1->first)).recHitsSize() > ((iMap2->first)).recHitsSize()) {
0208 thePair.clear();
0209 thePair.push_back(iMap1->first);
0210 allPairs.push_back(thePair);
0211 allPairSCAss[thePair] = iMap1->second;
0212 } else {
0213 thePair.clear();
0214 thePair.push_back(iMap2->first);
0215 allPairs.push_back(thePair);
0216 allPairSCAss[thePair] = iMap2->second;
0217 }
0218 }
0219 }
0220
0221 } else if (scTrkAssocMap.size() == 1) {
0222
0223 oneLeg = true;
0224 } else {
0225 noTrack = true;
0226 }
0227
0228 if (oneLeg) {
0229 thePair.clear();
0230
0231
0232 iMap1 = scTrkAssocMap.begin();
0233
0234
0235
0236 thePair.push_back(iMap1->first);
0237 allPairs.push_back(thePair);
0238 allPairSCAss[thePair] = iMap1->second;
0239
0240
0241 }
0242
0243 if (noTrack) {
0244
0245 thePair.clear();
0246 allPairSCAss.clear();
0247 }
0248
0249
0250 for (iMap1 = scTrkAssocMap.begin(); iMap1 != scTrkAssocMap.end(); ++iMap1) {
0251 int nFound = 0;
0252 for (std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair = allPairSCAss.begin();
0253 iPair != allPairSCAss.end();
0254 ++iPair) {
0255 if ((iMap1->second) == (iPair->second))
0256 nFound++;
0257 }
0258
0259 if (nFound == 0) {
0260
0261 int iList = 0;
0262 for (iAux = auxMap.begin(); iAux != auxMap.end(); ++iAux) {
0263 if ((iMap1->first) == (iAux->second) && iList == 0) {
0264 thePair.clear();
0265 thePair.push_back(iAux->second);
0266 allPairSCAss[thePair] = iMap1->second;
0267 }
0268
0269 iList++;
0270 }
0271 }
0272 }
0273
0274
0275 for (std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair = allPairSCAss.begin();
0276 iPair != allPairSCAss.end();
0277 ++iPair) {
0278 thePair.clear();
0279 if ((iPair->first).size() == 2) {
0280 if (sqrt((iPair->first)[0].track().innerMomentum().perp2()) >
0281 sqrt((iPair->first)[1].track().innerMomentum().perp2())) {
0282 thePair.push_back((iPair->first)[0]);
0283 thePair.push_back((iPair->first)[1]);
0284 } else {
0285 thePair.push_back((iPair->first)[1]);
0286 thePair.push_back((iPair->first)[0]);
0287 }
0288 } else {
0289 thePair.push_back((iPair->first)[0]);
0290 }
0291
0292 allPairOrdInPtSCAss[thePair] = iPair->second;
0293 }
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 return allPairOrdInPtSCAss;
0306 }