Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-05 22:26:26

0001 #include "DataFormats/Common/interface/DetSetVector.h"
0002 #include "FWCore/Framework/interface/ESHandle.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0005 #include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
0006 #include "SimMuon/MCTruth/interface/CSCHitAssociator.h"
0007 
0008 CSCHitAssociator::Config::Config(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
0009     : linksTag_(conf.getParameter<edm::InputTag>("CSClinksTag")),
0010       linksToken_(iC.consumes(linksTag_)),
0011       geomToken_(iC.esConsumes()) {}
0012 
0013 CSCHitAssociator::CSCHitAssociator(const edm::Event &event, const edm::EventSetup &setup, const Config &conf)
0014     : theConfig(conf), theDigiSimLinks(nullptr) {
0015   initEvent(event, setup);
0016 }
0017 
0018 void CSCHitAssociator::initEvent(const edm::Event &event, const edm::EventSetup &setup) {
0019   LogTrace("CSCHitAssociator") << "getting CSC Strip DigiSimLink collection - " << theConfig.linksTag_;
0020   theDigiSimLinks = &event.get(theConfig.linksToken_);
0021 
0022   // get CSC Geometry to use CSCLayer methods
0023   cscgeom = &setup.getData(theConfig.geomToken_);
0024 }
0025 
0026 std::vector<CSCHitAssociator::SimHitIdpr> CSCHitAssociator::associateCSCHitId(const CSCRecHit2D *cscrechit) const {
0027   std::vector<SimHitIdpr> simtrackids;
0028 
0029   unsigned int detId = cscrechit->geographicalId().rawId();
0030   int nchannels = cscrechit->nStrips();
0031   const CSCLayerGeometry *laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
0032 
0033   DigiSimLinks::const_iterator layerLinks = theDigiSimLinks->find(detId);
0034 
0035   if (layerLinks != theDigiSimLinks->end()) {
0036     for (int idigi = 0; idigi < nchannels; ++idigi) {
0037       // strip and readout channel numbers may differ in ME1/1A
0038       int istrip = cscrechit->channels(idigi);
0039       int channel = laygeom->channel(istrip);
0040 
0041       for (LayerLinks::const_iterator link = layerLinks->begin(); link != layerLinks->end(); ++link) {
0042         int ch = static_cast<int>(link->channel());
0043         if (ch == channel) {
0044           SimHitIdpr currentId(link->SimTrackId(), link->eventId());
0045           if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
0046             simtrackids.push_back(currentId);
0047         }
0048       }
0049     }
0050 
0051   } else
0052     LogTrace("CSCHitAssociator") << "*** WARNING in CSCHitAssociator::associateCSCHitId - CSC layer " << detId
0053                                  << " has no DigiSimLinks !" << std::endl;
0054 
0055   return simtrackids;
0056 }
0057 
0058 std::vector<CSCHitAssociator::SimHitIdpr> CSCHitAssociator::associateHitId(const TrackingRecHit &hit) const {
0059   std::vector<SimHitIdpr> simtrackids;
0060 
0061   const TrackingRecHit *hitp = &hit;
0062   const CSCRecHit2D *cscrechit = dynamic_cast<const CSCRecHit2D *>(hitp);
0063 
0064   if (cscrechit) {
0065     unsigned int detId = cscrechit->geographicalId().rawId();
0066     int nchannels = cscrechit->nStrips();
0067     const CSCLayerGeometry *laygeom = cscgeom->layer(cscrechit->cscDetId())->geometry();
0068 
0069     DigiSimLinks::const_iterator layerLinks = theDigiSimLinks->find(detId);
0070 
0071     if (layerLinks != theDigiSimLinks->end()) {
0072       for (int idigi = 0; idigi < nchannels; ++idigi) {
0073         // strip and readout channel numbers may differ in ME1/1A
0074         int istrip = cscrechit->channels(idigi);
0075         int channel = laygeom->channel(istrip);
0076 
0077         for (LayerLinks::const_iterator link = layerLinks->begin(); link != layerLinks->end(); ++link) {
0078           int ch = static_cast<int>(link->channel());
0079           if (ch == channel) {
0080             SimHitIdpr currentId(link->SimTrackId(), link->eventId());
0081             if (find(simtrackids.begin(), simtrackids.end(), currentId) == simtrackids.end())
0082               simtrackids.push_back(currentId);
0083           }
0084         }
0085       }
0086 
0087     } else
0088       LogTrace("CSCHitAssociator") << "*** WARNING in CSCHitAssociator::associateHitId - CSC layer " << detId
0089                                    << " has no DigiSimLinks !" << std::endl;
0090 
0091   } else
0092     LogTrace("CSCHitAssociator") << "*** WARNING in CSCHitAssociator::associateHitId, null dynamic_cast "
0093                                     "!";
0094 
0095   return simtrackids;
0096 }