Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:45

0001 #include "SimMuon/GEMDigitizer/interface/ME0DigiModel.h"
0002 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0003 
0004 void ME0DigiModel::fillDigis(int rollDetId, ME0DigiCollection &digis) {
0005   for (const auto &d : strips_) {
0006     if (d.second == -999)
0007       continue;
0008 
0009     // (strip, bx)
0010     ME0Digi digi(d.first, d.second);
0011     digis.insertDigi(ME0DetId(rollDetId), digi);
0012     addLinks(d.first, d.second);
0013     addLinksWithPartId(d.first, d.second);
0014   }
0015   strips_.clear();
0016 }
0017 
0018 void ME0DigiModel::addLinks(unsigned int strip, int bx) {
0019   std::pair<unsigned int, int> digi(strip, bx);
0020   auto channelHitItr = detectorHitMap_.equal_range(digi);
0021 
0022   // find the fraction contribution for each SimTrack
0023   std::map<int, float> simTrackChargeMap;
0024   std::map<int, EncodedEventId> eventIdMap;
0025   float totalCharge(0.);
0026   for (auto hitItr = channelHitItr.first; hitItr != channelHitItr.second; ++hitItr) {
0027     const PSimHit *hit(hitItr->second);
0028     // might be zero for unit tests and such
0029     if (hit == nullptr)
0030       continue;
0031 
0032     int simTrackId(hit->trackId());
0033     //float charge = hit->getCharge();
0034     const float charge(1.f);
0035     auto chargeItr = simTrackChargeMap.find(simTrackId);
0036     if (chargeItr == simTrackChargeMap.end()) {
0037       simTrackChargeMap[simTrackId] = charge;
0038       eventIdMap[simTrackId] = hit->eventId();
0039     } else {
0040       chargeItr->second += charge;
0041     }
0042     totalCharge += charge;
0043   }
0044 
0045   for (const auto &charge : simTrackChargeMap) {
0046     const int simTrackId(charge.first);
0047     auto link(StripDigiSimLink(strip, simTrackId, eventIdMap[simTrackId], charge.second / totalCharge));
0048     stripDigiSimLinks_.push_back(link);
0049   }
0050 }
0051 
0052 void ME0DigiModel::addLinksWithPartId(unsigned int strip, int bx) {
0053   std::pair<unsigned int, int> digi(strip, bx);
0054   auto channelHitItr = detectorHitMap_.equal_range(digi);
0055   for (auto hitItr = channelHitItr.first; hitItr != channelHitItr.second; ++hitItr) {
0056     const PSimHit *hit = (hitItr->second);
0057     // might be zero for unit tests and such
0058     if (hit == nullptr)
0059       continue;
0060 
0061     theME0DigiSimLinks_.push_back(ME0DigiSimLink(strip, bx, hit->particleType(), hit->trackId(), hit->eventId()));
0062   }
0063 }