Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   auto const chbhe_ref = e.getHandle(tokHBHE_ref_);
0097   auto const chbhe_target = e.getHandle(tokHBHE_target_);
0098 
0099   if (not(chbhe_ref.isValid() and chbhe_target.isValid())) {
0100     edm::LogWarning("HcalGPUComparisonTask")
0101         << "Either CPU or GPU RecHit Collection is unavailable, will not fill this event.";
0102     return;
0103   }
0104 
0105   auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
0106   _currentLS = lumiCache->currentLS;
0107 
0108   std::map<HcalDetId, double> mRecHitEnergy;
0109 
0110   for (HBHERecHitCollection::const_iterator it = chbhe_ref->begin(); it != chbhe_ref->end(); ++it) {
0111     double energy = it->energy();
0112 
0113     //  Explicit check on the DetIds present in the Collection
0114     HcalDetId did = it->id();
0115 
0116     if (mRecHitEnergy.find(did) == mRecHitEnergy.end())
0117       mRecHitEnergy.insert(std::make_pair(did, energy));
0118     else
0119       edm::LogError("HcalGPUComparisonTask") << "Duplicate Rechit from the same HcalDetId";
0120     ;
0121   }
0122 
0123   for (HBHERecHitCollection::const_iterator it = chbhe_target->begin(); it != chbhe_target->end(); ++it) {
0124     double energy = it->energy();
0125     HcalDetId did = it->id();
0126 
0127     if (mRecHitEnergy.find(did) != mRecHitEnergy.end()) {
0128       energyGPUvsCPU_subdet_.fill(did, mRecHitEnergy[did], energy);
0129 
0130       if (mRecHitEnergy[did] != 0.) {
0131         energyDiffGPUCPU_subdet_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
0132         if (energy > 0.1)
0133           energyDiffGPUCPU_depth_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
0134       } else if (mRecHitEnergy[did] == 0. && energy == 0.) {
0135         energyDiffGPUCPU_subdet_.fill(did, 0.);
0136         if (energy > 0.1)
0137           energyDiffGPUCPU_depth_.fill(did, 0.);
0138       } else {
0139         energyDiffGPUCPU_subdet_.fill(did, -1.);
0140         if (energy > 0.1)
0141           energyDiffGPUCPU_depth_.fill(did, -1.);
0142       }
0143 
0144       mRecHitEnergy.erase(did);
0145     } else {
0146       if (energy > 2.)
0147         edm::LogError("HcalGPUComparisonTask")
0148             << "Energetic GPU Rechit exist, but not reconstructed by CPU. DetId = " << did;
0149     }
0150   }
0151   if (!mRecHitEnergy.empty()) {
0152     for (auto const& rhpair : mRecHitEnergy) {
0153       if (rhpair.second > 2.)
0154         edm::LogError("HcalGPUComparisonTask")
0155             << "Energetic CPU Rechit exist, but not reconstructed by GPU. DetId = " << rhpair.first;
0156     }
0157   }
0158 }
0159 
0160 std::shared_ptr<hcaldqm::Cache> HcalGPUComparisonTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& lb,
0161                                                                                   edm::EventSetup const& es) const {
0162   return DQTask::globalBeginLuminosityBlock(lb, es);
0163 }
0164 
0165 /* virtual */ void HcalGPUComparisonTask::globalEndLuminosityBlock(edm::LuminosityBlock const& lb,
0166                                                                    edm::EventSetup const& es) {
0167   if (_ptype != fOnline)
0168     return;
0169 
0170   auto lumiCache = luminosityBlockCache(lb.index());
0171   _currentLS = lumiCache->currentLS;
0172 
0173   //    in the end always do the DQTask::endLumi
0174   DQTask::globalEndLuminosityBlock(lb, es);
0175 }
0176 
0177 void HcalGPUComparisonTask::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0178   edm::ParameterSetDescription desc;
0179   desc.addUntracked<std::string>("name", "HcalGPUComparisonTask");
0180   desc.addUntracked<int>("debug", 0);
0181   desc.addUntracked<int>("runkeyVal", 0);
0182   desc.addUntracked<std::string>("runkeyName", "pp_run");
0183   desc.addUntracked<int>("ptype", 1);
0184   desc.addUntracked<bool>("mtype", true);
0185   desc.addUntracked<std::string>("subsystem", "Hcal");
0186   desc.addUntracked<edm::InputTag>("tagHBHE_ref", edm::InputTag("hbhereco@cpu"));
0187   desc.addUntracked<edm::InputTag>("tagHBHE_target", edm::InputTag("hbhereco@cuda"));
0188   desc.addUntracked<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
0189   descriptions.addWithDefaultLabel(desc);
0190 }
0191 
0192 DEFINE_FWK_MODULE(HcalGPUComparisonTask);