CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
< simHitCollectionID,
std::vector< PSimHit > > 
simhit_collectionMap
 
typedef std::map< unsigned int,
std::vector< PSimHit > > 
simhit_map
 
typedef std::pair
< simHitCollectionID, unsigned
int > 
simhitAddr
 
typedef std::pair< unsigned
int, unsigned int > 
simHitCollectionID
 

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 associatePixelRecHit (const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simhitid, 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)
 

Private Attributes

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

Detailed Description

Definition at line 54 of file TrackerHitAssociator.h.

Member Typedef Documentation

Definition at line 103 of file TrackerHitAssociator.h.

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

Definition at line 101 of file TrackerHitAssociator.h.

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

Definition at line 74 of file TrackerHitAssociator.h.

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

Definition at line 73 of file TrackerHitAssociator.h.

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

Definition at line 107 of file TrackerHitAssociator.h.

Constructor & Destructor Documentation

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

Definition at line 83 of file TrackerHitAssociator.cc.

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

83  :
84  doPixel_(config.doPixel_),
85  doStrip_(config.doStrip_),
86  doTrackAssoc_(config.doTrackAssoc_),
87  assocHitbySimTrack_(config.assocHitbySimTrack_) {
88  //if track association there is no need to access the input collections
89  if(!doTrackAssoc_) {
90  makeMaps(e, config);
91  }
92 
93  if(doStrip_) e.getByToken(config.stripToken_, stripdigisimlink);
94  if(doPixel_) e.getByToken(config.pixelToken_, pixeldigisimlink);
95 }
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
void makeMaps(const edm::Event &theEvent, const Config &config)
virtual TrackerHitAssociator::~TrackerHitAssociator ( )
inlinevirtual

Definition at line 71 of file TrackerHitAssociator.h.

71 {}

Member Function Documentation

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

Definition at line 390 of file TrackerHitAssociator.cc.

References associateSimpleRecHitCluster(), and SimHitCollMap.

393  {
394  std::vector<simhitAddr> simhitCFPos;
395  associateSimpleRecHitCluster(clust, detid, simtrackid, &simhitCFPos);
396 
397  for(auto const& theSimHitAddr : simhitCFPos ) {
398  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
399  simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
400  if (it!= SimHitCollMap.end()) {
401  unsigned int theSimHitIndex = theSimHitAddr.second;
402  if (theSimHitIndex < (it->second).size()) simhit.push_back((it->second)[theSimHitIndex]);
403  // const PSimHit& theSimHit = (it->second)[theSimHitIndex];
404  // std::cout << "For cluster, simHit detId = " << theSimHit.detUnitId() << " address = (" << (theSimHitAddr.first).first
405  // << ", " << (theSimHitAddr.first).second << ", " << theSimHitIndex
406  // << "), process = " << theSimHit.processType() << " (" << theSimHit.eventId().bunchCrossing()
407  // << ", " << theSimHit.eventId().event() << ", " << theSimHit.trackId() << ")" << std::endl;
408  }
409  }
410 }
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
simhit_collectionMap SimHitCollMap
std::pair< unsigned int, unsigned int > simHitCollectionID
std::vector< SimHitIdpr > TrackerHitAssociator::associateFastRecHit ( const FastTrackerRecHit rechit) const

Definition at line 632 of file TrackerHitAssociator.cc.

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

Referenced by associateHitId().

633 {
634  vector<SimHitIdpr> simtrackid;
635  simtrackid.clear();
636  for(size_t index =0, indexEnd = rechit->nSimTrackIds();index<indexEnd;++index){
637  SimHitIdpr currentId(rechit->simTrackId(index), EncodedEventId(rechit->simTrackEventId(index)));
638  simtrackid.push_back(currentId);
639  }
640  return simtrackid;
641 }
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 175 of file TrackerHitAssociator.cc.

References assocHitbySimTrack_, associateHitId(), associateMultiRecHit(), begin, cond::rpcobgas::detid, doTrackAssoc_, end, PSimHit::eventId(), plotBeamSpotDB::first, TrackingRecHit::geographicalId(), DetId::rawId(), query::result, edm::second(), SimHitCollMap, SimHitMap, and PSimHit::trackId().

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

176 {
177 
178  if (const SiTrackerMultiRecHit * rechit = dynamic_cast<const SiTrackerMultiRecHit *>(&thit)){
179  return associateMultiRecHit(rechit);
180  }
181 
182  //vector with the matched SimHit
183  std::vector<PSimHit> result;
184 
185  if(doTrackAssoc_) return result;
186 
187  // Vectors to contain lists of matched simTracks, simHits
188  std::vector<SimHitIdpr> simtrackid;
189  std::vector<simhitAddr> simhitCFPos;
190 
191  //get the Detector type of the rechit
192  DetId detid= thit.geographicalId();
193  uint32_t detID = detid.rawId();
194 
195  // Get the vectors of simtrackIDs and simHit indices associated with this rechit
196  associateHitId(thit, simtrackid, &simhitCFPos);
197  // std::cout << "recHit subdet, detID = " << detid.subdetId() << ", " << detID << ", (bnch, evt, trk) = ";
198  // for (size_t i=0; i<simtrackid.size(); ++i)
199  // std::cout << ", (" << simtrackid[i].second.bunchCrossing() << ", "
200  // << simtrackid[i].second.event() << ", " << simtrackid[i].first << ")";
201  // std::cout << std::endl;
202 
203  // Get the vector of simHits associated with this rechit
204 
205  if (!assocHitbySimTrack_ && simhitCFPos.size() > 0) {
206  // We use the indices to the simHit collections taken
207  // from the DigiSimLinks and returned in simhitCFPos.
208  // simhitCFPos[i] contains the full address of the ith simhit:
209  // <collection, index> = <<subdet, tofBin>, index>
210 
211  //check if the recHit is a SiStripMatchedRecHit2D
212  if(dynamic_cast<const SiStripMatchedRecHit2D *>(&thit)) {
213  for(auto const& theSimHitAddr : simhitCFPos) {
214  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
215  simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
216  if (it!= SimHitCollMap.end()) {
217  unsigned int theSimHitIndex = theSimHitAddr.second;
218  if (theSimHitIndex < (it->second).size()) {
219  const PSimHit& theSimHit = (it->second)[theSimHitIndex];
220  // Try to remove ghosts by requiring a match to the simTrack also
221  unsigned int simHitid = theSimHit.trackId();
222  EncodedEventId simHiteid = theSimHit.eventId();
223  for(auto const& id : simtrackid) {
224  if(simHitid == id.first && simHiteid == id.second) {
225  result.push_back(theSimHit);
226  }
227  }
228  // std::cout << "by CFpos, simHit detId = " << theSimHit.detUnitId() << " address = (" << (theSimHitAddr.first).first
229  // << ", " << (theSimHitAddr.first).second << ", " << theSimHitIndex
230  // << "), process = " << theSimHit.processType() << " (" << theSimHit.eventId().bunchCrossing()
231  // << ", " << theSimHit.eventId().event() << ", " << theSimHit.trackId() << ")" << std::endl;
232  }
233  }
234  }
235  } else {
236  for(auto const& theSimHitAddr : simhitCFPos) {
237  simHitCollectionID theSimHitCollID = theSimHitAddr.first;
238  simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
239  if (it!= SimHitCollMap.end()) {
240  unsigned int theSimHitIndex = theSimHitAddr.second;
241  if (theSimHitIndex < (it->second).size()) {
242  result.push_back((it->second)[theSimHitIndex]);
243  // std::cout << "by CFpos, simHit detId = " << theSimHit.detUnitId() << " address = (" << (theSimHitAddr.first).first
244  // << ", " << (theSimHitAddr.first).second << ", " << theSimHitIndex
245  // << "), process = " << theSimHit.processType() << " (" << theSimHit.eventId().bunchCrossing()
246  // << ", " << theSimHit.eventId().event() << ", " << theSimHit.trackId() << ")" << std::endl;
247  }
248  }
249  }
250  }
251  return result;
252  }
253 
254  // Get the SimHit from the trackid instead
255  std::map<unsigned int, std::vector<PSimHit> >::const_iterator it = SimHitMap.find(detID);
256  if (it!= SimHitMap.end()) {
257  vector<PSimHit>::const_iterator simHitIter = (it->second).begin();
258  vector<PSimHit>::const_iterator simHitIterEnd = (it->second).end();
259  for (;simHitIter != simHitIterEnd; ++simHitIter) {
260  const PSimHit& ihit = *simHitIter;
261  unsigned int simHitid = ihit.trackId();
262  EncodedEventId simHiteid = ihit.eventId();
263  // std::cout << "by simTk, simHit, process = " << ihit.processType() << " (" << ihit.eventId().bunchCrossing()
264  // << ", " << ihit.eventId().event() << ", " << ihit.trackId() << ")";
265  for(auto id : simtrackid) {
266  if(simHitid == id.first && simHiteid == id.second) {
267 // cout << "Associator ---> ID" << ihit.trackId() << " Simhit x= " << ihit.localPosition().x()
268 // << " y= " << ihit.localPosition().y() << " z= " << ihit.localPosition().x() << endl;
269  // std::cout << " matches";
270  result.push_back(ihit);
271  break;
272  }
273  }
274  // std::cout << std::endl;
275  }
276 
277  }else{
278 
280  std::map<unsigned int, std::vector<PSimHit> >::const_iterator itrphi =
281  SimHitMap.find(detID+2); //iterator to the simhit in the rphi module
282  std::map<unsigned int, std::vector<PSimHit> >::const_iterator itster =
283  SimHitMap.find(detID+1);//iterator to the simhit in the stereo module
284  if (itrphi!= SimHitMap.end()&&itster!=SimHitMap.end()) {
285  std::vector<PSimHit> simHitVector = itrphi->second;
286  simHitVector.insert(simHitVector.end(),(itster->second).begin(),(itster->second).end());
287  vector<PSimHit>::const_iterator simHitIter = simHitVector.begin();
288  vector<PSimHit>::const_iterator simHitIterEnd = simHitVector.end();
289  for (;simHitIter != simHitIterEnd; ++simHitIter) {
290  const PSimHit& ihit = *simHitIter;
291  unsigned int simHitid = ihit.trackId();
292  EncodedEventId simHiteid = ihit.eventId();
293  for(auto const& id : simtrackid) {
294  if(simHitid == id.first && simHiteid == id.second) {
295 // if(simHitid == simtrackid[i].first && simHiteid.bunchCrossing() == simtrackid[i].second.bunchCrossing()) {
296  // cout << "GluedDet Associator ---> ID" << ihit.trackId() << " Simhit x= " << ihit.localPosition().x()
297  // << " y= " << ihit.localPosition().y() << " z= " << ihit.localPosition().x() << endl;
298  result.push_back(ihit);
299  break;
300  }
301  }
302  }
303  }
304  }
305 
306  return result;
307 }
std::vector< PSimHit > associateMultiRecHit(const SiTrackerMultiRecHit *multirechit) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
tuple result
Definition: query.py:137
EncodedEventId eventId() const
Definition: PSimHit.h:105
#define end
Definition: vmac.h:37
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
#define begin
Definition: vmac.h:30
unsigned int trackId() const
Definition: PSimHit.h:102
DetId geographicalId() const
std::pair< unsigned int, unsigned int > simHitCollectionID
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 316 of file TrackerHitAssociator.cc.

