CMS 3D CMS Logo

TrackerHitAssociator.cc
Go to the documentation of this file.
1 // File: TrackerHitAssociator.cc
2 
3 #include <memory>
4 #include <string>
5 #include <vector>
6 
8 
10 
11 //--- for Geometry:
16 
18 
19 //for accumulate
20 #include <numeric>
21 #include <iostream>
22 
23 using namespace std;
24 using namespace edm;
25 
26 //
27 // Constructor for Config helper class, using default parameters
28 //
30  : doPixel_(true), doStrip_(true), useOTph2_(false), doTrackAssoc_(false), assocHitbySimTrack_(false) {
31  if (doStrip_) {
32  if (useOTph2_)
33  ph2OTrToken_ = iC.consumes<edm::DetSetVector<PixelDigiSimLink> >(edm::InputTag("simSiPixelDigis", "Tracker"));
34  else
35  stripToken_ = iC.consumes<edm::DetSetVector<StripDigiSimLink> >(edm::InputTag("simSiStripDigis"));
36  }
37  if (doPixel_) {
38  if (useOTph2_)
39  pixelToken_ = iC.consumes<edm::DetSetVector<PixelDigiSimLink> >(edm::InputTag("simSiPixelDigis", "Pixel"));
40  else
41  pixelToken_ = iC.consumes<edm::DetSetVector<PixelDigiSimLink> >(edm::InputTag("simSiPixelDigis"));
42  }
43  if (!doTrackAssoc_) {
44  std::vector<std::string> trackerContainers;
45  trackerContainers.reserve(12);
46  trackerContainers.emplace_back("g4SimHitsTrackerHitsTIBLowTof");
47  trackerContainers.emplace_back("g4SimHitsTrackerHitsTIBHighTof");
48  trackerContainers.emplace_back("g4SimHitsTrackerHitsTIDLowTof");
49  trackerContainers.emplace_back("g4SimHitsTrackerHitsTIDHighTof");
50  trackerContainers.emplace_back("g4SimHitsTrackerHitsTOBLowTof");
51  trackerContainers.emplace_back("g4SimHitsTrackerHitsTOBHighTof");
52  trackerContainers.emplace_back("g4SimHitsTrackerHitsTECLowTof");
53  trackerContainers.emplace_back("g4SimHitsTrackerHitsTECHighTof");
54  trackerContainers.emplace_back("g4SimHitsTrackerHitsPixelBarrelLowTof");
55  trackerContainers.emplace_back("g4SimHitsTrackerHitsPixelBarrelHighTof");
56  trackerContainers.emplace_back("g4SimHitsTrackerHitsPixelEndcapLowTof");
57  trackerContainers.emplace_back("g4SimHitsTrackerHitsPixelEndcapHighTof");
58  cfTokens_.reserve(trackerContainers.size());
59  simHitTokens_.reserve(trackerContainers.size());
60  for (auto const& trackerContainer : trackerContainers) {
61  cfTokens_.push_back(iC.consumes<CrossingFrame<PSimHit> >(edm::InputTag("mix", trackerContainer)));
62  simHitTokens_.push_back(iC.consumes<std::vector<PSimHit> >(edm::InputTag("g4SimHits", trackerContainer)));
63  }
64  }
65 }
66 
67 //
68 // Constructor for Config helper class, using configured parameters
69 //
71  : doPixel_(conf.getParameter<bool>("associatePixel")),
72  doStrip_(conf.getParameter<bool>("associateStrip")),
73  useOTph2_(conf.existsAs<bool>("usePhase2Tracker") ? conf.getParameter<bool>("usePhase2Tracker") : false),
74  //
75  doTrackAssoc_(conf.getParameter<bool>("associateRecoTracks")),
77  conf.existsAs<bool>("associateHitbySimTrack") ? conf.getParameter<bool>("associateHitbySimTrack") : false) {
78  if (doStrip_) {
79  if (useOTph2_)
81  conf.getParameter<edm::InputTag>("phase2TrackerSimLinkSrc"));
82  else
83  stripToken_ =
84  iC.consumes<edm::DetSetVector<StripDigiSimLink> >(conf.getParameter<edm::InputTag>("stripSimLinkSrc"));
85  }
86  if (doPixel_)
87  pixelToken_ =
88  iC.consumes<edm::DetSetVector<PixelDigiSimLink> >(conf.getParameter<edm::InputTag>("pixelSimLinkSrc"));
89  if (!doTrackAssoc_) {
90  std::vector<std::string> trackerContainers(conf.getParameter<std::vector<std::string> >("ROUList"));
91  cfTokens_.reserve(trackerContainers.size());
92  simHitTokens_.reserve(trackerContainers.size());
93  for (auto const& trackerContainer : trackerContainers) {
94  cfTokens_.push_back(iC.consumes<CrossingFrame<PSimHit> >(edm::InputTag("mix", trackerContainer)));
95  simHitTokens_.push_back(iC.consumes<std::vector<PSimHit> >(edm::InputTag("g4SimHits", trackerContainer)));
96  }
97  }
98 }
99 
100 //
101 // Constructor supporting consumes interface
102 //
109  //if track association there is no need to access the input collections
110  if (!doTrackAssoc_) {
111  makeMaps(e, config);
112  }
113 
114  if (doStrip_) {
115  if (useOTph2_)
116  e.getByToken(config.ph2OTrToken_, ph2trackerdigisimlink);
117  else
118  e.getByToken(config.stripToken_, stripdigisimlink);
119  }
120  if (doPixel_)
121  e.getByToken(config.pixelToken_, pixeldigisimlink);
122 }
123 
125  // Step A: Get Inputs
126  // The collections are specified via ROUList in the configuration, and can
127  // be either crossing frames (e.g., mix/g4SimHitsTrackerHitsTIBLowTof)
128  // or just PSimHits (e.g., g4SimHits/TrackerHitsTIBLowTof)
129  if (assocHitbySimTrack_) {
130  for (auto const& cfToken : config.cfTokens_) {
132  int Nhits = 0;
133  if (theEvent.getByToken(cfToken, cf_simhit)) {
134  std::unique_ptr<MixCollection<PSimHit> > thisContainerHits(new MixCollection<PSimHit>(cf_simhit.product()));
135  for (auto const& isim : *thisContainerHits) {
136  DetId theDet(isim.detUnitId());
137  SimHitMap[theDet].push_back(isim);
138  ++Nhits;
139  }
140  LogDebug("TrkHitAssocTrace") << "simHits from crossing frames; map size = " << SimHitMap.size()
141  << ", Hit count = " << Nhits << std::endl;
142  }
143  }
144  for (auto const& simHitToken : config.simHitTokens_) {
146  int Nhits = 0;
147  if (theEvent.getByToken(simHitToken, simHits)) {
148  for (auto const& isim : *simHits) {
149  DetId theDet(isim.detUnitId());
150  SimHitMap[theDet].push_back(isim);
151  ++Nhits;
152  }
153  LogDebug("TrkHitAssocTrace") << "simHits from prompt collections; map size = " << SimHitMap.size()
154  << ", Hit count = " << Nhits << std::endl;
155  }
156  }
157  } else { // !assocHitbySimTrack_
158  const char* const highTag = "HighTof";
159  unsigned int tofBin;
161  subDetTofBin theSubDetTofBin;
162  unsigned int collectionIndex = 0;
163  for (auto const& cfToken : config.cfTokens_) {
164  collectionIndex++;
166  int Nhits = 0;
167  if (theEvent.getByToken(cfToken, cf_simhit)) {
168  std::unique_ptr<MixCollection<PSimHit> > thisContainerHits(new MixCollection<PSimHit>(cf_simhit.product()));
169  theEvent.labelsForToken(cfToken, labels);
170  if (std::strstr(labels.productInstance, highTag) != nullptr) {
171  tofBin = StripDigiSimLink::HighTof;
172  } else {
173  tofBin = StripDigiSimLink::LowTof;
174  }
175  for (auto const& isim : *thisContainerHits) {
176  DetId theDet(isim.detUnitId());
177  theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
178  SimHitCollMap[theSubDetTofBin] = collectionIndex;
179  SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
180  ++Nhits;
181  }
182  LogDebug("TrkHitAssocTrace") << "simHits from crossing frames " << collectionIndex << ": " << Nhits
183  << std::endl;
184  }
185  }
186  collectionIndex = 0;
187  for (auto const& simHitToken : config.simHitTokens_) {
188  collectionIndex++;
190  int Nhits = 0;
191  if (theEvent.getByToken(simHitToken, simHits)) {
192  theEvent.labelsForToken(simHitToken, labels);
193  if (std::strstr(labels.productInstance, highTag) != nullptr) {
194  tofBin = StripDigiSimLink::HighTof;
195  } else {
196  tofBin = StripDigiSimLink::LowTof;
197  }
198  for (auto const& isim : *simHits) {
199  DetId theDet(isim.detUnitId());
200  theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
201  SimHitCollMap[theSubDetTofBin] = collectionIndex;
202  SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
203  ++Nhits;
204  }
205  LogDebug("TrkHitAssocTrace") << "simHits from prompt collection " << collectionIndex << ": " << Nhits
206  << std::endl;
207  }
208  }
209  }
210 }
211 
212 std::vector<PSimHit> TrackerHitAssociator::associateHit(const TrackingRecHit& thit) const {
213  if (const SiTrackerMultiRecHit* rechit = dynamic_cast<const SiTrackerMultiRecHit*>(&thit)) {
214  return associateMultiRecHit(rechit);
215  }
216 
217  //vector with the matched SimHit
218  std::vector<PSimHit> result;
219 
220  if (doTrackAssoc_)
221  return result; // We don't want the SimHits for this RecHit
222 
223  // Vectors to contain lists of matched simTracks, simHits
224  std::vector<SimHitIdpr> simtrackid;
225  std::vector<simhitAddr> simhitCFPos;
226 
227  //get the Detector type of the rechit
228  DetId detid = thit.geographicalId();
229  uint32_t detID = detid.rawId();
230 
231  // Get the vectors of simtrackIDs and simHit addresses associated with this rechit
232  associateHitId(thit, simtrackid, &simhitCFPos);
233  LogDebug("TrkHitAssocTrace") << printDetBnchEvtTrk(detid, detID, simtrackid);
234 
235  // Get the vector of simHits associated with this rechit
236  if (!assocHitbySimTrack_ && !simhitCFPos.empty()) {
237  // We use the indices to the simHit collections taken
238  // from the DigiSimLinks and returned in simhitCFPos.
239  // simhitCFPos[i] contains the full address of the ith simhit:
240  // <collection index, simhit index>
241 
242  //check if the recHit is a SiStripMatchedRecHit2D
243  if (dynamic_cast<const SiStripMatchedRecHit2D*>(&thit)) {
244  for (auto const& theSimHitAddr : simhitCFPos) {
245  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
246  auto it = SimHitMap.find(theSimHitCollID);
247  if (it != SimHitMap.end()) {
248  unsigned int theSimHitIndex = theSimHitAddr.second;
249  if (theSimHitIndex < (it->second).size()) {
250  const PSimHit& theSimHit = (it->second)[theSimHitIndex];
251  // Try to remove ghosts by requiring a match to the simTrack also
252  unsigned int simHitid = theSimHit.trackId();
253  EncodedEventId simHiteid = theSimHit.eventId();
254  for (auto const& id : simtrackid) {
255  if (simHitid == id.first && simHiteid == id.second) {
256  result.push_back(theSimHit);
257  }
258  }
259  LogDebug("TrkHitAssocTrace") << "by CFpos, simHit detId = " << theSimHit.detUnitId() << " address = ("
260  << theSimHitAddr.first << ", " << theSimHitIndex
261  << "), process = " << theSimHit.processType() << " ("
262  << theSimHit.eventId().bunchCrossing() << ", " << theSimHit.eventId().event()
263  << ", " << theSimHit.trackId() << ")" << std::endl;
264  }
265  }
266  }
267  } else { // Not a SiStripMatchedRecHit2D
268  for (auto const& theSimHitAddr : simhitCFPos) {
269  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
270  auto it = SimHitMap.find(theSimHitCollID);
271  if (it != SimHitMap.end()) {
272  unsigned int theSimHitIndex = theSimHitAddr.second;
273  if (theSimHitIndex < (it->second).size()) {
274  result.push_back((it->second)[theSimHitIndex]);
275  LogDebug("TrkHitAssocTrace") << "by CFpos, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
276  << " address = (" << theSimHitCollID << ", " << theSimHitIndex
277  << "), process = " << (it->second)[theSimHitIndex].processType() << " ("
278  << (it->second)[theSimHitIndex].eventId().bunchCrossing() << ", "
279  << (it->second)[theSimHitIndex].eventId().event() << ", "
280  << (it->second)[theSimHitIndex].trackId() << ")" << std::endl;
281  }
282  }
283  }
284  }
285  return result;
286  } // if !assocHitbySimTrack
287 
288  // Get the SimHit from the trackid instead
289  auto it = SimHitMap.find(detID);
290  if (it != SimHitMap.end()) {
291  for (auto const& ihit : it->second) {
292  unsigned int simHitid = ihit.trackId();
293  EncodedEventId simHiteid = ihit.eventId();
294  for (auto id : simtrackid) {
295  if (simHitid == id.first && simHiteid == id.second) {
296  result.push_back(ihit);
297  LogDebug("TrkHitAssocTrace") << "by TrackID, simHit detId = " << ihit.detUnitId()
298  << ", process = " << ihit.processType() << " (" << ihit.eventId().bunchCrossing()
299  << ", " << ihit.eventId().event() << ", " << ihit.trackId() << ")" << std::endl;
300  break;
301  }
302  }
303  }
304 
305  } else {
307  auto itrphi = SimHitMap.find(detID + 2); //iterator to the simhit in the rphi module
308  auto itster = SimHitMap.find(detID + 1); //iterator to the simhit in the stereo module
309  if (itrphi != SimHitMap.end() && itster != SimHitMap.end()) {
310  std::vector<PSimHit> simHitVector = itrphi->second;
311  simHitVector.insert(simHitVector.end(), (itster->second).begin(), (itster->second).end());
312  for (auto const& ihit : simHitVector) {
313  unsigned int simHitid = ihit.trackId();
314  EncodedEventId simHiteid = ihit.eventId();
315  for (auto const& id : simtrackid) {
316  if (simHitid == id.first && simHiteid == id.second) {
317  result.push_back(ihit);
318  LogDebug("TrkHitAssocTrace") << "by TrackID, simHit detId = " << ihit.detUnitId()
319  << ", process = " << ihit.processType() << " ("
320  << ihit.eventId().bunchCrossing() << ", " << ihit.eventId().event() << ", "
321  << ihit.trackId() << ")" << std::endl;
322  break;
323  }
324  }
325  }
326  }
327  }
328 
329  return result;
330 }
331 
332 std::vector<SimHitIdpr> TrackerHitAssociator::associateHitId(const TrackingRecHit& thit) const {
333  std::vector<SimHitIdpr> simhitid;
334  associateHitId(thit, simhitid);
335  return simhitid;
336 }
337 
339  std::vector<SimHitIdpr>& simtkid,
340  std::vector<simhitAddr>* simhitCFPos) const {
341  simtkid.clear();
342 
343  if (const SiTrackerMultiRecHit* rechit = dynamic_cast<const SiTrackerMultiRecHit*>(&thit))
344  simtkid = associateMultiRecHitId(rechit, simhitCFPos);
345 
346  //check if it is a simple SiStripRecHit2D
347  if (const SiStripRecHit2D* rechit = dynamic_cast<const SiStripRecHit2D*>(&thit))
348  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
349 
350  //check if it is a SiStripRecHit1D
351  else if (const SiStripRecHit1D* rechit = dynamic_cast<const SiStripRecHit1D*>(&thit))
352  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
353 
354  //check if it is a SiStripMatchedRecHit2D
355  else if (const SiStripMatchedRecHit2D* rechit = dynamic_cast<const SiStripMatchedRecHit2D*>(&thit))
356  simtkid = associateMatchedRecHit(rechit, simhitCFPos);
357 
358  //check if it is a ProjectedSiStripRecHit2D
359  else if (const ProjectedSiStripRecHit2D* rechit = dynamic_cast<const ProjectedSiStripRecHit2D*>(&thit))
360  simtkid = associateProjectedRecHit(rechit, simhitCFPos);
361 
362  //check if it is a Phase2TrackerRecHit1D
363  else if (const Phase2TrackerRecHit1D* rechit = dynamic_cast<const Phase2TrackerRecHit1D*>(&thit))
364  associatePhase2TrackerRecHit(rechit, simtkid, simhitCFPos);
365 
366  //check if it is a SiPixelRecHit
367  else if (const SiPixelRecHit* rechit = dynamic_cast<const SiPixelRecHit*>(&thit))
368  associatePixelRecHit(rechit, simtkid, simhitCFPos);
369 
370  //check if these are GSRecHits (from FastSim)
371  if (trackerHitRTTI::isFast(thit))
372  simtkid = associateFastRecHit(static_cast<const FastTrackerRecHit*>(&thit));
373 }
374 
375 template <typename T>
376 inline void TrackerHitAssociator::associateSiStripRecHit(const T* simplerechit,
377  std::vector<SimHitIdpr>& simtrackid,
378  std::vector<simhitAddr>* simhitCFPos) const {
379  const SiStripCluster* clust = &(*simplerechit->cluster());
380  associateSimpleRecHitCluster(clust, simplerechit->geographicalId(), simtrackid, simhitCFPos);
381 }
382 
383 //
384 // Method for obtaining simTracks and simHits from a cluster
385 //
387  const DetId& detid,
388  std::vector<SimHitIdpr>& simtrackid,
389  std::vector<PSimHit>& simhit) const {
390  std::vector<simhitAddr> simhitCFPos;
391  associateSimpleRecHitCluster(clust, detid, simtrackid, &simhitCFPos);
392 
393  for (auto const& theSimHitAddr : simhitCFPos) {
394  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
395  auto it = SimHitMap.find(theSimHitCollID);
396 
397  if (it != SimHitMap.end()) {
398  unsigned int theSimHitIndex = theSimHitAddr.second;
399  if (theSimHitIndex < (it->second).size())
400  simhit.push_back((it->second)[theSimHitIndex]);
401  LogDebug("TrkHitAssocTrace") << "For cluster, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
402  << " address = (" << theSimHitCollID << ", " << theSimHitIndex
403  << "), process = " << (it->second)[theSimHitIndex].processType()
404  << " (bnch, evt, trk) = (" << (it->second)[theSimHitIndex].eventId().bunchCrossing()
405  << ", " << (it->second)[theSimHitIndex].eventId().event() << ", "
406  << (it->second)[theSimHitIndex].trackId() << ")" << std::endl;
407  }
408  }
409 }
410 
412  const DetId& detid,
413  std::vector<SimHitIdpr>& simtrackid,
414  std::vector<simhitAddr>* simhitCFPos) const {
415  uint32_t detID = detid.rawId();
416  auto isearch = stripdigisimlink->find(detID);
417  if (isearch != stripdigisimlink->end()) { //if it is not empty
418  auto link_detset = (*isearch);
419 
420  if (clust != nullptr) { //the cluster is valid
421  int clusiz = clust->amplitudes().size();
422  int first = clust->firstStrip();
423  int last = first + clusiz;
424 
425  LogDebug("TrkHitAssocDbg") << "Cluster size " << clusiz << " first strip = " << first
426  << " last strip = " << last - 1 << std::endl
427  << " detID = " << detID << " DETSET size = " << link_detset.data.size() << std::endl;
428  int channel;
429  for (const auto& linkiter : link_detset.data) {
430  channel = (int)(linkiter.channel());
431  if (channel >= first && channel < last) {
432  LogDebug("TrkHitAssocDbg") << "Channel = " << std::setw(4) << linkiter.channel()
433  << ", TrackID = " << std::setw(8) << linkiter.SimTrackId()
434  << ", tofBin = " << std::setw(3) << linkiter.TofBin()
435  << ", fraction = " << std::setw(8) << linkiter.fraction()
436  << ", Position = " << linkiter.CFposition() << std::endl;
437  SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
438 
439  //create a vector with the list of SimTrack ID's of the tracks that contributed to the RecHit
440  //write the id only once in the vector
441 
442  if (find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
443  LogDebug("TrkHitAssocDbg") << " Adding track id = " << currentId.first
444  << " Event id = " << currentId.second.event()
445  << " Bunch Xing = " << currentId.second.bunchCrossing() << std::endl;
446  simtrackid.push_back(currentId);
447  }
448 
449  if (simhitCFPos != nullptr) {
450  //create a vector that contains all the positions (in the MixCollection) of the SimHits that contributed to the RecHit
451  //write position only once
452  unsigned int currentCFPos = linkiter.CFposition();
453  unsigned int tofBin = linkiter.TofBin();
454  subDetTofBin theSubDetTofBin = std::make_pair(detid.subdetId(), tofBin);
455  auto it = SimHitCollMap.find(theSubDetTofBin);
456  if (it != SimHitCollMap.end()) {
457  simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
458  if (find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
459  simhitCFPos->push_back(currentAddr);
460  }
461  }
462  }
463  }
464  }
465  } else {
466  edm::LogError("TrackerHitAssociator") << "no cluster reference attached";
467  }
468  }
469 }
470 
471 std::vector<SimHitIdpr> TrackerHitAssociator::associateMatchedRecHit(const SiStripMatchedRecHit2D* matchedrechit,
472  std::vector<simhitAddr>* simhitCFPos) const {
473  std::vector<SimHitIdpr> matched_mono;
474  std::vector<SimHitIdpr> matched_st;
475 
476  const SiStripRecHit2D mono = matchedrechit->monoHit();
477  const SiStripRecHit2D st = matchedrechit->stereoHit();
478  //associate the two simple hits separately
479  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
480  associateSiStripRecHit(&st, matched_st, simhitCFPos);
481 
482  //save in a vector all the simtrack-id's that are common to mono and stereo hits
483  std::vector<SimHitIdpr> simtrackid;
484  if (!(matched_mono.empty() || matched_st.empty())) {
485  for (auto const& mhit : matched_mono) {
486  //save only once the ID
487  if (find(simtrackid.begin(), simtrackid.end(), mhit) == simtrackid.end()) {
488  //save if the stereoID matched the monoID
489  if (find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
490  simtrackid.push_back(mhit);
491  }
492  }
493  }
494  }
495  return simtrackid;
496 }
497 
498 std::vector<SimHitIdpr> TrackerHitAssociator::associateProjectedRecHit(const ProjectedSiStripRecHit2D* projectedrechit,
499  std::vector<simhitAddr>* simhitCFPos) const {
500  //projectedRecHit is a "matched" rechit with only one component
501 
502  std::vector<SimHitIdpr> matched_mono;
503 
504  const SiStripRecHit2D mono = projectedrechit->originalHit();
505  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
506  return matched_mono;
507 }
508 
510  std::vector<SimHitIdpr>& simtrackid,
511  std::vector<simhitAddr>* simhitCFPos) const {
512  //
513  // Phase 2 outer tracker associator
514  //
515  DetId detid = rechit->geographicalId();
516  uint32_t detID = detid.rawId();
517 
518  auto isearch = ph2trackerdigisimlink->find(detID);
519  if (isearch != ph2trackerdigisimlink->end()) { //if it is not empty
520  auto link_detset = (*isearch);
521  Phase2TrackerRecHit1D::CluRef const& cluster = rechit->cluster();
522 
523  //check the reference is valid
524  if (!(cluster.isNull())) { //if the cluster is valid
525  int minRow = (*cluster).firstStrip();
526  int maxRow = (*cluster).firstStrip() + (*cluster).size();
527  int Col = (*cluster).column();
528  LogDebug("TrkHitAssocDbg") << " Cluster minRow " << minRow << " maxRow " << maxRow << " column " << Col
529  << std::endl;
530  int dsl = 0;
531  for (auto const& linkiter : link_detset.data) {
532  ++dsl;
533  std::pair<int, int> coord = Phase2TrackerDigi::channelToPixel(linkiter.channel());
534  LogDebug("TrkHitAssocDbg") << " " << dsl << ") Digi link: row " << coord.first << " col " << coord.second
535  << std::endl;
536  if (coord.first <= maxRow && coord.first >= minRow && coord.second == Col) {
537  LogDebug("TrkHitAssocDbg") << " !-> trackid " << linkiter.SimTrackId() << endl
538  << " fraction " << linkiter.fraction() << endl;
539  SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
540  if (find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
541  simtrackid.push_back(currentId);
542  }
543 
544  if (simhitCFPos != nullptr) {
545  //create a vector that contains all the positions (in the MixCollection) of the SimHits that contributed to the RecHit
546  //write position only once
547  unsigned int currentCFPos = linkiter.CFposition();
548  unsigned int tofBin = linkiter.TofBin();
549  subDetTofBin theSubDetTofBin = std::make_pair(detid.subdetId(), tofBin);
550  auto it = SimHitCollMap.find(theSubDetTofBin);
551  if (it != SimHitCollMap.end()) {
552  simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
553  if (find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
554  simhitCFPos->push_back(currentAddr);
555  }
556  }
557  }
558  }
559  } // end of simlink loop
560  } else {
561  edm::LogError("TrackerHitAssociator") << "no Phase2 outer tracker cluster reference attached";
562  }
563  }
564 }
565 
567  std::vector<SimHitIdpr>& simtrackid,
568  std::vector<simhitAddr>* simhitCFPos) const {
569  //
570  // Pixel associator
571  //
572  DetId detid = pixelrechit->geographicalId();
573  uint32_t detID = detid.rawId();
574 
575  auto isearch = pixeldigisimlink->find(detID);
576  if (isearch != pixeldigisimlink->end()) { //if it is not empty
577  auto link_detset = (*isearch);
578  SiPixelRecHit::ClusterRef const& cluster = pixelrechit->cluster();
579 
580  //check the reference is valid
581 
582  if (!(cluster.isNull())) { //if the cluster is valid
583 
584  int minPixelRow = (*cluster).minPixelRow();
585  int maxPixelRow = (*cluster).maxPixelRow();
586  int minPixelCol = (*cluster).minPixelCol();
587  int maxPixelCol = (*cluster).maxPixelCol();
588  LogDebug("TrkHitAssocDbg") << " Cluster minRow " << minPixelRow << " maxRow " << maxPixelRow << std::endl
589  << " Cluster minCol " << minPixelCol << " maxCol " << maxPixelCol << std::endl;
590  int dsl = 0;
591  for (auto const& linkiter : link_detset.data) {
592  ++dsl;
593  std::pair<int, int> pixel_coord = PixelDigi::channelToPixel(linkiter.channel());
594  LogDebug("TrkHitAssocDbg") << " " << dsl << ") Digi link: row " << pixel_coord.first << " col "
595  << pixel_coord.second << std::endl;
596  if (pixel_coord.first <= maxPixelRow && pixel_coord.first >= minPixelRow && pixel_coord.second <= maxPixelCol &&
597  pixel_coord.second >= minPixelCol) {
598  LogDebug("TrkHitAssocDbg") << " !-> trackid " << linkiter.SimTrackId() << endl
599  << " fraction " << linkiter.fraction() << endl;
600  SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
601  if (find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
602  simtrackid.push_back(currentId);
603  }
604 
605  if (simhitCFPos != nullptr) {
606  //create a vector that contains all the positions (in the MixCollection) of the SimHits that contributed to the RecHit
607  //write position only once
608  unsigned int currentCFPos = linkiter.CFposition();
609  unsigned int tofBin = linkiter.TofBin();
610  subDetTofBin theSubDetTofBin = std::make_pair(detid.subdetId(), tofBin);
611  auto it = SimHitCollMap.find(theSubDetTofBin);
612  if (it != SimHitCollMap.end()) {
613  simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
614  if (find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
615  simhitCFPos->push_back(currentAddr);
616  }
617  }
618  }
619  }
620  }
621  } else {
622  edm::LogError("TrackerHitAssociator") << "no Pixel cluster reference attached";
623  }
624  }
625 }
626 
627 std::vector<PSimHit> TrackerHitAssociator::associateMultiRecHit(const SiTrackerMultiRecHit* multirechit) const {
628  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
629  // std::vector<PSimHit> assimhits;
630  int size = multirechit->weights().size(), idmostprobable = 0;
631 
632  for (int i = 0; i < size; ++i) {
633  if (multirechit->weight(i) > multirechit->weight(idmostprobable))
634  idmostprobable = i;
635  }
636 
637  return associateHit(*componenthits[idmostprobable]);
638 }
639 
640 std::vector<SimHitIdpr> TrackerHitAssociator::associateMultiRecHitId(const SiTrackerMultiRecHit* multirechit,
641  std::vector<simhitAddr>* simhitCFPos) const {
642  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
643  int size = multirechit->weights().size(), idmostprobable = 0;
644 
645  for (int i = 0; i < size; ++i) {
646  if (multirechit->weight(i) > multirechit->weight(idmostprobable))
647  idmostprobable = i;
648  }
649 
650  std::vector<SimHitIdpr> simhitid;
651  associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
652  return simhitid;
653 }
654 
655 // fastsim
656 std::vector<SimHitIdpr> TrackerHitAssociator::associateFastRecHit(const FastTrackerRecHit* rechit) const {
657  vector<SimHitIdpr> simtrackid;
658  simtrackid.clear();
659  for (size_t index = 0, indexEnd = rechit->nSimTrackIds(); index < indexEnd; ++index) {
660  SimHitIdpr currentId(rechit->simTrackId(index), EncodedEventId(rechit->simTrackEventId(index)));
661  simtrackid.push_back(currentId);
662  }
663  return simtrackid;
664 }
665 
667  const uint32_t& detID,
668  std::vector<SimHitIdpr>& simtrackid) const {
669  std::stringstream message;
670  message << "recHit subdet, detID = " << detid.subdetId() << ", " << detID << ", (bnch, evt, trk) = ";
671  for (size_t i = 0; i < simtrackid.size(); ++i)
672  message << ", (" << simtrackid[i].second.bunchCrossing() << ", " << simtrackid[i].second.event() << ", "
673  << simtrackid[i].first << ")";
674  // message << std::endl;
675  return message.str();
676 }
TrackerHitAssociator::Config::doStrip_
bool doStrip_
Definition: TrackerHitAssociator.h:61
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::DetSetVector
Definition: DetSetVector.h:61
TrackerHitAssociator::SimHitCollMap
simhit_collectionMap SimHitCollMap
Definition: TrackerHitAssociator.h:118
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
PixelSubdetector.h
TrackerHitAssociator::associatePhase2TrackerRecHit
void associatePhase2TrackerRecHit(const Phase2TrackerRecHit1D *rechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:509
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
TrackerHitAssociator::Config::ph2OTrToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > ph2OTrToken_
Definition: TrackerHitAssociator.h:63
TrackerHitAssociator::assocHitbySimTrack_
bool assocHitbySimTrack_
Definition: TrackerHitAssociator.h:130
edm::Handle::product
T const * product() const
Definition: Handle.h:70
TrackerHitAssociator::associateSimpleRecHitCluster
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:411
TrackerHitAssociator::associatePixelRecHit
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:566
SiPixelPhase1TrackingParticleV_cfi.simHitToken
simHitToken
Definition: SiPixelPhase1TrackingParticleV_cfi.py:122
SimHitIdpr
std::pair< uint32_t, EncodedEventId > SimHitIdpr
Definition: TrackerHitAssociator.h:54
TrackerHitAssociator::ph2trackerdigisimlink
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
Definition: TrackerHitAssociator.h:129
TrackerHitAssociator::associateMultiRecHit
std::vector< PSimHit > associateMultiRecHit(const SiTrackerMultiRecHit *multirechit) const
Definition: TrackerHitAssociator.cc:627
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
CrossingFrame.h
TrackerHitAssociator::associateProjectedRecHit
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:498
TrackerHitAssociator::stripdigisimlink
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
Definition: TrackerHitAssociator.h:127
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
TrackerHitAssociator::associateHit
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
Definition: TrackerHitAssociator.cc:212
edm::DetSetVector::reserve
void reserve(size_t s)
Definition: DetSetVector.h:147
SiTrackerMultiRecHit::recHits
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
Definition: SiTrackerMultiRecHit.cc:59
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
FastTrackerRecHit
Definition: FastTrackerRecHit.h:40
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
TrackerHitAssociator.h
TrackerHitAssociator::Config::doTrackAssoc_
bool doTrackAssoc_
Definition: TrackerHitAssociator.h:61
TrackerHitAssociator::Config
Definition: TrackerHitAssociator.h:57
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
TrackerHitAssociator::TrackerHitAssociator
TrackerHitAssociator(const edm::Event &e, const Config &config)
Definition: TrackerHitAssociator.cc:103
edm::Handle
Definition: AssociativeIterator.h:50
SiPixelRecHit::cluster
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
dqmdumpme.first
first
Definition: dqmdumpme.py:55
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
ProjectedSiStripRecHit2D
Definition: ProjectedSiStripRecHit2D.h:8
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
edm::Ref
Definition: AssociativeIterator.h:58
PSimHit::eventId
EncodedEventId eventId() const
Definition: PSimHit.h:108
PSimHit::detUnitId
unsigned int detUnitId() const
Definition: PSimHit.h:97
SiStripCluster::firstStrip
uint16_t firstStrip() const
Definition: SiStripCluster.h:47
EncodedEventId
Definition: EncodedEventId.h:11
config
Definition: config.py:1
DetId
Definition: DetId.h:17
CrossingFrame
Definition: CrossingFrame.h:38
dqmdumpme.last
last
Definition: dqmdumpme.py:56
Phase2TrackerRecHit1D::cluster
CluRef cluster() const
Definition: Phase2TrackerRecHit1D.h:24
PSimHit::processType
unsigned short processType() const
Definition: PSimHit.h:120
edm::Event::labelsForToken
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: Event.h:251
MixCollection
Definition: MixCollection.h:11
mps_fire.end
end
Definition: mps_fire.py:242
SiStripMatchedRecHit2D::stereoHit
SiStripRecHit2D stereoHit() const
Definition: SiStripMatchedRecHit2D.h:25
ProjectedSiStripRecHit2D::originalHit
SiStripRecHit2D originalHit() const
Definition: ProjectedSiStripRecHit2D.h:56
FastTrackerRecHit::simTrackId
virtual int32_t simTrackId(size_t i) const
Definition: FastTrackerRecHit.h:99
SiTrackerMultiRecHit::weight
float weight(unsigned int i) const
Definition: SiTrackerMultiRecHit.h:52
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
TrackerHitAssociator::simHitCollectionID
unsigned int simHitCollectionID
Definition: TrackerHitAssociator.h:75
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FastTrackerRecHit::nSimTrackIds
virtual size_t nSimTrackIds() const
Definition: FastTrackerRecHit.h:98
TrackerHitAssociator::Config::stripToken_
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > stripToken_
Definition: TrackerHitAssociator.h:62
funct::true
true
Definition: Factorize.h:173
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
TrackerHitAssociator::Config::simHitTokens_
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
Definition: TrackerHitAssociator.h:65
FastTrackerRecHit::simTrackEventId
virtual int32_t simTrackEventId(size_t i) const
Definition: FastTrackerRecHit.h:100
SiTrackerMultiRecHit::weights
std::vector< float > const & weights() const
Definition: SiTrackerMultiRecHit.h:47
TrackerHitAssociator::printDetBnchEvtTrk
std::string printDetBnchEvtTrk(const DetId &detid, const uint32_t &detID, std::vector< SimHitIdpr > &simtrackid) const
Definition: TrackerHitAssociator.cc:666
TrackerHitAssociator::doStrip_
bool doStrip_
Definition: TrackerHitAssociator.h:130
TrackerHitAssociator::SimHitMap
simhit_map SimHitMap
Definition: TrackerHitAssociator.h:116
TrackerHitAssociator::pixeldigisimlink
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
Definition: TrackerHitAssociator.h:128
EncodedEventId::event
int event() const
get the contents of the subdetector field (should be protected?)
Definition: EncodedEventId.h:30
SiStripMatchedRecHit2D::monoHit
SiStripRecHit2D monoHit() const
Definition: SiStripMatchedRecHit2D.h:26
TrackerHitAssociator::useOTph2_
bool useOTph2_
Definition: TrackerHitAssociator.h:130
createfilelist.int
int
Definition: createfilelist.py:10
SiStripCluster::size
uint8_t size() const
Definition: SiStripCluster.h:64
TrackerHitAssociator::associateCluster
void associateCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< PSimHit > &simhit) const
Definition: TrackerHitAssociator.cc:386
TrackerHitAssociator::Config::pixelToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > pixelToken_
Definition: TrackerHitAssociator.h:63
Phase2TrackerDigi::channelToPixel
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
Definition: Phase2TrackerDigi.h:39
TrackerHitAssociator::associateMatchedRecHit
std::vector< SimHitIdpr > associateMatchedRecHit(const SiStripMatchedRecHit2D *matchedrechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:471
TrackerHitAssociator::doTrackAssoc_
bool doTrackAssoc_
Definition: TrackerHitAssociator.h:130
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiStripRecHit1D
Definition: SiStripRecHit1D.h:8
SiStripCluster::amplitudes
SiStripCluster const & amplitudes() const
Definition: SiStripCluster.h:69
TrackingRecHit
Definition: TrackingRecHit.h:21
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Ref.h
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
TrackerHitAssociator::associateMultiRecHitId
std::vector< SimHitIdpr > associateMultiRecHitId(const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:640
DetId.h
T
long double T
Definition: Basic3DVectorLD.h:48
TrackerHitAssociator::Config::Config
Config()
Definition: TrackerHitAssociator.h:58
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrackerHitAssociator::Config::doPixel_
bool doPixel_
Definition: TrackerHitAssociator.h:61
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
PSimHit::trackId
unsigned int trackId() const
Definition: PSimHit.h:106
TrackerHitAssociator::Config::cfTokens_
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > cfTokens_
Definition: TrackerHitAssociator.h:64
mps_fire.result
result
Definition: mps_fire.py:311
PSimHit
Definition: PSimHit.h:15
edm::Event
Definition: Event.h:73
SiStripCluster
Definition: SiStripCluster.h:9
SiTrackerMultiRecHit
Definition: SiTrackerMultiRecHit.h:13
TrackerHitAssociator::associateHitId
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
Definition: TrackerHitAssociator.cc:332
TrackerHitAssociator::associateFastRecHit
std::vector< SimHitIdpr > associateFastRecHit(const FastTrackerRecHit *rechit) const
Definition: TrackerHitAssociator.cc:656
TrackerHitAssociator::associateSiStripRecHit
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
Definition: TrackerHitAssociator.cc:376
StripSubdetector.h
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
TrackerHitAssociator::Config::useOTph2_
bool useOTph2_
Definition: TrackerHitAssociator.h:61
TrackerHitAssociator::makeMaps
void makeMaps(const edm::Event &theEvent, const Config &config)
Definition: TrackerHitAssociator.cc:124
EncodedEventId::bunchCrossing
int bunchCrossing() const
get the detector field from this detid
Definition: EncodedEventId.h:25
TrackerHitAssociator::doPixel_
bool doPixel_
Definition: TrackerHitAssociator.h:130
TrackerHitAssociator::simhitAddr
std::pair< unsigned int, unsigned int > simhitAddr
Definition: TrackerHitAssociator.h:74
Phase2TrackerRecHit1D
Definition: Phase2TrackerRecHit1D.h:10
edm::ProductLabels
Definition: ProductLabels.h:4
PixelDigi::channelToPixel
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:65
trackerHitRTTI::isFast
bool isFast(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:37
TrackerHitAssociator::subDetTofBin
std::pair< unsigned int, unsigned int > subDetTofBin
Definition: TrackerHitAssociator.h:74
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37