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