References associateFastRecHit(), associateMatchedRecHit(), associateMultiRecHitId(), associatePixelRecHit(), associateProjectedRecHit(), associateSiStripRecHit(), cond::rpcobgas::detid, TrackingRecHit::geographicalId(), trackerHitRTTI::isFast(), PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, DetId::subdetId(), StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, and StripSubdetector::TOB.

318 {
319 
320  simtkid.clear();
321 
322  //get the Detector type of the rechit
323  DetId detid= thit.geographicalId();
324  if (const SiTrackerMultiRecHit * rechit = dynamic_cast<const SiTrackerMultiRecHit *>(&thit)){
325  simtkid=associateMultiRecHitId(rechit, simhitCFPos);
326  }
327 
328  //cout << "Associator ---> get Detid " << detID << endl;
329  //check we are in the strip tracker
330  if(detid.subdetId() == StripSubdetector::TIB ||
331  detid.subdetId() == StripSubdetector::TOB ||
332  detid.subdetId() == StripSubdetector::TID ||
333  detid.subdetId() == StripSubdetector::TEC)
334  {
335  //check if it is a simple SiStripRecHit2D
336  if(const SiStripRecHit2D * rechit =
337  dynamic_cast<const SiStripRecHit2D *>(&thit))
338  {
339  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
340  }
341  //check if it is a SiStripRecHit1D
342  else if(const SiStripRecHit1D * rechit =
343  dynamic_cast<const SiStripRecHit1D *>(&thit))
344  {
345  associateSiStripRecHit(rechit, simtkid, simhitCFPos);
346  }
347  //check if it is a SiStripMatchedRecHit2D
348  else if(const SiStripMatchedRecHit2D * rechit =
349  dynamic_cast<const SiStripMatchedRecHit2D *>(&thit))
350  {
351  simtkid = associateMatchedRecHit(rechit, simhitCFPos);
352  }
353  //check if it is a ProjectedSiStripRecHit2D
354  else if(const ProjectedSiStripRecHit2D * rechit =
355  dynamic_cast<const ProjectedSiStripRecHit2D *>(&thit))
356  {
357  simtkid = associateProjectedRecHit(rechit, simhitCFPos);
358  }
359  else{
360  //std::cout << "associate to invalid" << std::endl;
361  //throw cms::Exception("Unknown RecHit Type") << "TrackerHitAssociator failed second casting of " << typeid(thit).name() << " type ";
362  }
363  }
364  //check we are in the pixel tracker
365  else if( (unsigned int)(detid.subdetId()) == PixelSubdetector::PixelBarrel ||
366  (unsigned int)(detid.subdetId()) == PixelSubdetector::PixelEndcap)
367  {
368  if(const SiPixelRecHit * rechit = dynamic_cast<const SiPixelRecHit *>(&thit))
369  {
370  associatePixelRecHit(rechit, simtkid, simhitCFPos);
371  }
372  }
373  //check if these are GSRecHits (from FastSim)
374  if(trackerHitRTTI::isFast(thit))
375  {
376  simtkid = associateFastRecHit(static_cast<const FastTrackerRecHit *>(&thit));
377  }
378 }
std::vector< SimHitIdpr > associateMultiRecHitId(const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=0) const
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simhitid, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< SimHitIdpr > associateFastRecHit(const FastTrackerRecHit *rechit) const
bool isFast(TrackingRecHit const &hit)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
DetId geographicalId() 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 494 of file TrackerHitAssociator.cc.

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

