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