Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:58:51

0001 // -*- C++ -*-
0002 //
0003 
0004 #include "DQM/HcalCommon/interface/DQTask.h"
0005 #include "DQM/HcalCommon/interface/Utilities.h"
0006 #include "DQM/HcalCommon/interface/HashFilter.h"
0007 #include "DQM/HcalCommon/interface/Container1D.h"
0008 #include "DQM/HcalCommon/interface/Container2D.h"
0009 #include "DQM/HcalCommon/interface/ContainerProf1D.h"
0010 #include "DQM/HcalCommon/interface/ContainerProf2D.h"
0011 #include "DQM/HcalCommon/interface/ContainerSingle1D.h"
0012 #include "DQM/HcalCommon/interface/ContainerSingle2D.h"
0013 #include "DQM/HcalCommon/interface/ContainerSingleProf2D.h"
0014 #include "DQM/HcalCommon/interface/ElectronicsMap.h"
0015 
0016 #include <cmath>
0017 
0018 using namespace hcaldqm;
0019 using namespace hcaldqm::constants;
0020 using namespace hcaldqm::filter;
0021 
0022 class HcalGPUComparisonTask : public hcaldqm::DQTask {
0023 public:
0024   HcalGPUComparisonTask(edm::ParameterSet const&);
0025   ~HcalGPUComparisonTask() override = default;
0026 
0027   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0028   std::shared_ptr<hcaldqm::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0029                                                              edm::EventSetup const&) const override;
0030   void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0031   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032 
0033 private:
0034   void _process(edm::Event const&, edm::EventSetup const&) override;
0035   void _resetMonitors(hcaldqm::UpdateFreq) override;
0036 
0037   edm::InputTag tagHBHE_ref_;     //CPU version
0038   edm::InputTag tagHBHE_target_;  //GPU version
0039   edm::EDGetTokenT<HBHERecHitCollection> tokHBHE_ref_;
0040   edm::EDGetTokenT<HBHERecHitCollection> tokHBHE_target_;
0041   edm::ESGetToken<HcalDbService, HcalDbRecord> hcalDbServiceToken_;
0042 
0043   //    GPU reco test verification
0044   hcaldqm::Container2D energyGPUvsCPU_subdet_;
0045   hcaldqm::Container1D energyDiffGPUCPU_subdet_;
0046   hcaldqm::ContainerProf2D energyDiffGPUCPU_depth_;
0047 };
0048 
0049 HcalGPUComparisonTask::HcalGPUComparisonTask(edm::ParameterSet const& ps)
0050     : DQTask(ps),
0051       tagHBHE_ref_(ps.getUntrackedParameter<edm::InputTag>("tagHBHE_ref", edm::InputTag("hltHbhereco@cpu"))),
0052       tagHBHE_target_(ps.getUntrackedParameter<edm::InputTag>("tagHBHE_target", edm::InputTag("hltHbhereco@cuda"))),
0053       tokHBHE_ref_(consumes<HBHERecHitCollection>(tagHBHE_ref_)),
0054       tokHBHE_target_(consumes<HBHERecHitCollection>(tagHBHE_target_)),
0055       hcalDbServiceToken_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()) {}
0056 
0057 /* virtual */ void HcalGPUComparisonTask::bookHistograms(DQMStore::IBooker& ib,
0058                                                          edm::Run const& r,
0059                                                          edm::EventSetup const& es) {
0060   DQTask::bookHistograms(ib, r, es);
0061 
0062   //    GET WHAT YOU NEED
0063   edm::ESHandle<HcalDbService> dbs = es.getHandle(hcalDbServiceToken_);
0064   _emap = dbs->getHcalMapping();
0065 
0066   //    Book monitoring elements
0067   energyGPUvsCPU_subdet_.initialize(_name,
0068                                     "EnergyGPUvsCPU",
0069                                     hcaldqm::hashfunctions::fSubdet,
0070                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fCPUenergy, true),
0071                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fGPUenergy, true),
0072                                     new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN),
0073                                     0);
0074   energyDiffGPUCPU_subdet_.initialize(_name,
0075                                       "EnergyDiffGPUCPU",
0076                                       hcaldqm::hashfunctions::fSubdet,
0077                                       new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fDiffRatio),
0078                                       new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fN, true),
0079                                       0);
0080   energyDiffGPUCPU_depth_.initialize(_name,
0081                                      "EnergyDiffGPUCPU",
0082                                      hcaldqm::hashfunctions::fdepth,
0083                                      new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fieta),
0084                                      new hcaldqm::quantity::DetectorQuantity(hcaldqm::quantity::fiphi),
0085                                      new hcaldqm::quantity::ValueQuantity(hcaldqm::quantity::fDiffRatio),
0086                                      0);
0087 
0088   energyGPUvsCPU_subdet_.book(ib, _emap, _subsystem);
0089   energyDiffGPUCPU_subdet_.book(ib, _emap, _subsystem);
0090   energyDiffGPUCPU_depth_.book(ib, _emap, _subsystem);
0091 }
0092 
0093 /* virtual */ void HcalGPUComparisonTask::_resetMonitors(hcaldqm::UpdateFreq uf) { DQTask::_resetMonitors(uf); }
0094 
0095 /* virtual */ void HcalGPUComparisonTask::_process(edm::Event const& e, edm::EventSetup const&) {
0096   edm::Handle<HBHERecHitCollection> chbhe_ref;
0097   edm::Handle<HBHERecHitCollection> chbhe_target;
0098 
0099   if (!(e.getByToken(tokHBHE_ref_, chbhe_ref)))
0100     _logger.dqmthrow("The CPU HBHERecHitCollection \"" + tagHBHE_ref_.encode() + "\" is not available");
0101   if (!(e.getByToken(tokHBHE_target_, chbhe_target)))
0102     _logger.dqmthrow("The GPU HBHERecHitCollection \"" + tagHBHE_target_.encode() + "\" is not available");
0103 
0104   auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
0105   _currentLS = lumiCache->currentLS;
0106 
0107   std::map<HcalDetId, double> mRecHitEnergy;
0108 
0109   for (HBHERecHitCollection::const_iterator it = chbhe_ref->begin(); it != chbhe_ref->end(); ++it) {
0110     double energy = it->energy();
0111 
0112     //  Explicit check on the DetIds present in the Collection
0113     HcalDetId did = it->id();
0114 
0115     if (mRecHitEnergy.find(did) == mRecHitEnergy.end())
0116       mRecHitEnergy.insert(std::make_pair(did, energy));
0117     else
0118       edm::LogError("HcalDQM|RechitTask") << "Duplicate Rechit from the same HcalDetId";
0119   }
0120 
0121   for (HBHERecHitCollection::const_iterator it = chbhe_target->begin(); it != chbhe_target->end(); ++it) {
0122     double energy = it->energy();
0123     HcalDetId did = it->id();
0124 
0125     if (mRecHitEnergy.find(did) != mRecHitEnergy.end()) {
0126       energyGPUvsCPU_subdet_.fill(did, mRecHitEnergy[did], energy);
0127 
0128       if (mRecHitEnergy[did] != 0.) {
0129         energyDiffGPUCPU_subdet_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
0130         if (energy > 0.1)
0131           energyDiffGPUCPU_depth_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
0132       } else if (mRecHitEnergy[did] == 0. && energy == 0.) {
0133         energyDiffGPUCPU_subdet_.fill(did, 0.);
0134         if (energy > 0.1)
0135           energyDiffGPUCPU_depth_.fill(did, 0.);
0136       } else {
0137         energyDiffGPUCPU_subdet_.fill(did, -1.);
0138         if (energy > 0.1)
0139           energyDiffGPUCPU_depth_.fill(did, -1.);
0140       }
0141 
0142       mRecHitEnergy.erase(did);
0143     } else
0144       edm::LogError("HcalDQM|RechitTask") << "GPU Rechit id not found in CPU Rechit id collection";
0145   }
0146   if (!mRecHitEnergy.empty())
0147     edm::LogError("HcalDQM|RechitTask") << "CPU Rechit id not found in GPU Rechit id collection";
0148 }
0149 
0150 std::shared_ptr<hcaldqm::Cache> HcalGPUComparisonTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& lb,
0151                                                                                   edm::EventSetup const& es) const {
0152   return DQTask::globalBeginLuminosityBlock(lb, es);
0153 }
0154 
0155 /* virtual */ void HcalGPUComparisonTask::globalEndLuminosityBlock(edm::LuminosityBlock const& lb,
0156                                                                    edm::EventSetup const& es) {
0157   if (_ptype != fOnline)
0158     return;
0159 
0160   auto lumiCache = luminosityBlockCache(lb.index());
0161   _currentLS = lumiCache->currentLS;
0162 
0163   //    in the end always do the DQTask::endLumi
0164   DQTask::globalEndLuminosityBlock(lb, es);
0165 }
0166 
0167 void HcalGPUComparisonTask::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0168   edm::ParameterSetDescription desc;
0169   desc.addUntracked<std::string>("name", "HcalGPUComparisonTask");
0170   desc.addUntracked<int>("debug", 0);
0171   desc.addUntracked<int>("runkeyVal", 0);
0172   desc.addUntracked<std::string>("runkeyName", "pp_run");
0173   desc.addUntracked<int>("ptype", 1);
0174   desc.addUntracked<bool>("mtype", true);
0175   desc.addUntracked<std::string>("subsystem", "Hcal");
0176   desc.addUntracked<edm::InputTag>("tagHBHE_ref", edm::InputTag("hbhereco@cpu"));
0177   desc.addUntracked<edm::InputTag>("tagHBHE_target", edm::InputTag("hbhereco@cuda"));
0178   desc.addUntracked<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
0179   descriptions.addWithDefaultLabel(desc);
0180 }
0181 
0182 DEFINE_FWK_MODULE(HcalGPUComparisonTask);