20 iEvent.getByToken(digisimLinkToken, thePixelDigiSimLinkHandle);
24 iEvent.getByToken(tpToken, TrackingParticleHandle);
27 const TrackerGeometry*
const theTrackerGeom = theTrackerGeometry.product();
32 simTrackUniqueToTPMap.clear();
34 if (!TrackingParticleHandle->empty()) {
36 unsigned int tpCnt = 0;
37 std::vector<TrackingParticle>::const_iterator iterTPart;
38 for (iterTPart = TrackingParticleHandle->begin(); iterTPart != TrackingParticleHandle->end(); ++iterTPart) {
46 std::vector<SimTrack>::const_iterator iterSimTrack;
47 for (iterSimTrack = tempTPPtr->
g4Tracks().begin(); iterSimTrack != tempTPPtr->
g4Tracks().end(); ++iterSimTrack) {
49 std::pair<unsigned int, EncodedEventId> simTrackUniqueId(iterSimTrack->trackId(), eventId);
50 simTrackUniqueToTPMap.insert(std::make_pair(simTrackUniqueId, tempTPPtr));
59 for (
auto iTag = TTClustersTokens.begin(); iTag != TTClustersTokens.end(); iTag++) {
61 auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
66 iEvent.getByToken(*iTag, TTClusterHandle);
70 std::vector<edm::Ptr<TrackingParticle>>>
71 clusterToTrackingParticleVectorMap;
72 std::map<edm::Ptr<TrackingParticle>,
75 trackingParticleToClusterVectorMap;
76 clusterToTrackingParticleVectorMap.clear();
77 trackingParticleToClusterVectorMap.clear();
80 for (
auto gd = theTrackerGeom->
dets().begin(); gd != theTrackerGeom->
dets().end(); gd++) {
81 DetId detid = (*gd)->geographicalId();
85 if (TTClusterHandle->find(detid) == TTClusterHandle->end())
91 for (
auto contentIter =
clusters.begin(); contentIter !=
clusters.end(); ++contentIter) {
97 if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
98 std::vector<edm::Ptr<TrackingParticle>> tpVector;
100 clusterToTrackingParticleVectorMap.insert(std::make_pair(tempCluRef, tpVector));
105 if (thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end()) {
110 std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
111 for (
unsigned int i = 0;
i < theseHits.size();
i++) {
115 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
126 std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
127 for (
unsigned int i = 0;
i < theseHits.size();
i++) {
129 for (iterSimLink = thisDigiSimLink.
data.begin(); iterSimLink != thisDigiSimLink.
data.end(); iterSimLink++) {
131 if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(
i)->channel()))
135 unsigned int curSimTrkId = iterSimLink->SimTrackId();
139 std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
142 if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
146 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
149 if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
150 trackingParticleToClusterVectorMap.end()) {
154 clusterVector.clear();
155 trackingParticleToClusterVectorMap.insert(std::make_pair(thisTrackingParticle, clusterVector));
157 trackingParticleToClusterVectorMap.find(thisTrackingParticle)
158 ->second.push_back(tempCluRef);
163 clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
169 std::vector<edm::Ptr<TrackingParticle>> theseClusterTrackingParticlePtrs =
170 clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
171 bool allOfThemAreNull =
true;
172 for (
unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
173 if (theseClusterTrackingParticlePtrs.at(tpi).isNull() ==
false)
174 allOfThemAreNull =
false;
177 if (allOfThemAreNull) {
179 clusterToTrackingParticleVectorMap.erase(tempCluRef);
186 std::map<edm::Ptr<TrackingParticle>,
187 std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>,
189 for (iterMapToClean = trackingParticleToClusterVectorMap.begin();
190 iterMapToClean != trackingParticleToClusterVectorMap.end();
194 tempVector = iterMapToClean->second;
197 std::sort(tempVector.begin(), tempVector.end());
198 tempVector.erase(
std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
199 iterMapToClean->second = tempVector;
203 associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
204 associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
208 iEvent.put(
std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance());