File indexing completed on 2024-04-06 12:31:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "SimTracker/TrackTriggerAssociation/plugins/TTTrackAssociator.h"
0011
0012
0013 template <>
0014 void TTTrackAssociator<Ref_Phase2TrackerDigi_>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0015
0016 if (iEvent.isRealData())
0017 return;
0018
0019
0020 edm::Handle<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> ttClusterAssociationMapHandle;
0021 iEvent.getByToken(ttClusterTruthToken_, ttClusterAssociationMapHandle);
0022 edm::Handle<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> ttStubAssociationMapHandle;
0023 iEvent.getByToken(ttStubTruthToken_, ttStubAssociationMapHandle);
0024
0025 int ncont1 = 0;
0026
0027
0028 for (const auto& iTag : ttTracksTokens_) {
0029
0030 auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
0031
0032
0033 edm::Handle<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> TTTrackHandle;
0034 iEvent.getByToken(iTag, TTTrackHandle);
0035
0036
0037 std::map<TTTrackPtr, TrackingParticlePtr> trackToTrackingParticleMap;
0038 std::map<TrackingParticlePtr, std::vector<TTTrackPtr>> trackingParticleToTrackVectorMap;
0039
0040
0041
0042 for (unsigned int jTrk = 0; jTrk < TTTrackHandle->size(); jTrk++) {
0043
0044 TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk);
0045
0046
0047 const std::vector<TTStubRef>& theseStubs = tempTrackPtr->getStubRefs();
0048
0049
0050 std::map<const TrackingParticle*, TrackingParticlePtr> auxMap;
0051 int mayCombinUnknown = 0;
0052
0053
0054
0055
0056 for (const TTStubRef& stub : theseStubs) {
0057 for (unsigned int ic = 0; ic < 2; ic++) {
0058 const std::vector<TrackingParticlePtr>& tempTPs =
0059 ttClusterAssociationMapHandle->findTrackingParticlePtrs(stub->clusterRef(ic));
0060 for (const TrackingParticlePtr& testTP : tempTPs)
0061 {
0062 if (testTP.isNull())
0063 continue;
0064
0065
0066 if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) {
0067 std::vector<TTTrackPtr> trackVector;
0068 trackingParticleToTrackVectorMap.emplace(testTP, trackVector);
0069 }
0070 trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr);
0071
0072
0073 if (auxMap.find(testTP.get()) == auxMap.end()) {
0074 auxMap.emplace(testTP.get(), testTP);
0075 }
0076 }
0077 }
0078
0079
0080 if (ttStubAssociationMapHandle->isUnknown(stub))
0081 ++mayCombinUnknown;
0082
0083 }
0084
0085
0086
0087
0088 if (mayCombinUnknown >= 2)
0089 continue;
0090
0091
0092
0093
0094
0095
0096 std::vector<const TrackingParticle*> tpInAllStubs;
0097
0098 for (const auto& auxPair : auxMap) {
0099
0100 const std::vector<TTStubRef>& tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second);
0101
0102
0103 int nnotfound = 0;
0104 for (const TTStubRef& stub : theseStubs) {
0105
0106
0107
0108
0109 if (std::find(tempStubs.begin(), tempStubs.end(), stub) == tempStubs.end()) {
0110 ++nnotfound;
0111 }
0112 }
0113
0114
0115
0116 if (nnotfound > 1)
0117 continue;
0118
0119
0120
0121
0122 tpInAllStubs.push_back(auxPair.first);
0123 }
0124
0125
0126
0127 std::sort(tpInAllStubs.begin(), tpInAllStubs.end());
0128 tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end());
0129 unsigned int nTPs = tpInAllStubs.size();
0130
0131
0132
0133
0134
0135
0136
0137 if (nTPs != 1)
0138 continue;
0139
0140
0141
0142
0143 trackToTrackingParticleMap.emplace(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second);
0144
0145 }
0146
0147
0148
0149 for (auto& p : trackingParticleToTrackVectorMap) {
0150
0151
0152 std::vector<TTTrackPtr>& tempVector = p.second;
0153
0154
0155 std::sort(tempVector.begin(), tempVector.end());
0156 tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
0157 }
0158
0159
0160 edm::RefProd<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> theStubAssoMap(ttStubAssociationMapHandle);
0161
0162
0163 associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap);
0164 associationMapForOutput->setTrackingParticleToTTTracksMap(trackingParticleToTrackVectorMap);
0165 associationMapForOutput->setTTStubAssociationMap(theStubAssoMap);
0166 associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub);
0167
0168
0169 iEvent.put(std::move(associationMapForOutput), ttTracksInputTags_.at(ncont1).instance());
0170
0171 ++ncont1;
0172 }
0173 }