CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //--- for Geometry:
13 
15 
16 //for accumulate
17 #include <numeric>
18 #include <iostream>
19 
20 using namespace std;
21 using namespace edm;
22 
23 //
24 // Constructor
25 //
27  doPixel_( true ),
28  doStrip_( true ),
29  doTrackAssoc_( false ),
30  assocHitbySimTrack_( false ) {
31  //
32  // Take by default all tracker SimHits
33  //
34  vstring trackerContainers;
35  trackerContainers.push_back("g4SimHitsTrackerHitsTIBLowTof");
36  trackerContainers.push_back("g4SimHitsTrackerHitsTIBHighTof");
37  trackerContainers.push_back("g4SimHitsTrackerHitsTIDLowTof");
38  trackerContainers.push_back("g4SimHitsTrackerHitsTIDHighTof");
39  trackerContainers.push_back("g4SimHitsTrackerHitsTOBLowTof");
40  trackerContainers.push_back("g4SimHitsTrackerHitsTOBHighTof");
41  trackerContainers.push_back("g4SimHitsTrackerHitsTECLowTof");
42  trackerContainers.push_back("g4SimHitsTrackerHitsTECHighTof");
43  trackerContainers.push_back("g4SimHitsTrackerHitsPixelBarrelLowTof");
44  trackerContainers.push_back("g4SimHitsTrackerHitsPixelBarrelHighTof");
45  trackerContainers.push_back("g4SimHitsTrackerHitsPixelEndcapLowTof");
46  trackerContainers.push_back("g4SimHitsTrackerHitsPixelEndcapHighTof");
47 
48  makeMaps(e, trackerContainers);
49 
50  if(doStrip_) e.getByLabel("simSiStripDigis", stripdigisimlink);
51  if(doPixel_) e.getByLabel("simSiPixelDigis", pixeldigisimlink);
52 }
53 
54 //
55 // Constructor with configurables
56 //
58  doPixel_( conf.getParameter<bool>("associatePixel") ),
59  doStrip_( conf.getParameter<bool>("associateStrip") ),
60  doTrackAssoc_( conf.getParameter<bool>("associateRecoTracks") ) {
61  assocHitbySimTrack_ = conf.existsAs<bool>("associateHitbySimTrack") ? conf.getParameter<bool>("associateHitbySimTrack") : false;
62 
63  //if track association there is no need to access the input collections
64  if(!doTrackAssoc_) {
65  vstring trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
66  makeMaps(e, trackerContainers);
67  }
68 
69  if(doStrip_) e.getByLabel("simSiStripDigis", stripdigisimlink);
70  if(doPixel_) e.getByLabel("simSiPixelDigis", pixeldigisimlink);
71 }
72 
73 void TrackerHitAssociator::makeMaps(const edm::Event& theEvent, const vstring trackerContainers) {
74  // Step A: Get Inputs
75  // The collections are specified via ROUList in the configuration, and can
76  // be either crossing frames (e.g., mix/g4SimHitsTrackerHitsTIBLowTof)
77  // or just PSimHits (e.g., g4SimHits/TrackerHitsTIBLowTof)
78 
79  for(auto const& trackerContainer : trackerContainers) {
81  edm::InputTag tag_cf("mix", trackerContainer);
83  edm::InputTag tag_hits("g4SimHits", trackerContainer);
84  int Nhits = 0;
85  if (theEvent.getByLabel(tag_cf, cf_simhit)) {
86  std::auto_ptr<MixCollection<PSimHit> > thisContainerHits(new MixCollection<PSimHit>(cf_simhit.product()));
87  for (MixCollection<PSimHit>::iterator isim = thisContainerHits->begin();
88  isim != thisContainerHits->end(); isim++) {
89  DetId theDet((*isim).detUnitId());
90  if (assocHitbySimTrack_) {
91  SimHitMap[theDet].push_back((*isim));
92  } else {
93  unsigned int tofBin = StripDigiSimLink::LowTof;
94  if (trackerContainer.find(std::string("HighTof")) != std::string::npos) tofBin = StripDigiSimLink::HighTof;
95  simHitCollectionID theSimHitCollID = std::make_pair(theDet.subdetId(), tofBin);
96  SimHitCollMap[theSimHitCollID].push_back((*isim));
97  }
98  Nhits++;
99  }
100  // std::cout << "simHits from crossing frames; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
101  } else {
102  theEvent.getByLabel(tag_hits, simHits);
103  for (std::vector<PSimHit>::const_iterator isim = simHits->begin();
104  isim != simHits->end(); isim++) {
105  DetId theDet((*isim).detUnitId());
106  if (assocHitbySimTrack_) {
107  SimHitMap[theDet].push_back((*isim));
108  } else {
109  unsigned int tofBin = StripDigiSimLink::LowTof;
110  if (trackerContainer.find(std::string("HighTof")) != std::string::npos) tofBin = StripDigiSimLink::HighTof;
111  simHitCollectionID theSimHitCollID = std::make_pair(theDet.subdetId(), tofBin);
112  SimHitCollMap[theSimHitCollID].push_back((*isim));
113  }
114  Nhits++;
115  }
116  // std::cout << "simHits from prompt collections; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
117  }
118  }
119 }
120 
121 std::vector<PSimHit> TrackerHitAssociator::associateHit(const TrackingRecHit & thit) const
122 {
123 
124  if (const SiTrackerMultiRecHit * rechit = dynamic_cast<const SiTrackerMultiRecHit *>(&thit)){
125  return associateMultiRecHit(rechit);
126  }
127 
128  //vector with the matched SimHit
129  std::vector<PSimHit> result;
130 
131  if(doTrackAssoc_) return result;
132 
133  // Vectors to contain lists of matched simTracks, simHits
134  std::vector<SimHitIdpr> simtrackid;
135  std::vector<simhitAddr> simhitCFPos;
136 
137  //get the Detector type of the rechit
138  DetId detid= thit.geographicalId();
139  uint32_t detID = detid.rawId();
140 
141  // Get the vectors of simtrackIDs and simHit indices associated with this rechit
142  associateHitId(thit, simtrackid, &simhitCFPos);
143  // std::cout << "recHit subdet, detID = " << detid.subdetId() << ", " << detID << ", (bnch, evt, trk) = ";
144  // for (size_t i=0; i<simtrackid.size(); ++i)
145  // std::cout << ", (" << simtrackid[i].second.bunchCrossing() << ", "
146  // << simtrackid[i].second.event() << ", " << simtrackid[i].first << ")";
147  // std::cout << std::endl;
148 
149  // Get the vector of simHits associated with this rechit
150 
151  if (!assocHitbySimTrack_ && simhitCFPos.size() > 0) {
152  // We use the indices to the simHit collections taken
153  // from the DigiSimLinks and returned in simhitCFPos.
154  // simhitCFPos[i] contains the full address of the ith simhit:
155  // <collection, index> = <<subdet, tofBin>, index>
156 
157  //check if the recHit is a SiStripMatchedRecHit2D
158  bool isMatchedHit = false;
159  if(dynamic_cast<const SiStripMatchedRecHit2D *>(&thit))
160  isMatchedHit = true;
161 
162  for(size_t i=0; i<simhitCFPos.size(); i++) {
163  simhitAddr theSimHitAddr = simhitCFPos[i];
164  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
165  simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
166  if (it!= SimHitCollMap.end()) {
167  unsigned int theSimHitIndex = theSimHitAddr.second;
168  if (theSimHitIndex < (it->second).size()) {
169  const PSimHit& theSimHit = (it->second)[theSimHitIndex];
170  if (isMatchedHit) {
171  // Try to remove ghosts by requiring a match to the simTrack also
172  unsigned int simHitid = theSimHit.trackId();
173  EncodedEventId simHiteid = theSimHit.eventId();
174  for(size_t i=0; i<simtrackid.size();i++) {
175  if(simHitid == simtrackid[i].first && simHiteid == simtrackid[i].second) {
176  result.push_back(theSimHit);
177  }
178  }
179  } else {
180  result.push_back(theSimHit);
181  }
182  // std::cout << "by CFpos, simHit detId = " << theSimHit.detUnitId() << " address = (" << (theSimHitAddr.first).first
183  // << ", " << (theSimHitAddr.first).second << ", " << theSimHitIndex
184  // << "), process = " << theSimHit.processType() << " (" << theSimHit.eventId().bunchCrossing()
185  // << ", " << theSimHit.eventId().event() << ", " << theSimHit.trackId() << ")" << std::endl;
186  }
187  }
188  }
189  return result;
190  }
191 
192  // Get the SimHit from the trackid instead
193  std::map<unsigned int, std::vector<PSimHit> >::const_iterator it = SimHitMap.find(detID);
194  if (it!= SimHitMap.end()) {
195  vector<PSimHit>::const_iterator simHitIter = (it->second).begin();
196  vector<PSimHit>::const_iterator simHitIterEnd = (it->second).end();
197  for (;simHitIter != simHitIterEnd; ++simHitIter) {
198  const PSimHit& ihit = *simHitIter;
199  unsigned int simHitid = ihit.trackId();
200  EncodedEventId simHiteid = ihit.eventId();
201  // std::cout << "by simTk, simHit, process = " << ihit.processType() << " (" << ihit.eventId().bunchCrossing()
202  // << ", " << ihit.eventId().event() << ", " << ihit.trackId() << ")";
203 
204  for(size_t i=0; i<simtrackid.size();i++) {
205  if(simHitid == simtrackid[i].first && simHiteid == simtrackid[i].second) {
206 // cout << "Associator ---> ID" << ihit.trackId() << " Simhit x= " << ihit.localPosition().x()
207 // << " y= " << ihit.localPosition().y() << " z= " << ihit.localPosition().x() << endl;
208  // std::cout << " matches";
209  result.push_back(ihit);
210  break;
211  }
212  }
213  // std::cout << std::endl;
214  }
215 
216  }else{
217 
219  std::map<unsigned int, std::vector<PSimHit> >::const_iterator itrphi =
220  SimHitMap.find(detID+2); //iterator to the simhit in the rphi module
221  std::map<unsigned int, std::vector<PSimHit> >::const_iterator itster =
222  SimHitMap.find(detID+1);//iterator to the simhit in the stereo module
223  if (itrphi!= SimHitMap.end()&&itster!=SimHitMap.end()) {
224  std::vector<PSimHit> simHitVector = itrphi->second;
225  simHitVector.insert(simHitVector.end(),(itster->second).begin(),(itster->second).end());
226  vector<PSimHit>::const_iterator simHitIter = simHitVector.begin();
227  vector<PSimHit>::const_iterator simHitIterEnd = simHitVector.end();
228  for (;simHitIter != simHitIterEnd; ++simHitIter) {
229  const PSimHit& ihit = *simHitIter;
230  unsigned int simHitid = ihit.trackId();
231  EncodedEventId simHiteid = ihit.eventId();
232  for(size_t i=0; i<simtrackid.size();i++) {
233  if(simHitid == simtrackid[i].first && simHiteid == simtrackid[i].second) {
234 // if(simHitid == simtrackid[i].first && simHiteid.bunchCrossing() == simtrackid[i].second.bunchCrossing()) {
235  // cout << "GluedDet Associator ---> ID" << ihit.trackId() << " Simhit x= " << ihit.localPosition().x()
236  // << " y= " << ihit.localPosition().y() << " z= " << ihit.localPosition().x() << endl;
237  result.push_back(ihit);
238  break;
239  }
240  }
241  }
242  }
243  }
244 
245  return result;
246 }
247 
248 std::vector< SimHitIdpr > TrackerHitAssociator::associateHitId(const TrackingRecHit & thit) const
249 {
250  std::vector< SimHitIdpr > simhitid;
251  associateHitId(thit, simhitid);
252  return simhitid;
253 }
254 
255 void TrackerHitAssociator::associateHitId(const TrackingRecHit & thit, std::vector< SimHitIdpr > & simtkid,
256  std::vector<simhitAddr>* simhitCFPos) const
257 {
258 
259  simtkid.clear();
260 
261  //get the Detector type of the rechit
262  DetId detid= thit.geographicalId();
263  if (const SiTrackerMultiRecHit * rechit = dynamic_cast<const SiTrackerMultiRecHit *>(&thit)){
264  simtkid=associateMultiRecHitId(rechit, simhitCFPos);
265  }
266 
267  //cout << "Associator ---> get Detid " << detID << endl;
268  //check we are in the strip tracker
269  if(detid.subdetId() == StripSubdetector::TIB ||
270  detid.subdetId() == StripSubdetector::TOB ||
271  detid.subdetId() == StripSubdetector::TID ||
272  detid.subdetId() == StripSubdetector::TEC)
273  {
274  //check if it is a simple SiStripRecHit2D
275  if(const SiStripRecHit2D * rechit =
276  dynamic_cast<const SiStripRecHit2D *>(&thit))
277  {
278  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
279  }
280  //check if it is a SiStripRecHit1D
281  else if(const SiStripRecHit1D * rechit =
282  dynamic_cast<const SiStripRecHit1D *>(&thit))
283  {
284  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
285  }
286  //check if it is a SiStripMatchedRecHit2D
287  else if(const SiStripMatchedRecHit2D * rechit =
288  dynamic_cast<const SiStripMatchedRecHit2D *>(&thit))
289  {
290  simtkid = associateMatchedRecHit(rechit, simhitCFPos);
291  }
292  //check if it is a ProjectedSiStripRecHit2D
293  else if(const ProjectedSiStripRecHit2D * rechit =
294  dynamic_cast<const ProjectedSiStripRecHit2D *>(&thit))
295  {
296  simtkid = associateProjectedRecHit(rechit, simhitCFPos);
297  }
298  else{
299  //std::cout << "associate to invalid" << std::endl;
300  //throw cms::Exception("Unknown RecHit Type") << "TrackerHitAssociator failed second casting of " << typeid(thit).name() << " type ";
301  }
302  }
303  //check we are in the pixel tracker
304  else if( (unsigned int)(detid.subdetId()) == PixelSubdetector::PixelBarrel ||
305  (unsigned int)(detid.subdetId()) == PixelSubdetector::PixelEndcap)
306  {
307  if(const SiPixelRecHit * rechit = dynamic_cast<const SiPixelRecHit *>(&thit))
308  {
309  associatePixelRecHit(rechit, simtkid, simhitCFPos);
310  }
311  }
312  //check if these are GSRecHits (from FastSim)
313  if(const SiTrackerGSRecHit2D * rechit = dynamic_cast<const SiTrackerGSRecHit2D *>(&thit))
314  {
315  simtkid = associateGSRecHit(rechit);
316  }
317  if(const SiTrackerGSMatchedRecHit2D * rechit = dynamic_cast<const SiTrackerGSMatchedRecHit2D *>(&thit))
318  {
319  simtkid = associateGSMatchedRecHit(rechit);
320  }
321 
322 }
323 
324 template<typename T>
325 void TrackerHitAssociator::associateSiStripRecHit(const T *simplerechit, std::vector<SimHitIdpr>& simtrackid, std::vector<simhitAddr>* simhitCFPos) const
326 {
327  const SiStripCluster* clust = &(*simplerechit->cluster());
328  associateSimpleRecHitCluster(clust, simplerechit->geographicalId(), simtrackid, simhitCFPos);
329 }
330 
332  const DetId& detid,
333  std::vector<SimHitIdpr>& simtrackid,
334  std::vector<simhitAddr>* simhitCFPos) const {
335 
336  uint32_t detID = detid.rawId();
338  if(isearch != stripdigisimlink->end()) { //if it is not empty
339  edm::DetSet<StripDigiSimLink> link_detset = (*isearch);
340 
341  if(clust!=0){//the cluster is valid
342  int clusiz = clust->amplitudes().size();
343  int first = clust->firstStrip();
344  int last = first + clusiz;
345 
346 // std::cout << "CLUSTERSIZE " << clusiz << " first strip = " << first << " last strip = " << last-1 << std::endl;
347 // std::cout << " detID = " << detID << " DETSET size = " << link_detset.data.size() << std::endl;
348  //use a vector
349  std::vector<SimHitIdpr> idcachev;
350  std::vector<simhitAddr> CFposcachev;
351  for(edm::DetSet<StripDigiSimLink>::const_iterator linkiter = link_detset.data.begin(); linkiter != link_detset.data.end(); linkiter++){
352  if( (int)(linkiter->channel()) >= first && (int)(linkiter->channel()) < last ){
353 
354  //check this digisimlink
355 // printf("%s%4d%s%8d%s%3d%s%8.4f\n", "CHANNEL = ", linkiter->channel(), " TrackID = ", linkiter->SimTrackId(),
356 // " tofBin = ", linkiter->TofBin(), " fraction = ", linkiter->fraction());
357  /*
358  std::cout << "CHECKING CHANNEL = " << linkiter->channel() << std::endl;
359  std::cout << "TrackID = " << linkiter->SimTrackId() << std::endl;
360  std::cout << "Position = " << linkiter->CFposition() << std::endl;
361  std::cout << " fraction = " << linkiter->fraction() << std::endl;
362  */
363 
364  SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
365 
366  //create a vector with the list of SimTrack ID's of the tracks that contributed to the RecHit
367  //write the id only once in the vector
368 
369  if(find(idcachev.begin(),idcachev.end(),currentId ) == idcachev.end()){
370  /*
371  std::cout << " Adding track id = " << currentId.first
372  << " Event id = " << currentId.second.event()
373  << " Bunch Xing = " << currentId.second.bunchCrossing()
374  << std::endl;
375  */
376  idcachev.push_back(currentId);
377  simtrackid.push_back(currentId);
378  }
379 
380  if (simhitCFPos != 0) {
381  //create a vector that contains all the position (in the MixCollection) of the SimHits that contributed to the RecHit
382  //write position only once
383  unsigned int currentCFPos = linkiter->CFposition();
384  unsigned int tofBin = linkiter->TofBin();
385  simHitCollectionID theSimHitCollID = std::make_pair(detid.subdetId(), tofBin);
386  simhitAddr currentAddr = std::make_pair(theSimHitCollID, currentCFPos);
387 
388  if(find(CFposcachev.begin(), CFposcachev.end(), currentAddr ) == CFposcachev.end()) {
389 // std::cout << "CHECKING CHANNEL = " << linkiter->channel() << std::endl;
390 // std::cout << "\tTrackID = " << linkiter->SimTrackId() << "\tCFPos = " << currentCFPos <<"\ttofBin = " << tofBin << std::endl;
391 // simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
392 // if (it!= SimHitCollMap.end()) {
393 // PSimHit theSimHit = it->second[currentCFPos];
394 // std::cout << "\tLocal Pos = " << theSimHit.localPosition()
395 // << "\tProcess = " << theSimHit.processType() << std::endl;
396 // }
397  CFposcachev.push_back(currentAddr);
398  simhitCFPos->push_back(currentAddr);
399  }
400  }
401  }
402  }
403  }
404  else {
405  edm::LogError("TrackerHitAssociator")<<"no cluster reference attached";
406  }
407  }
408 }
409 
410 std::vector<SimHitIdpr> TrackerHitAssociator::associateMatchedRecHit(const SiStripMatchedRecHit2D* matchedrechit, std::vector<simhitAddr>* simhitCFPos) const
411 {
412  std::vector<SimHitIdpr> matched_mono;
413  std::vector<SimHitIdpr> matched_st;
414 
415  const SiStripRecHit2D mono = matchedrechit->monoHit();
416  const SiStripRecHit2D st = matchedrechit->stereoHit();
417  //associate the two simple hits separately
418  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
419  associateSiStripRecHit(&st, matched_st, simhitCFPos);
420 
421  //save in a vector all the simtrack-id's that are common to mono and stereo hits
422  std::vector<SimHitIdpr> simtrackid;
423  if(!matched_mono.empty() && !matched_st.empty()){
424  std::vector<SimHitIdpr> idcachev;
425  for(vector<SimHitIdpr>::iterator mhit=matched_mono.begin(); mhit != matched_mono.end(); mhit++){
426  //save only once the ID
427  if(find(idcachev.begin(), idcachev.end(), (*mhit)) == idcachev.end()) {
428  idcachev.push_back(*mhit);
429  //save if the stereoID matched the monoID
430  if(find(matched_st.begin(), matched_st.end(), (*mhit)) != matched_st.end()) {
431  simtrackid.push_back(*mhit);
432  }
433  }
434  }
435  }
436 
437  return simtrackid;
438 }
439 
440 
441 std::vector<SimHitIdpr> TrackerHitAssociator::associateProjectedRecHit(const ProjectedSiStripRecHit2D * projectedrechit,
442  std::vector<simhitAddr>* simhitCFPos) const
443 {
444  //projectedRecHit is a "matched" rechit with only one component
445 
446  std::vector<SimHitIdpr> matched_mono;
447 
448  const SiStripRecHit2D mono = projectedrechit->originalHit();
449  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
450  return matched_mono;
451 }
452 
454  std::vector<SimHitIdpr> & simtrackid,
455  std::vector<simhitAddr>* simhitCFPos) const
456 {
457  //
458  // Pixel associator
459  //
460  DetId detid= pixelrechit->geographicalId();
461  uint32_t detID = detid.rawId();
462 
464  if(isearch != pixeldigisimlink->end()) { //if it is not empty
465  edm::DetSet<PixelDigiSimLink> link_detset = (*isearch);
466  SiPixelRecHit::ClusterRef const& cluster = pixelrechit->cluster();
467 
468  //check the reference is valid
469 
470  if(!(cluster.isNull())){//if the cluster is valid
471 
472  int minPixelRow = (*cluster).minPixelRow();
473  int maxPixelRow = (*cluster).maxPixelRow();
474  int minPixelCol = (*cluster).minPixelCol();
475  int maxPixelCol = (*cluster).maxPixelCol();
476  //std::cout << " Cluster minRow " << minPixelRow << " maxRow " << maxPixelRow << std::endl;
477  //std::cout << " Cluster minCol " << minPixelCol << " maxCol " << maxPixelCol << std::endl;
478  edm::DetSet<PixelDigiSimLink>::const_iterator linkiter = link_detset.data.begin();
479  int dsl = 0;
480  std::vector<SimHitIdpr> idcachev;
481  std::vector<simhitAddr> CFposcachev;
482  for( ; linkiter != link_detset.data.end(); linkiter++) {
483  dsl++;
484  std::pair<int,int> pixel_coord = PixelDigi::channelToPixel(linkiter->channel());
485  //std::cout << " " << dsl << ") Digi link: row " << pixel_coord.first << " col " << pixel_coord.second << std::endl;
486  if( pixel_coord.first <= maxPixelRow &&
487  pixel_coord.first >= minPixelRow &&
488  pixel_coord.second <= maxPixelCol &&
489  pixel_coord.second >= minPixelCol ) {
490  //std::cout << " !-> trackid " << linkiter->SimTrackId() << endl;
491  //std::cout << " fraction " << linkiter->fraction() << endl;
492  SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
493  if(find(idcachev.begin(),idcachev.end(),currentId) == idcachev.end()){
494  simtrackid.push_back(currentId);
495  idcachev.push_back(currentId);
496  }
497 
498  if (simhitCFPos != 0) {
499  //create a vector that contains all the position (in the MixCollection) of the SimHits that contributed to the RecHit
500  //write position only once
501  unsigned int currentCFPos = linkiter->CFposition();
502  unsigned int tofBin = linkiter->TofBin();
503  simHitCollectionID theSimHitCollID = std::make_pair(detid.subdetId(), tofBin);
504  simhitAddr currentAddr = std::make_pair(theSimHitCollID, currentCFPos);
505 
506  if(find(CFposcachev.begin(), CFposcachev.end(), currentAddr) == CFposcachev.end()) {
507  CFposcachev.push_back(currentAddr);
508  simhitCFPos->push_back(currentAddr);
509  }
510  }
511 
512  }
513  }
514  }
515  else{
516  edm::LogError("TrackerHitAssociator")<<"no Pixel cluster reference attached";
517 
518  }
519  }
520 }
521 
522 std::vector<SimHitIdpr> TrackerHitAssociator::associateGSRecHit(const SiTrackerGSRecHit2D * gsrechit) const
523 {
524  //GSRecHit is the FastSimulation RecHit that contains the TrackId already
525 
526  vector<SimHitIdpr> simtrackid;
527  simtrackid.clear();
528  SimHitIdpr currentId(gsrechit->simtrackId(), EncodedEventId(gsrechit->eeId()));
529  simtrackid.push_back(currentId);
530  return simtrackid;
531 }
532 
533 std::vector<PSimHit> TrackerHitAssociator::associateMultiRecHit(const SiTrackerMultiRecHit * multirechit) const{
534  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
535  // std::vector<PSimHit> assimhits;
536  int size=multirechit->weights().size(), idmostprobable=0;
537 
538  for (int i=0; i<size; i++){
539  if(multirechit->weight(i)>multirechit->weight(idmostprobable)) idmostprobable=i;
540  }
541 
542  return associateHit(*componenthits[idmostprobable]);
543 }
544 
545 std::vector<SimHitIdpr> TrackerHitAssociator::associateMultiRecHitId(const SiTrackerMultiRecHit * multirechit, std::vector<simhitAddr>* simhitCFPos) const{
546  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
547  int size=multirechit->weights().size(), idmostprobable=0;
548 
549  for (int i=0; i<size; i++){
550  if(multirechit->weight(i)>multirechit->weight(idmostprobable)) idmostprobable=i;
551  }
552 
553  std::vector< SimHitIdpr > simhitid;
554  associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
555  return simhitid;
556 }
557 
558 std::vector<SimHitIdpr> TrackerHitAssociator::associateGSMatchedRecHit(const SiTrackerGSMatchedRecHit2D * gsmrechit) const
559 {
560  //GSRecHit is the FastSimulation RecHit that contains the TrackId already
561 
562  vector<SimHitIdpr> simtrackid;
563  simtrackid.clear();
564  SimHitIdpr currentId(gsmrechit->simtrackId(), EncodedEventId(gsmrechit->eeId()));
565  simtrackid.push_back(currentId);
566  return simtrackid;
567 }
568 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:184
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::vector< std::string > vstring
TrackerHitAssociator(const edm::Event &e)
std::pair< simHitCollectionID, unsigned int > simhitAddr
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simhitid, std::vector< simhitAddr > *simhitCFPos=0) const
uint16_t firstStrip() 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:7
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
float weight(unsigned int i) const
const int & simtrackId() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
std::vector< float > const & weights() const
tuple result
Definition: query.py:137
std::vector< SimHitIdpr > associateGSMatchedRecHit(const SiTrackerGSMatchedRecHit2D *gsmrechit) const
EncodedEventId eventId() const
Definition: PSimHit.h:105
#define end
Definition: vmac.h:37
bool first
Definition: L1TdeRCT.cc:75
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
tuple conf
Definition: dbtoconf.py:185
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
void makeMaps(const edm::Event &theEvent, const vstring trackerContainers)
const uint32_t & eeId() const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
T const * product() const
Definition: Handle.h:81
const uint32_t & eeId() const
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:62
tuple simHits
Definition: trackerHits.py:16
collection_type data
Definition: DetSet.h:78
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:30
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
unsigned int trackId() const
Definition: PSimHit.h:102
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
std::vector< SimHitIdpr > associateGSRecHit(const SiTrackerGSRecHit2D *gsrechit) const
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
long double T
std::vector< SimHitIdpr > associateMatchedRecHit(const SiStripMatchedRecHit2D *matchedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
tuple size
Write out results.
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
const std::vector< uint8_t > & amplitudes() const
std::pair< unsigned int, unsigned int > simHitCollectionID
Pixel Reconstructed Hit.