CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes
TrackerHitAssociator Class Reference

#include <TrackerHitAssociator.h>

Classes

struct  Config
 

Public Types

typedef std::map< subDetTofBin, unsigned int > simhit_collectionMap
 
typedef std::map< unsigned int, std::vector< PSimHit > > simhit_map
 
typedef std::pair< unsigned int, unsigned int > simhitAddr
 
typedef unsigned int simHitCollectionID
 
typedef std::pair< unsigned int, unsigned int > subDetTofBin
 

Public Member Functions

void associateCluster (const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< PSimHit > &simhit) const
 
std::vector< SimHitIdprassociateFastRecHit (const FastTrackerRecHit *rechit) const
 
std::vector< PSimHitassociateHit (const TrackingRecHit &thit) const
 
std::vector< SimHitIdprassociateHitId (const TrackingRecHit &thit) const
 
void associateHitId (const TrackingRecHit &thit, std::vector< SimHitIdpr > &simhitid, std::vector< simhitAddr > *simhitCFPos=0) const
 
std::vector< SimHitIdprassociateMatchedRecHit (const SiStripMatchedRecHit2D *matchedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
 
std::vector< PSimHitassociateMultiRecHit (const SiTrackerMultiRecHit *multirechit) const
 
std::vector< SimHitIdprassociateMultiRecHitId (const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=0) const
 
void associatePhase2TrackerRecHit (const Phase2TrackerRecHit1D *rechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
 
void associatePixelRecHit (const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
 
std::vector< SimHitIdprassociateProjectedRecHit (const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
 
void associateSimpleRecHitCluster (const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
 
template<typename T >
void associateSiStripRecHit (const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
 
 TrackerHitAssociator (const edm::Event &e, const Config &config)
 
virtual ~TrackerHitAssociator ()
 

Public Attributes

simhit_collectionMap SimHitCollMap
 
simhit_map SimHitMap
 

Private Types

typedef std::vector< std::string > vstring
 

Private Member Functions

void makeMaps (const edm::Event &theEvent, const Config &config)
 
std::string printDetBnchEvtTrk (const DetId &detid, const uint32_t &detID, std::vector< SimHitIdpr > &simtrackid) const
 

Private Attributes

bool assocHitbySimTrack_
 
bool doPixel_
 
bool doStrip_
 
bool doTrackAssoc_
 
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
 
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
 
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
 
bool useOTph2_
 

Detailed Description

Definition at line 55 of file TrackerHitAssociator.h.

Member Typedef Documentation

Definition at line 106 of file TrackerHitAssociator.h.

typedef std::map<unsigned int, std::vector<PSimHit> > TrackerHitAssociator::simhit_map

Definition at line 104 of file TrackerHitAssociator.h.

typedef std::pair<unsigned int, unsigned int> TrackerHitAssociator::simhitAddr

Definition at line 75 of file TrackerHitAssociator.h.

Definition at line 76 of file TrackerHitAssociator.h.

typedef std::pair<unsigned int, unsigned int> TrackerHitAssociator::subDetTofBin

Definition at line 75 of file TrackerHitAssociator.h.

typedef std::vector<std::string> TrackerHitAssociator::vstring
private

Definition at line 110 of file TrackerHitAssociator.h.

Constructor & Destructor Documentation

TrackerHitAssociator::TrackerHitAssociator ( const edm::Event e,
const Config config 
)

Definition at line 98 of file TrackerHitAssociator.cc.

References doPixel_, doStrip_, doTrackAssoc_, edm::Event::getByToken(), makeMaps(), TrackerHitAssociator::Config::ph2OTrToken_, ph2trackerdigisimlink, pixeldigisimlink, TrackerHitAssociator::Config::pixelToken_, stripdigisimlink, TrackerHitAssociator::Config::stripToken_, and useOTph2_.

98  :
99  doPixel_(config.doPixel_),
100  doStrip_(config.doStrip_),
101  useOTph2_(config.useOTph2_),
102  doTrackAssoc_(config.doTrackAssoc_),
103  assocHitbySimTrack_(config.assocHitbySimTrack_) {
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_) {
110  if (useOTph2_) e.getByToken(config.ph2OTrToken_, ph2trackerdigisimlink);
111  else e.getByToken(config.stripToken_, stripdigisimlink);
112  }
113  if(doPixel_) e.getByToken(config.pixelToken_, pixeldigisimlink);
114 }
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Definition: config.py:1
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
void makeMaps(const edm::Event &theEvent, const Config &config)
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
virtual TrackerHitAssociator::~TrackerHitAssociator ( )
inlinevirtual

Definition at line 73 of file TrackerHitAssociator.h.

73 {}

Member Function Documentation

void TrackerHitAssociator::associateCluster ( const SiStripCluster clust,
const DetId detid,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< PSimHit > &  simhit 
) const

Definition at line 376 of file TrackerHitAssociator.cc.

References associateSimpleRecHitCluster(), LogDebug, and SimHitMap.

379  {
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 }
#define LogDebug(id)
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< SimHitIdpr > TrackerHitAssociator::associateFastRecHit ( const FastTrackerRecHit rechit) const

Definition at line 651 of file TrackerHitAssociator.cc.

References FastTrackerRecHit::nSimTrackIds(), FastTrackerRecHit::simTrackEventId(), and FastTrackerRecHit::simTrackId().

Referenced by associateHitId().

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 }
virtual int32_t simTrackEventId(size_t i) const
virtual int32_t simTrackId(size_t i) const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
virtual size_t nSimTrackIds() const
std::vector< PSimHit > TrackerHitAssociator::associateHit ( const TrackingRecHit thit) const

Check if it's the gluedDet.

Definition at line 200 of file TrackerHitAssociator.cc.

References assocHitbySimTrack_, associateHitId(), associateMultiRecHit(), begin, EncodedEventId::bunchCrossing(), PSimHit::detUnitId(), doTrackAssoc_, end, EncodedEventId::event(), PSimHit::eventId(), plotBeamSpotDB::first, TrackingRecHit::geographicalId(), LogDebug, printDetBnchEvtTrk(), PSimHit::processType(), DetId::rawId(), mps_fire::result, edm::second(), SimHitMap, and PSimHit::trackId().

Referenced by CkfDebugger::analyseCompatibleMeasurements(), SiPixelPhase1RecHitsV::analyze(), SiPixelRecHitsValid::analyze(), TestHits::analyze(), TestSmoothHits::analyze(), TestTrackHits::analyze(), TestOutliers::analyze(), SiPixelErrorEstimation::analyze(), SiPixelTrackingRecHitsValid::analyze(), OverlapValidation::analyze(), CkfDebugger::associated(), associateMultiRecHit(), PixelClusterShapeExtractor::checkSimHits(), CkfDebugger::correctTrajectory(), GlobalRecHitsAnalyzer::fillTrk(), GlobalRecHitsProducer::fillTrk(), spr::matchedSimTrack(), CkfDebugger::nextCorrectHits(), SiStripRecHitsValid::rechitanalysis(), SiStripTrackingRecHitsValid::rechitanalysis(), SiStripRecHitsValid::rechitanalysis_matched(), SiStripTrackingRecHitsValid::rechitanalysis_matched(), and CkfDebugger::testSeed().

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 }
#define LogDebug(id)
int event() const
get the contents of the subdetector field (should be protected?)
std::vector< PSimHit > associateMultiRecHit(const SiTrackerMultiRecHit *multirechit) const
std::string printDetBnchEvtTrk(const DetId &detid, const uint32_t &detID, std::vector< SimHitIdpr > &simtrackid) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
U second(std::pair< T, U > const &p)
int bunchCrossing() const
get the detector field from this detid
EncodedEventId eventId() const
Definition: PSimHit.h:108
#define end
Definition: vmac.h:39
Definition: DetId.h:18
unsigned short processType() const
Definition: PSimHit.h:120
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:32
unsigned int trackId() const
Definition: PSimHit.h:106
DetId geographicalId() const
unsigned int detUnitId() const
Definition: PSimHit.h:97
std::vector< SimHitIdpr > TrackerHitAssociator::associateHitId ( const TrackingRecHit thit) const
void TrackerHitAssociator::associateHitId ( const TrackingRecHit thit,
std::vector< SimHitIdpr > &  simhitid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 329 of file TrackerHitAssociator.cc.

References associateFastRecHit(), associateMatchedRecHit(), associateMultiRecHitId(), associatePhase2TrackerRecHit(), associatePixelRecHit(), associateProjectedRecHit(), associateSiStripRecHit(), and trackerHitRTTI::isFast().

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 }
std::vector< SimHitIdpr > associateMultiRecHitId(const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< SimHitIdpr > associateFastRecHit(const FastTrackerRecHit *rechit) const
bool isFast(TrackingRecHit const &hit)
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
void associatePhase2TrackerRecHit(const Phase2TrackerRecHit1D *rechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
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
Our base class.
Definition: SiPixelRecHit.h:23
std::vector< SimHitIdpr > TrackerHitAssociator::associateMatchedRecHit ( const SiStripMatchedRecHit2D matchedrechit,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 463 of file TrackerHitAssociator.cc.

References associateSiStripRecHit(), spr::find(), SiStripMatchedRecHit2D::monoHit(), and SiStripMatchedRecHit2D::stereoHit().

Referenced by associateHitId().

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 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
SiStripRecHit2D stereoHit() const
SiStripRecHit2D monoHit() const
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< PSimHit > TrackerHitAssociator::associateMultiRecHit ( const SiTrackerMultiRecHit multirechit) const

Definition at line 625 of file TrackerHitAssociator.cc.

References associateHit(), mps_fire::i, SiTrackerMultiRecHit::recHits(), findQualityFiles::size, SiTrackerMultiRecHit::weight(), and SiTrackerMultiRecHit::weights().

Referenced by associateHit().

625  {
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 }
size
Write out results.
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
float weight(unsigned int i) const
std::vector< float > const & weights() const
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
std::vector< SimHitIdpr > TrackerHitAssociator::associateMultiRecHitId ( const SiTrackerMultiRecHit multirechit,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 637 of file TrackerHitAssociator.cc.

References associateHitId(), mps_fire::i, SiTrackerMultiRecHit::recHits(), findQualityFiles::size, SiTrackerMultiRecHit::weight(), and SiTrackerMultiRecHit::weights().

Referenced by associateHitId().

637  {
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 }
size
Write out results.
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
float weight(unsigned int i) const
std::vector< float > const & weights() const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
void TrackerHitAssociator::associatePhase2TrackerRecHit ( const Phase2TrackerRecHit1D rechit,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 502 of file TrackerHitAssociator.cc.

References Phase2TrackerDigi::channelToPixel(), Phase2TrackerRecHit1D::cluster(), spr::find(), TrackingRecHit::geographicalId(), edm::Ref< C, T, F >::isNull(), LogDebug, ph2trackerdigisimlink, DetId::rawId(), SimHitCollMap, and DetId::subdetId().

Referenced by associateHitId().

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 }
#define LogDebug(id)
std::pair< unsigned int, unsigned int > simhitAddr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
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
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
bool isNull() const
Checks for null.
Definition: Ref.h:248
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
std::pair< uint32_t, EncodedEventId > SimHitIdpr
DetId geographicalId() const
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
void TrackerHitAssociator::associatePixelRecHit ( const SiPixelRecHit pixelrechit,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 561 of file TrackerHitAssociator.cc.

References PixelDigi::channelToPixel(), SiPixelRecHit::cluster(), spr::find(), TrackingRecHit::geographicalId(), edm::Ref< C, T, F >::isNull(), LogDebug, pixeldigisimlink, DetId::rawId(), SimHitCollMap, and DetId::subdetId().

Referenced by associateHitId().

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 }
#define LogDebug(id)
std::pair< unsigned int, unsigned int > simhitAddr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
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
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
bool isNull() const
Checks for null.
Definition: Ref.h:248
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
std::pair< uint32_t, EncodedEventId > SimHitIdpr
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:62
DetId geographicalId() const
std::vector< SimHitIdpr > TrackerHitAssociator::associateProjectedRecHit ( const ProjectedSiStripRecHit2D projectedrechit,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 490 of file TrackerHitAssociator.cc.

References associateSiStripRecHit(), and ProjectedSiStripRecHit2D::originalHit().

Referenced by associateHitId().

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 }
SiStripRecHit2D originalHit() const
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
void TrackerHitAssociator::associateSimpleRecHitCluster ( const SiStripCluster clust,
const DetId detid,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 401 of file TrackerHitAssociator.cc.

References SiStripCluster::amplitudes(), spr::find(), plotBeamSpotDB::first, SiStripCluster::firstStrip(), createfilelist::int, plotBeamSpotDB::last, LogDebug, DetId::rawId(), SimHitCollMap, stripdigisimlink, and DetId::subdetId().

Referenced by associateCluster(), and associateSiStripRecHit().

404  {
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 }
#define LogDebug(id)
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
std::pair< unsigned int, unsigned int > simhitAddr
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
uint16_t firstStrip() const
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
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
simhit_collectionMap SimHitCollMap
std::pair< uint32_t, EncodedEventId > SimHitIdpr
const std::vector< uint8_t > & amplitudes() const
template<typename T >
void TrackerHitAssociator::associateSiStripRecHit ( const T simplerechit,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const
inline

Definition at line 367 of file TrackerHitAssociator.cc.

References associateSimpleRecHitCluster().

Referenced by associateHitId(), associateMatchedRecHit(), and associateProjectedRecHit().

368 {
369  const SiStripCluster* clust = &(*simplerechit->cluster());
370  associateSimpleRecHitCluster(clust, simplerechit->geographicalId(), simtrackid, simhitCFPos);
371 }
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
void TrackerHitAssociator::makeMaps ( const edm::Event theEvent,
const Config config 
)
private

Definition at line 116 of file TrackerHitAssociator.cc.

References assocHitbySimTrack_, TrackerHitAssociator::Config::cfTokens_, edm::Event::getByToken(), StripDigiSimLink::HighTof, tablePrinter::labels, edm::Event::labelsForToken(), LogDebug, StripDigiSimLink::LowTof, edm::Handle< T >::product(), edm::ProductLabels::productInstance, SimHitCollMap, SimHitMap, trackerHits::simHits, SiPixelPhase1TrackingParticleV_cfi::simHitToken, and TrackerHitAssociator::Config::simHitTokens_.

Referenced by TrackerHitAssociator().

116  {
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 }
#define LogDebug(id)
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: Event.h:243
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Definition: config.py:1
std::pair< unsigned int, unsigned int > subDetTofBin
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:74
char const * productInstance
Definition: ProductLabels.h:6
std::string TrackerHitAssociator::printDetBnchEvtTrk ( const DetId detid,
const uint32_t &  detID,
std::vector< SimHitIdpr > &  simtrackid 
) const
inlineprivate

Definition at line 662 of file TrackerHitAssociator.cc.

References mps_fire::i, edm::second(), and DetId::subdetId().

Referenced by associateHit().

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 }
U second(std::pair< T, U > const &p)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41

Member Data Documentation

bool TrackerHitAssociator::assocHitbySimTrack_
private

Definition at line 117 of file TrackerHitAssociator.h.

Referenced by associateHit(), and makeMaps().

bool TrackerHitAssociator::doPixel_
private

Definition at line 117 of file TrackerHitAssociator.h.

Referenced by TrackerHitAssociator().

bool TrackerHitAssociator::doStrip_
private

Definition at line 117 of file TrackerHitAssociator.h.

Referenced by TrackerHitAssociator().

bool TrackerHitAssociator::doTrackAssoc_
private

Definition at line 117 of file TrackerHitAssociator.h.

Referenced by associateHit(), and TrackerHitAssociator().

edm::Handle< edm::DetSetVector<PixelDigiSimLink> > TrackerHitAssociator::ph2trackerdigisimlink
private

Definition at line 116 of file TrackerHitAssociator.h.

Referenced by associatePhase2TrackerRecHit(), and TrackerHitAssociator().

edm::Handle< edm::DetSetVector<PixelDigiSimLink> > TrackerHitAssociator::pixeldigisimlink
private

Definition at line 115 of file TrackerHitAssociator.h.

Referenced by associatePixelRecHit(), and TrackerHitAssociator().

simhit_collectionMap TrackerHitAssociator::SimHitCollMap
simhit_map TrackerHitAssociator::SimHitMap
edm::Handle< edm::DetSetVector<StripDigiSimLink> > TrackerHitAssociator::stripdigisimlink
private

Definition at line 114 of file TrackerHitAssociator.h.

Referenced by associateSimpleRecHitCluster(), and TrackerHitAssociator().

bool TrackerHitAssociator::useOTph2_
private

Definition at line 117 of file TrackerHitAssociator.h.

Referenced by TrackerHitAssociator().