CMS 3D CMS Logo

TTClusterAssociator.cc
Go to the documentation of this file.
1 
11 
13 template <>
16  if (iEvent.isRealData())
17  return;
18 
20  iEvent.getByToken(digisimLinkToken_, thePixelDigiSimLinkHandle_);
21 
23 
24  iEvent.getByToken(tpToken_, trackingParticleHandle_);
25 
26  // const TrackerTopology* const tTopo = theTrackerTopology_.product();
27  const TrackerGeometry* const theTrackerGeom = &iSetup.getData(theTrackerGeometryToken_);
28 
31  std::map<std::pair<unsigned int, EncodedEventId>, TrackingParticlePtr> simTrackUniqueToTPMap;
32 
33  if (not trackingParticleHandle_->empty()) {
35  for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle_->size(); tpCnt++) {
37  TrackingParticlePtr tempTPPtr(trackingParticleHandle_, tpCnt);
38 
40  EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId());
41 
43  for (const auto& simTrack : tempTPPtr->g4Tracks()) {
45  simTrackUniqueToTPMap.emplace(std::make_pair(simTrack.trackId(), eventId), tempTPPtr);
46  }
47  }
48  }
49 
51 
52  int ncont1 = 0;
53 
54  for (const auto& iTag : ttClustersTokens_) {
56  auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
57 
59  edm::Handle<TTClusterDetSetVec> TTClusterHandle;
60 
61  iEvent.getByToken(iTag, TTClusterHandle);
62 
64  std::map<TTClusterRef, std::vector<TrackingParticlePtr>> clusterToTrackingParticleVectorMap;
65  std::map<TrackingParticlePtr, std::vector<TTClusterRef>> trackingParticleToClusterVectorMap;
66 
68  for (const auto& gd : theTrackerGeom->dets()) {
69  DetId detid = gd->geographicalId();
70  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
71  continue; // only run on OT
72 
73  if (TTClusterHandle->find(detid) == TTClusterHandle->end())
74  continue;
75 
78 
79  for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) {
81  TTClusterRef tempCluRef = edmNew::makeRefTo(TTClusterHandle, contentIter);
82 
84  if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
85  std::vector<TrackingParticlePtr> tpVector;
86  clusterToTrackingParticleVectorMap.emplace(tempCluRef, tpVector);
87  }
88 
91  if (thePixelDigiSimLinkHandle_->find(detid) == thePixelDigiSimLinkHandle_->end()) {
94 
96  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
97  for (unsigned int i = 0; i < theseHits.size(); i++) {
100  TrackingParticlePtr tempTPPtr;
101  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
102  }
103 
105  continue;
106  }
107 
108  edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle_))[detid];
110 
112  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
113  for (unsigned int i = 0; i < theseHits.size(); i++) {
115  for (iterSimLink = thisDigiSimLink.data.begin(); iterSimLink != thisDigiSimLink.data.end(); iterSimLink++) {
117  if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()))
118  continue;
119 
121  unsigned int curSimTrkId = iterSimLink->SimTrackId();
122  EncodedEventId curSimEvId = iterSimLink->eventId();
123 
125  std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
126 
128  if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
129  TrackingParticlePtr thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second;
130 
132  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
133 
135  if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
136  trackingParticleToClusterVectorMap.end()) {
137  std::vector<TTClusterRef> clusterVector;
138  trackingParticleToClusterVectorMap.emplace(thisTrackingParticle, clusterVector);
139  }
140  trackingParticleToClusterVectorMap.find(thisTrackingParticle)
141  ->second.push_back(tempCluRef);
142  } else {
144 
145  TrackingParticlePtr tempTPPtr;
146  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
147  }
148  }
149  }
150 
152  const std::vector<TrackingParticlePtr>& theseClusterTrackingParticlePtrs =
153  clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
154  bool allOfThemAreNull = true;
155  for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
156  if (theseClusterTrackingParticlePtrs.at(tpi).isNull() == false)
157  allOfThemAreNull = false;
158  }
159 
160  if (allOfThemAreNull) {
162  clusterToTrackingParticleVectorMap.erase(tempCluRef);
163  }
164  }
165  }
166 
169  for (auto& p : trackingParticleToClusterVectorMap) {
171  std::vector<TTClusterRef>& tempVector = p.second;
172 
174  std::sort(tempVector.begin(), tempVector.end());
175  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
176  }
177 
179  associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
180  associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
181 
183  iEvent.put(std::move(associationMapForOutput), ttClustersInputTags_.at(ncont1).instance());
184 
185  ++ncont1;
186 
187  }
188 }
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
EncodedEventId eventId() const
Signal source, crossing number.
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Mandatory methods.
const std::vector< SimTrack > & g4Tracks() const
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:24
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
Definition: DetId.h:17
collection_type data
Definition: DetSet.h:80
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
static constexpr auto TID
def move(src, dest)
Definition: eostools.py:511