Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:25

0001 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0002 #include "SimMuon/MCTruth/interface/PSimHitMap.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 void PSimHitMap::fill(const edm::Event &e) {
0006   theMap.clear();
0007   edm::Handle<CrossingFrame<PSimHit>> cf;
0008   LogTrace("PSimHitMap") << "getting CrossingFrame<PSimHit> collection ";
0009   e.getByToken(sh_token, cf);
0010 
0011   MixCollection<PSimHit> simHits(cf.product());
0012   LogTrace("PSimHitMap") << "... size = " << simHits.size();
0013 
0014   // arrange the hits by detUnit
0015   for (MixCollection<PSimHit>::MixItr hitItr = simHits.begin(); hitItr != simHits.end(); ++hitItr) {
0016     theMap[hitItr->detUnitId()].push_back(*hitItr);
0017   }
0018 }
0019 
0020 const edm::PSimHitContainer &PSimHitMap::hits(int detId) const {
0021   std::map<int, edm::PSimHitContainer>::const_iterator mapItr = theMap.find(detId);
0022   if (mapItr != theMap.end()) {
0023     return mapItr->second;
0024   } else {
0025     return theEmptyContainer;
0026   }
0027 }
0028 
0029 std::vector<int> PSimHitMap::detsWithHits() const {
0030   std::vector<int> result;
0031   result.reserve(theMap.size());
0032   for (std::map<int, edm::PSimHitContainer>::const_iterator mapItr = theMap.begin(), mapEnd = theMap.end();
0033        mapItr != mapEnd;
0034        ++mapItr) {
0035     result.push_back(mapItr->first);
0036   }
0037   return result;
0038 }