Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "SimMuon/MCTruth/interface/GEMHitAssociator.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 using namespace std;
0005 
0006 // Constructor
0007 GEMHitAssociator::Config::Config(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
0008     : GEMdigisimlinkTag(conf.getParameter<edm::InputTag>("GEMdigisimlinkTag")),
0009       // CrossingFrame used or not ?
0010       GEMsimhitsTag(conf.getParameter<edm::InputTag>("GEMsimhitsTag")),
0011       GEMsimhitsXFTag(conf.getParameter<edm::InputTag>("GEMsimhitsXFTag")),
0012       crossingframe(conf.getParameter<bool>("crossingframe")),
0013       useGEMs_(conf.getParameter<bool>("useGEMs")) {
0014   if (crossingframe) {
0015     GEMsimhitsXFToken_ = iC.consumes<CrossingFrame<PSimHit>>(GEMsimhitsXFTag);
0016   } else if (!GEMsimhitsTag.label().empty()) {
0017     GEMsimhitsToken_ = iC.consumes<edm::PSimHitContainer>(GEMsimhitsTag);
0018   }
0019 
0020   GEMdigisimlinkToken_ = iC.consumes<edm::DetSetVector<GEMDigiSimLink>>(GEMdigisimlinkTag);
0021 }
0022 
0023 GEMHitAssociator::GEMHitAssociator(const edm::Event &e, const Config &config) : theConfig(config) { initEvent(e); }
0024 
0025 void GEMHitAssociator::initEvent(const edm::Event &e) {
0026   if (theConfig.useGEMs_) {
0027     if (theConfig.crossingframe) {
0028       LogTrace("GEMHitAssociator") << "getting CrossingFrame<PSimHit> collection - " << theConfig.GEMsimhitsXFTag;
0029       CrossingFrame<PSimHit> const &cf = e.get(theConfig.GEMsimhitsXFToken_);
0030 
0031       std::unique_ptr<MixCollection<PSimHit>> GEMsimhits(new MixCollection<PSimHit>(&cf));
0032       LogTrace("GEMHitAssociator") << "... size = " << GEMsimhits->size();
0033 
0034       //   MixCollection<PSimHit> & simHits = *hits;
0035 
0036       for (MixCollection<PSimHit>::MixItr hitItr = GEMsimhits->begin(); hitItr != GEMsimhits->end(); ++hitItr) {
0037         _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
0038       }
0039 
0040     } else if (!theConfig.GEMsimhitsTag.label().empty()) {
0041       LogTrace("GEMHitAssociator") << "getting PSimHit collection - " << theConfig.GEMsimhitsTag;
0042       edm::PSimHitContainer const &GEMsimhits = e.get(theConfig.GEMsimhitsToken_);
0043       LogTrace("GEMHitAssociator") << "... size = " << GEMsimhits.size();
0044 
0045       // arrange the hits by detUnit
0046       for (edm::PSimHitContainer::const_iterator hitItr = GEMsimhits.begin(); hitItr != GEMsimhits.end(); ++hitItr) {
0047         _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
0048       }
0049     }
0050 
0051     LogTrace("GEMHitAssociator") << "getting GEM Strip DigiSimLink collection - " << theConfig.GEMdigisimlinkTag;
0052     theDigiSimLinks = &e.get(theConfig.GEMdigisimlinkToken_);
0053   }
0054 }
0055 // end of constructor
0056 
0057 std::vector<GEMHitAssociator::SimHitIdpr> GEMHitAssociator::associateRecHit(const GEMRecHit *gemrechit) const {
0058   std::vector<SimHitIdpr> matched;
0059 
0060   if (theConfig.useGEMs_) {
0061     if (gemrechit) {
0062       GEMDetId gemDetId = gemrechit->gemId();
0063       int fstrip = gemrechit->firstClusterStrip();
0064       int cls = gemrechit->clusterSize();
0065       // int bx = gemrechit->BunchX();
0066 
0067       DigiSimLinks::const_iterator layerLinks = theDigiSimLinks->find(gemDetId);
0068 
0069       if (layerLinks != theDigiSimLinks->end()) {
0070         for (int i = fstrip; i < (fstrip + cls); ++i) {
0071           for (LayerLinks::const_iterator itlink = layerLinks->begin(); itlink != layerLinks->end(); ++itlink) {
0072             int ch = static_cast<int>(itlink->getStrip());
0073             if (ch != i)
0074               continue;
0075 
0076             SimHitIdpr currentId(itlink->getTrackId(), itlink->getEventId());
0077             if (find(matched.begin(), matched.end(), currentId) == matched.end())
0078               matched.push_back(currentId);
0079           }
0080         }
0081 
0082       } else
0083         edm::LogWarning("GEMHitAssociator")
0084             << "*** WARNING in GEMHitAssociator: GEM layer " << gemDetId << " has no DigiSimLinks !" << std::endl;
0085 
0086     } else
0087       edm::LogWarning("GEMHitAssociator") << "*** WARNING in GEMHitAssociator::associateRecHit, null "
0088                                              "dynamic_cast !";
0089   }
0090 
0091   return matched;
0092 }