CMS 3D CMS Logo

TTTrackAssociator.cc
Go to the documentation of this file.
1 
11 
13 template <>
16  if (iEvent.isRealData())
17  return;
18 
21  iEvent.getByToken(ttClusterTruthToken_, ttClusterAssociationMapHandle);
23  iEvent.getByToken(ttStubTruthToken_, ttStubAssociationMapHandle);
24 
25  int ncont1 = 0;
26 
28  for (const auto& iTag : ttTracksTokens_) {
30  auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
31 
34  iEvent.getByToken(iTag, TTTrackHandle);
35 
37  std::map<TTTrackPtr, TrackingParticlePtr> trackToTrackingParticleMap;
38  std::map<TrackingParticlePtr, std::vector<TTTrackPtr>> trackingParticleToTrackVectorMap;
39 
40  // Start the loop on tracks
41 
42  for (unsigned int jTrk = 0; jTrk < TTTrackHandle->size(); jTrk++) {
44  TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk);
45 
47  const std::vector<TTStubRef>& theseStubs = tempTrackPtr->getStubRefs();
48 
50  std::map<const TrackingParticle*, TrackingParticlePtr> auxMap;
51  int mayCombinUnknown = 0;
52 
56  for (const TTStubRef& stub : theseStubs) {
57  for (unsigned int ic = 0; ic < 2; ic++) {
58  const std::vector<TrackingParticlePtr>& tempTPs =
59  ttClusterAssociationMapHandle->findTrackingParticlePtrs(stub->clusterRef(ic));
60  for (const TrackingParticlePtr& testTP : tempTPs) // List of TPs linked to stub clusters
61  {
62  if (testTP.isNull()) // No TP linked to this cluster
63  continue;
64 
66  if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) {
67  std::vector<TTTrackPtr> trackVector;
68  trackingParticleToTrackVectorMap.emplace(testTP, trackVector);
69  }
70  trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr);
71 
73  if (auxMap.find(testTP.get()) == auxMap.end()) {
74  auxMap.emplace(testTP.get(), testTP);
75  }
76  }
77  }
78 
80  if (ttStubAssociationMapHandle->isUnknown(stub))
81  ++mayCombinUnknown;
82 
83  }
84 
88  if (mayCombinUnknown >= 2)
89  continue;
90 
95 
96  std::vector<const TrackingParticle*> tpInAllStubs;
97 
98  for (const auto& auxPair : auxMap) {
100  const std::vector<TTStubRef>& tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second);
101 
102  // Count stubs on track that are not related to this TP
103  int nnotfound = 0;
104  for (const TTStubRef& stub : theseStubs) {
109  if (std::find(tempStubs.begin(), tempStubs.end(), stub) == tempStubs.end()) {
110  ++nnotfound;
111  }
112  }
113 
116  if (nnotfound > 1)
117  continue;
118 
122  tpInAllStubs.push_back(auxPair.first);
123  }
124 
127  std::sort(tpInAllStubs.begin(), tpInAllStubs.end());
128  tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end());
129  unsigned int nTPs = tpInAllStubs.size();
130 
137  if (nTPs != 1)
138  continue;
139 
143  trackToTrackingParticleMap.emplace(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second);
144 
145  }
146 
149  for (auto& p : trackingParticleToTrackVectorMap) {
152  std::vector<TTTrackPtr>& tempVector = p.second;
153 
155  std::sort(tempVector.begin(), tempVector.end());
156  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
157  }
158 
160  edm::RefProd<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> theStubAssoMap(ttStubAssociationMapHandle);
161 
163  associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap);
164  associationMapForOutput->setTrackingParticleToTTTracksMap(trackingParticleToTrackVectorMap);
165  associationMapForOutput->setTTStubAssociationMap(theStubAssoMap);
166  associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub);
167 
169  iEvent.put(std::move(associationMapForOutput), ttTracksInputTags_.at(ncont1).instance());
170 
171  ++ncont1;
172  }
173 }
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Mandatory methods.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:24
def move(src, dest)
Definition: eostools.py:511