Referenced by associateHitId().

495 {
496  std::vector<SimHitIdpr> matched_mono;
497  std::vector<SimHitIdpr> matched_st;
498 
499  const SiStripRecHit2D mono = matchedrechit->monoHit();
500  const SiStripRecHit2D st = matchedrechit->stereoHit();
501  //associate the two simple hits separately
502  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
503  associateSiStripRecHit(&st, matched_st, simhitCFPos);
504 
505  //save in a vector all the simtrack-id's that are common to mono and stereo hits
506  std::vector<SimHitIdpr> simtrackid;
507  if(!(matched_mono.empty() || matched_st.empty())){
508  std::vector<SimHitIdpr> idcachev;
509  for(auto const& mhit: matched_mono){
510  //save only once the ID
511  if(find(idcachev.begin(), idcachev.end(), mhit) == idcachev.end()) {
512  idcachev.push_back(mhit);
513  //save if the stereoID matched the monoID
514  if(find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
515  simtrackid.push_back(mhit);
516  }
517  }
518  }
519  }
520 
521  return simtrackid;
522 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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 606 of file TrackerHitAssociator.cc.

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

Referenced by associateHit().

606  {
607  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
608  // std::vector<PSimHit> assimhits;
609  int size=multirechit->weights().size(), idmostprobable=0;
610 
611  for (int i=0; i<size; ++i){
612  if(multirechit->weight(i)>multirechit->weight(idmostprobable)) idmostprobable=i;
613  }
614 
615  return associateHit(*componenthits[idmostprobable]);
616 }
int i
Definition: DBlmapReader.cc:9
float weight(unsigned int i) const
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
std::vector< float > const & weights() const
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
tuple size
Write out results.
std::vector< SimHitIdpr > TrackerHitAssociator::associateMultiRecHitId ( const SiTrackerMultiRecHit multirechit,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 618 of file TrackerHitAssociator.cc.

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

Referenced by associateHitId().

618  {
619  std::vector<const TrackingRecHit*> componenthits = multirechit->recHits();
620  int size=multirechit->weights().size(), idmostprobable=0;
621 
622  for (int i=0; i<size; ++i){
623  if(multirechit->weight(i)>multirechit->weight(idmostprobable)) idmostprobable=i;
624  }
625 
626  std::vector< SimHitIdpr > simhitid;
627  associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
628  return simhitid;
629 }
int i
Definition: DBlmapReader.cc:9
float weight(unsigned int i) const
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
std::vector< float > const & weights() const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
tuple size
Write out results.
void TrackerHitAssociator::associatePixelRecHit ( const SiPixelRecHit pixelrechit,
std::vector< SimHitIdpr > &  simhitid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 537 of file TrackerHitAssociator.cc.

References PixelDigi::channelToPixel(), SiPixelRecHit::cluster(), edm::DetSet< T >::data, cond::rpcobgas::detid, spr::find(), TrackingRecHit::geographicalId(), edm::Ref< C, T, F >::isNull(), pixeldigisimlink, DetId::rawId(), and DetId::subdetId().

Referenced by associateHitId().

540 {
541  //
542  // Pixel associator
543  //
544  DetId detid= pixelrechit->geographicalId();
545  uint32_t detID = detid.rawId();
546 
548  if(isearch != pixeldigisimlink->end()) { //if it is not empty
549  edm::DetSet<PixelDigiSimLink> link_detset = (*isearch);
550  SiPixelRecHit::ClusterRef const& cluster = pixelrechit->cluster();
551 
552  //check the reference is valid
553 
554  if(!(cluster.isNull())){//if the cluster is valid
555 
556  int minPixelRow = (*cluster).minPixelRow();
557  int maxPixelRow = (*cluster).maxPixelRow();
558  int minPixelCol = (*cluster).minPixelCol();
559  int maxPixelCol = (*cluster).maxPixelCol();
560  //std::cout << " Cluster minRow " << minPixelRow << " maxRow " << maxPixelRow << std::endl;
561  //std::cout << " Cluster minCol " << minPixelCol << " maxCol " << maxPixelCol << std::endl;
562  edm::DetSet<PixelDigiSimLink>::const_iterator linkiter = link_detset.data.begin(), linkEnd = link_detset.data.end();
563  int dsl = 0;
564  std::vector<SimHitIdpr> idcachev;
565  std::vector<simhitAddr> CFposcachev;
566  for( ; linkiter != linkEnd; ++linkiter) {
567  ++dsl;
568  std::pair<int,int> pixel_coord = PixelDigi::channelToPixel(linkiter->channel());
569  //std::cout << " " << dsl << ") Digi link: row " << pixel_coord.first << " col " << pixel_coord.second << std::endl;
570  if( pixel_coord.first <= maxPixelRow &&
571  pixel_coord.first >= minPixelRow &&
572  pixel_coord.second <= maxPixelCol &&
573  pixel_coord.second >= minPixelCol ) {
574  //std::cout << " !-> trackid " << linkiter->SimTrackId() << endl;
575  //std::cout << " fraction " << linkiter->fraction() << endl;
576  SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
577  if(find(idcachev.begin(),idcachev.end(),currentId) == idcachev.end()){
578  simtrackid.push_back(currentId);
579  idcachev.push_back(currentId);
580  }
581 
582  if (simhitCFPos != 0) {
583  //create a vector that contains all the position (in the MixCollection) of the SimHits that contributed to the RecHit
584  //write position only once
585  unsigned int currentCFPos = linkiter->CFposition();
586  unsigned int tofBin = linkiter->TofBin();
587  simHitCollectionID theSimHitCollID = std::make_pair(detid.subdetId(), tofBin);
588  simhitAddr currentAddr = std::make_pair(theSimHitCollID, currentCFPos);
589 
590  if(find(CFposcachev.begin(), CFposcachev.end(), currentAddr) == CFposcachev.end()) {
591  CFposcachev.push_back(currentAddr);
592  simhitCFPos->push_back(currentAddr);
593  }
594  }
595 
596  }
597  }
598  }
599  else{
600  edm::LogError("TrackerHitAssociator")<<"no Pixel cluster reference attached";
601 
602  }
603  }
604 }
std::pair< simHitCollectionID, unsigned int > simhitAddr
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
bool isNull() const
Checks for null.
Definition: Ref.h:249
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
collection_type data
Definition: DetSet.h:78
DetId geographicalId() const
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
std::pair< unsigned int, unsigned int > simHitCollectionID
std::vector< SimHitIdpr > TrackerHitAssociator::associateProjectedRecHit ( const ProjectedSiStripRecHit2D projectedrechit,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const

Definition at line 525 of file TrackerHitAssociator.cc.

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

Referenced by associateHitId().

527 {
528  //projectedRecHit is a "matched" rechit with only one component
529 
530  std::vector<SimHitIdpr> matched_mono;
531 
532  const SiStripRecHit2D mono = projectedrechit->originalHit();
533  associateSiStripRecHit(&mono, matched_mono, simhitCFPos);
534  return matched_mono;
535 }
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 412 of file TrackerHitAssociator.cc.

References SiStripCluster::amplitudes(), edm::DetSet< T >::data, spr::find(), plotBeamSpotDB::first, SiStripCluster::firstStrip(), prof2calltree::last, DetId::rawId(), stripdigisimlink, and DetId::subdetId().

Referenced by associateCluster(), and associateSiStripRecHit().

415  {
416 
417  uint32_t detID = detid.rawId();
419  if(isearch != stripdigisimlink->end()) { //if it is not empty
420  edm::DetSet<StripDigiSimLink> link_detset = (*isearch);
421 
422  if(clust!=0){//the cluster is valid
423  int clusiz = clust->amplitudes().size();
424  int first = clust->firstStrip();
425  int last = first + clusiz;
426 
427 // std::cout << "CLUSTERSIZE " << clusiz << " first strip = " << first << " last strip = " << last-1 << std::endl;
428 // std::cout << " detID = " << detID << " DETSET size = " << link_detset.data.size() << std::endl;
429  //use a vector
430  std::vector<SimHitIdpr> idcachev;
431  std::vector<simhitAddr> CFposcachev;
432  int channel;
433 // for(auto linkiter : link_detset.data){
434  for(edm::DetSet<StripDigiSimLink>::const_iterator linkiter = link_detset.data.begin(), linkerEnd = link_detset.data.end(); linkiter != linkerEnd; ++linkiter){
435  channel = (int)(linkiter->channel());
436  if( channel >= first && channel < last ){
437 
438  //check this digisimlink
439 // printf("%s%4d%s%8d%s%3d%s%8.4f\n", "CHANNEL = ", linkiter->channel(), " TrackID = ", linkiter->SimTrackId(),
440 // " tofBin = ", linkiter->TofBin(), " fraction = ", linkiter->fraction());
441  /*
442  std::cout << "CHECKING CHANNEL = " << linkiter->channel() << std::endl;
443  std::cout << "TrackID = " << linkiter->SimTrackId() << std::endl;
444  std::cout << "Position = " << linkiter->CFposition() << std::endl;
445  std::cout << " fraction = " << linkiter->fraction() << std::endl;
446  */
447 
448  SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
449 
450  //create a vector with the list of SimTrack ID's of the tracks that contributed to the RecHit
451  //write the id only once in the vector
452 
453  if(find(idcachev.begin(),idcachev.end(),currentId ) == idcachev.end()){
454  /*
455  std::cout << " Adding track id = " << currentId.first
456  << " Event id = " << currentId.second.event()
457  << " Bunch Xing = " << currentId.second.bunchCrossing()
458  << std::endl;
459  */
460  idcachev.push_back(currentId);
461  simtrackid.push_back(currentId);
462  }
463 
464  if (simhitCFPos != 0) {
465  //create a vector that contains all the position (in the MixCollection) of the SimHits that contributed to the RecHit
466  //write position only once
467  unsigned int currentCFPos = linkiter->CFposition();
468  unsigned int tofBin = linkiter->TofBin();
469  simHitCollectionID theSimHitCollID = std::make_pair(detid.subdetId(), tofBin);
470  simhitAddr currentAddr = std::make_pair(theSimHitCollID, currentCFPos);
471 
472  if(find(CFposcachev.begin(), CFposcachev.end(), currentAddr ) == CFposcachev.end()) {
473 // std::cout << "CHECKING CHANNEL = " << linkiter->channel() << std::endl;
474 // std::cout << "\tTrackID = " << linkiter->SimTrackId() << "\tCFPos = " << currentCFPos <<"\ttofBin = " << tofBin << std::endl;
475 // simhit_collectionMap::const_iterator it = SimHitCollMap.find(theSimHitCollID);
476 // if (it!= SimHitCollMap.end()) {
477 // PSimHit theSimHit = it->second[currentCFPos];
478 // std::cout << "\tLocal Pos = " << theSimHit.localPosition()
479 // << "\tProcess = " << theSimHit.processType() << std::endl;
480 // }
481  CFposcachev.push_back(currentAddr);
482  simhitCFPos->push_back(currentAddr);
483  }
484  }
485  }
486  }
487  }
488  else {
489  edm::LogError("TrackerHitAssociator")<<"no cluster reference attached";
490  }
491  }
492 }
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
std::pair< simHitCollectionID, unsigned int > simhitAddr
uint16_t firstStrip() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::pair< uint32_t, EncodedEventId > SimHitIdpr
collection_type data
Definition: DetSet.h:78
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
const std::vector< uint8_t > & amplitudes() const
std::pair< unsigned int, unsigned int > simHitCollectionID
template<typename T >
void TrackerHitAssociator::associateSiStripRecHit ( const T simplerechit,
std::vector< SimHitIdpr > &  simtrackid,
std::vector< simhitAddr > *  simhitCFPos = 0 
) const
inline

Definition at line 381 of file TrackerHitAssociator.cc.

References associateSimpleRecHitCluster().

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

382 {
383  const SiStripCluster* clust = &(*simplerechit->cluster());
384  associateSimpleRecHitCluster(clust, simplerechit->geographicalId(), simtrackid, simhitCFPos);
385 }
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 97 of file TrackerHitAssociator.cc.

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

Referenced by TrackerHitAssociator().

97  {
98  // Step A: Get Inputs
99  // The collections are specified via ROUList in the configuration, and can
100  // be either crossing frames (e.g., mix/g4SimHitsTrackerHitsTIBLowTof)
101  // or just PSimHits (e.g., g4SimHits/TrackerHitsTIBLowTof)
102  if (assocHitbySimTrack_) {
103  for(auto const& cfToken : config.cfTokens_) {
105  //int Nhits = 0;
106  if (theEvent.getByToken(cfToken, cf_simhit)) {
107  std::unique_ptr<MixCollection<PSimHit> > thisContainerHits(new MixCollection<PSimHit>(cf_simhit.product()));
108  for (auto const& isim : *thisContainerHits) {
109  DetId theDet(isim.detUnitId());
110  SimHitMap[theDet].push_back(isim);
111  // ++Nhits;
112  }
113  // std::cout << "simHits from crossing frames; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
114  }
115  }
116  for(auto const& simHitToken : config.simHitTokens_) {
118  //int Nhits = 0;
119  if(theEvent.getByToken(simHitToken, simHits)) {
120  for (auto const& isim : *simHits) {
121  DetId theDet(isim.detUnitId());
122  SimHitMap[theDet].push_back(isim);
123  //++Nhits;
124  }
125  // std::cout << "simHits from prompt collections; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
126  }
127  }
128  } else {
129  const char* const highTag = "HighTof";
130  unsigned int tofBin;
132  simHitCollectionID theSimHitCollID;
133  for(auto const& cfToken : config.cfTokens_) {
135  //int Nhits = 0;
136  if (theEvent.getByToken(cfToken, cf_simhit)) {
137  std::unique_ptr<MixCollection<PSimHit> > thisContainerHits(new MixCollection<PSimHit>(cf_simhit.product()));
138  theEvent.labelsForToken(cfToken, labels);
139  if(std::strstr(labels.productInstance, highTag) != NULL) {
140  tofBin = StripDigiSimLink::HighTof;
141  } else {
142  tofBin = StripDigiSimLink::LowTof;
143  }
144  for (auto const& isim : *thisContainerHits) {
145  DetId theDet(isim.detUnitId());
146  theSimHitCollID = std::make_pair(theDet.subdetId(), tofBin);
147  SimHitCollMap[theSimHitCollID].push_back(isim);
148  //++Nhits;
149  }
150  // std::cout << "simHits from crossing frames; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
151  }
152  }
153  for(auto const& simHitToken : config.simHitTokens_) {
155  //int Nhits = 0;
156  if(theEvent.getByToken(simHitToken, simHits)) {
157  theEvent.labelsForToken(simHitToken, labels);
158  if(std::strstr(labels.productInstance, highTag) != NULL) {
159  tofBin = StripDigiSimLink::HighTof;
160  } else {
161  tofBin = StripDigiSimLink::LowTof;
162  }
163  for (auto const& isim : *simHits) {
164  DetId theDet(isim.detUnitId());
165  theSimHitCollID = std::make_pair(theDet.subdetId(), tofBin);
166  SimHitCollMap[theSimHitCollID].push_back(isim);
167  //++Nhits;
168  }
169  // std::cout << "simHits from prompt collections; map size = " << SimHitCollMap.size() << ", Hit count = " << Nhits << std::endl;
170  }
171  }
172  }
173 }
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
Definition: Event.h:226
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define NULL
Definition: scimark2.h:8
simhit_collectionMap SimHitCollMap
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
tuple simHits
Definition: trackerHits.py:16
char const * productInstance
Definition: ProductLabels.h:6
std::pair< unsigned int, unsigned int > simHitCollectionID

Member Data Documentation

bool TrackerHitAssociator::assocHitbySimTrack_
private

Definition at line 112 of file TrackerHitAssociator.h.

Referenced by associateHit(), and makeMaps().

bool TrackerHitAssociator::doPixel_
private

Definition at line 112 of file TrackerHitAssociator.h.

Referenced by TrackerHitAssociator().

bool TrackerHitAssociator::doStrip_
private

Definition at line 112 of file TrackerHitAssociator.h.

Referenced by TrackerHitAssociator().

bool TrackerHitAssociator::doTrackAssoc_
private

Definition at line 112 of file TrackerHitAssociator.h.

Referenced by associateHit(), and TrackerHitAssociator().

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

Definition at line 111 of file TrackerHitAssociator.h.

Referenced by associatePixelRecHit(), and TrackerHitAssociator().

simhit_collectionMap TrackerHitAssociator::SimHitCollMap

Definition at line 104 of file TrackerHitAssociator.h.

Referenced by associateCluster(), associateHit(), and makeMaps().

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

Definition at line 110 of file TrackerHitAssociator.h.

Referenced by associateSimpleRecHitCluster(), and TrackerHitAssociator().