Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:32

0001 #include "Validation/HGCalValidation/plugins/HeterogeneousHGCalRecHitsValidator.h"
0002 
0003 HeterogeneousHGCalRecHitsValidator::HeterogeneousHGCalRecHitsValidator(const edm::ParameterSet &ps)
0004     : tokens_({{{{consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("cpuRecHitsEEToken")),
0005                   consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("gpuRecHitsEEToken"))}},
0006                 {{consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("cpuRecHitsHSiToken")),
0007                   consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("gpuRecHitsHSiToken"))}},
0008                 {{consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("cpuRecHitsHSciToken")),
0009                   consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("gpuRecHitsHSciToken"))}}}}),
0010       treenames_({{"CEE", "CHSi", "CHSci"}}) {
0011   usesResource(TFileService::kSharedResource);
0012   estokenGeom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0013   edm::Service<TFileService> fs;
0014   for (unsigned i(0); i < nsubdetectors; ++i) {
0015     estokens_[i] = esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", handles_str_[i]});
0016     trees_[i] = fs->make<TTree>(treenames_[i].c_str(), treenames_[i].c_str());
0017     trees_[i]->Branch("cpu", "ValidHitCollection", &cpuValidRecHits[i]);
0018     trees_[i]->Branch("gpu", "ValidHitCollection", &gpuValidRecHits[i]);
0019     trees_[i]->Branch("diffs", "ValidHitCollection", &diffsValidRecHits[i]);
0020   }
0021 }
0022 
0023 HeterogeneousHGCalRecHitsValidator::~HeterogeneousHGCalRecHitsValidator() {}
0024 
0025 void HeterogeneousHGCalRecHitsValidator::endJob() {}
0026 
0027 void HeterogeneousHGCalRecHitsValidator::set_geometry_(const edm::EventSetup &setup, const unsigned &detidx) {
0028   edm::ESHandle<HGCalGeometry> handle = setup.getHandle(estokens_[detidx]);
0029 }
0030 
0031 void HeterogeneousHGCalRecHitsValidator::analyze(const edm::Event &event, const edm::EventSetup &setup) {
0032   recHitTools_.setGeometry(setup.getData(estokenGeom_));
0033 
0034   //future subdetector loop
0035   for (size_t idet = 0; idet < nsubdetectors; ++idet) {
0036     set_geometry_(setup, idet);
0037 
0038     //get hits produced with the CPU
0039     const auto &cpuhits = event.get(tokens_[idet][0]);
0040 
0041     //get hits produced with the GPU
0042     const auto &gpuhits = event.get(tokens_[idet][1]);
0043 
0044     size_t nhits = cpuhits.size();
0045     std::cout << nhits << ", " << gpuhits.size() << std::endl;
0046     assert(nhits == gpuhits.size());
0047     //float sum_cpu = 0.f, sum_gpu = 0.f, sum_son_cpu = 0.f, sum_son_gpu = 0.f;
0048     for (unsigned i(0); i < nhits; i++) {
0049       const HGCRecHit &cpuHit = cpuhits[i];
0050       const HGCRecHit &gpuHit = gpuhits[i];
0051 
0052       const float cpuEn = cpuHit.energy();
0053       const float gpuEn = gpuHit.energy();
0054       //sum_cpu += cpuEn; sum_gpu += gpuEn;
0055 
0056       const float cpuTime = cpuHit.time();
0057       const float gpuTime = gpuHit.time();
0058       const float cpuTimeErr = cpuHit.timeError();
0059       const float gpuTimeErr = gpuHit.timeError();
0060       const DetId cpuDetId = cpuHit.detid();
0061       const DetId gpuDetId = gpuHit.detid();
0062       const float cpuFB = cpuHit.flagBits();
0063       const float gpuFB = gpuHit.flagBits();
0064       const float cpuSoN = cpuHit.signalOverSigmaNoise();
0065       const float gpuSoN = gpuHit.signalOverSigmaNoise();
0066       //sum_son_cpu += cpuSoN; sum_son_gpu += gpuSoN;
0067 
0068       ValidHit vCPU(cpuEn, cpuTime, cpuTimeErr, cpuDetId, cpuFB, cpuSoN);
0069       ValidHit vGPU(gpuEn, gpuTime, gpuTimeErr, gpuDetId, gpuFB, gpuSoN);
0070       ValidHit vDiffs(cpuEn - gpuEn,
0071                       cpuTime - gpuTime,
0072                       cpuTimeErr - gpuTimeErr,
0073                       cpuDetId - gpuDetId,
0074                       cpuFB - gpuFB,
0075                       cpuSoN - gpuSoN);
0076 
0077       cpuValidRecHits[idet].push_back(vCPU);
0078       gpuValidRecHits[idet].push_back(vGPU);
0079       diffsValidRecHits[idet].push_back(vDiffs);
0080     }
0081     trees_[idet]->Fill();
0082   }
0083 }
0084 
0085 //define this as a plug-in
0086 DEFINE_FWK_MODULE(HeterogeneousHGCalRecHitsValidator);