File indexing completed on 2024-09-07 04:38:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "SimTracker/TrackTriggerAssociation/plugins/TTClusterAssociator.h"
0011
0012
0013 template <>
0014 void TTClusterAssociator<Ref_Phase2TrackerDigi_>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0015
0016 if (iEvent.isRealData())
0017 return;
0018
0019
0020 iEvent.getByToken(digisimLinkToken_, thePixelDigiSimLinkHandle_);
0021
0022
0023
0024 iEvent.getByToken(tpToken_, trackingParticleHandle_);
0025
0026
0027 const TrackerGeometry* const theTrackerGeom = &iSetup.getData(theTrackerGeometryToken_);
0028
0029
0030
0031 std::map<std::pair<unsigned int, EncodedEventId>, TrackingParticlePtr> simTrackUniqueToTPMap;
0032
0033 if (not trackingParticleHandle_->empty()) {
0034
0035 for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle_->size(); tpCnt++) {
0036
0037 TrackingParticlePtr tempTPPtr(trackingParticleHandle_, tpCnt);
0038
0039
0040 EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId());
0041
0042
0043 for (const auto& simTrack : tempTPPtr->g4Tracks()) {
0044
0045 simTrackUniqueToTPMap.emplace(std::make_pair(simTrack.trackId(), eventId), tempTPPtr);
0046 }
0047 }
0048 }
0049
0050
0051
0052 int ncont1 = 0;
0053
0054 for (const auto& iTag : ttClustersTokens_) {
0055
0056 auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
0057
0058
0059 edm::Handle<TTClusterDetSetVec> TTClusterHandle;
0060
0061 iEvent.getByToken(iTag, TTClusterHandle);
0062
0063
0064 std::map<TTClusterRef, std::vector<TrackingParticlePtr>> clusterToTrackingParticleVectorMap;
0065 std::map<TrackingParticlePtr, std::vector<TTClusterRef>> trackingParticleToClusterVectorMap;
0066
0067
0068 for (const auto& gd : theTrackerGeom->dets()) {
0069 DetId detid = gd->geographicalId();
0070 if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
0071 continue;
0072
0073 if (TTClusterHandle->find(detid) == TTClusterHandle->end())
0074 continue;
0075
0076
0077 edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> clusters = (*TTClusterHandle)[detid];
0078
0079 for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) {
0080
0081 TTClusterRef tempCluRef = edmNew::makeRefTo(TTClusterHandle, contentIter);
0082
0083
0084 if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
0085 std::vector<TrackingParticlePtr> tpVector;
0086 clusterToTrackingParticleVectorMap.emplace(tempCluRef, tpVector);
0087 }
0088
0089
0090
0091 if (thePixelDigiSimLinkHandle_->find(detid) == thePixelDigiSimLinkHandle_->end()) {
0092
0093
0094
0095
0096 std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
0097 for (unsigned int i = 0; i < theseHits.size(); i++) {
0098
0099
0100 TrackingParticlePtr tempTPPtr;
0101 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
0102 }
0103
0104
0105 continue;
0106 }
0107
0108 edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle_))[detid];
0109 edm::DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
0110
0111
0112 std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
0113 for (unsigned int i = 0; i < theseHits.size(); i++) {
0114
0115 for (iterSimLink = thisDigiSimLink.data.begin(); iterSimLink != thisDigiSimLink.data.end(); iterSimLink++) {
0116
0117 if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()))
0118 continue;
0119
0120
0121 unsigned int curSimTrkId = iterSimLink->SimTrackId();
0122 EncodedEventId curSimEvId = iterSimLink->eventId();
0123
0124
0125 std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
0126
0127
0128 if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
0129 TrackingParticlePtr thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second;
0130
0131
0132 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
0133
0134
0135 if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
0136 trackingParticleToClusterVectorMap.end()) {
0137 std::vector<TTClusterRef> clusterVector;
0138 trackingParticleToClusterVectorMap.emplace(thisTrackingParticle, clusterVector);
0139 }
0140 trackingParticleToClusterVectorMap.find(thisTrackingParticle)
0141 ->second.push_back(tempCluRef);
0142 } else {
0143
0144
0145 TrackingParticlePtr tempTPPtr;
0146 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
0147 }
0148 }
0149 }
0150
0151
0152 const std::vector<TrackingParticlePtr>& theseClusterTrackingParticlePtrs =
0153 clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
0154 bool allOfThemAreNull = true;
0155 for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
0156 if (theseClusterTrackingParticlePtrs.at(tpi).isNull() == false)
0157 allOfThemAreNull = false;
0158 }
0159
0160 if (allOfThemAreNull) {
0161
0162 clusterToTrackingParticleVectorMap.erase(tempCluRef);
0163 }
0164 }
0165 }
0166
0167
0168
0169 for (auto& p : trackingParticleToClusterVectorMap) {
0170
0171 std::vector<TTClusterRef>& tempVector = p.second;
0172
0173
0174 std::sort(tempVector.begin(), tempVector.end());
0175 tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
0176 }
0177
0178
0179 associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
0180 associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
0181
0182
0183 iEvent.put(std::move(associationMapForOutput), ttClustersInputTags_.at(ncont1).instance());
0184
0185 ++ncont1;
0186
0187 }
0188 }