|
| 1 | +// -*- C++ -*- |
| 2 | +// |
| 3 | + |
| 4 | +#include "DQM/HcalCommon/interface/DQTask.h" |
| 5 | +#include "DQM/HcalCommon/interface/Utilities.h" |
| 6 | +#include "DQM/HcalCommon/interface/HashFilter.h" |
| 7 | +#include "DQM/HcalCommon/interface/Container1D.h" |
| 8 | +#include "DQM/HcalCommon/interface/Container2D.h" |
| 9 | +#include "DQM/HcalCommon/interface/ContainerProf1D.h" |
| 10 | +#include "DQM/HcalCommon/interface/ContainerProf2D.h" |
| 11 | +#include "DQM/HcalCommon/interface/ContainerSingle1D.h" |
| 12 | +#include "DQM/HcalCommon/interface/ContainerSingle2D.h" |
| 13 | +#include "DQM/HcalCommon/interface/ContainerSingleProf2D.h" |
| 14 | +#include "DQM/HcalCommon/interface/ElectronicsMap.h" |
| 15 | +#include "DQMServices/Core/interface/DQMEDAnalyzer.h" |
| 16 | +#include "DQMServices/Core/interface/DQMStore.h" |
| 17 | +#include "DataFormats/CaloRecHit/interface/CaloCluster.h" |
| 18 | +#include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h" |
| 19 | +#include "DataFormats/CaloTowers/interface/CaloTowerCollection.h" |
| 20 | +#include "DataFormats/CaloTowers/interface/CaloTowerDetId.h" |
| 21 | +#include "DataFormats/Common/interface/Handle.h" |
| 22 | +#include "DataFormats/DetId/interface/DetId.h" |
| 23 | +#include "DataFormats/EcalDetId/interface/EcalSubdetector.h" |
| 24 | +#include "DataFormats/HcalDetId/interface/HcalDetId.h" |
| 25 | +#include "DataFormats/HcalDetId/interface/HcalSubdetector.h" |
| 26 | +#include "DataFormats/Math/interface/Vector3D.h" |
| 27 | +#include "DataFormats/Math/interface/deltaR.h" |
| 28 | +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" |
| 29 | +#include "DataFormats/ParticleFlowReco/interface/PFBlock.h" |
| 30 | +#include "DataFormats/ParticleFlowReco/interface/PFBlockElementCluster.h" |
| 31 | +#include "DataFormats/ParticleFlowReco/interface/PFBlockElementTrack.h" |
| 32 | +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" |
| 33 | +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" |
| 34 | +#include "DataFormats/ParticleFlowReco/interface/PFLayer.h" |
| 35 | +#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" |
| 36 | +#include "DataFormats/ParticleFlowReco/interface/PFRecHitFraction.h" |
| 37 | +#include "FWCore/Framework/interface/Event.h" |
| 38 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 39 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 40 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 41 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 42 | +#include "FWCore/PluginManager/interface/ModuleDef.h" |
| 43 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 44 | + |
| 45 | +#include <cmath> |
| 46 | +#ifdef PFLOW_DEBUG |
| 47 | +#define LOGVERB(x) edm::LogVerbatim(x) |
| 48 | +#else |
| 49 | +#define LOGVERB(x) LogTrace(x) |
| 50 | +#endif |
| 51 | + |
| 52 | +using namespace hcaldqm; |
| 53 | +using namespace hcaldqm::constants; |
| 54 | +using namespace hcaldqm::filter; |
| 55 | + |
| 56 | +class PFHcalGPUComparisonTask : public hcaldqm::DQTask { |
| 57 | +public: |
| 58 | + PFHcalGPUComparisonTask(edm::ParameterSet const&); |
| 59 | + ~PFHcalGPUComparisonTask() override = default; |
| 60 | + |
| 61 | + void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override; |
| 62 | + std::shared_ptr<hcaldqm::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&, |
| 63 | + edm::EventSetup const&) const override; |
| 64 | + void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; |
| 65 | + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); |
| 66 | + |
| 67 | +private: |
| 68 | + void _process(edm::Event const&, edm::EventSetup const&) override; |
| 69 | + void _resetMonitors(hcaldqm::UpdateFreq) override; |
| 70 | + |
| 71 | + edm::EDGetTokenT<reco::PFClusterCollection> pfClusterTok_ref_; |
| 72 | + edm::EDGetTokenT<reco::PFClusterCollection> pfClusterTok_target_; |
| 73 | + |
| 74 | + MonitorElement* pfCluster_Multiplicity_HostvsDevice_; |
| 75 | + MonitorElement* pfCluster_Energy_HostvsDevice_; |
| 76 | + MonitorElement* pfCluster_RecHitMultiplicity_HostvsDevice_; |
| 77 | + MonitorElement* pfCluster_Layer_HostvsDevice_; |
| 78 | + MonitorElement* pfCluster_Depth_HostvsDevice_; |
| 79 | + MonitorElement* pfCluster_Eta_HostvsDevice_; |
| 80 | + MonitorElement* pfCluster_Phi_HostvsDevice_; |
| 81 | + MonitorElement* pfCluster_DuplicateMatches_HostvsDevice_; |
| 82 | + |
| 83 | + std::string pfCaloGPUCompDir_; |
| 84 | +}; |
| 85 | + |
| 86 | +PFHcalGPUComparisonTask::PFHcalGPUComparisonTask(edm::ParameterSet const& conf) |
| 87 | + : DQTask(conf), |
| 88 | + pfClusterTok_ref_{ |
| 89 | + consumes<reco::PFClusterCollection>(conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_ref"))}, |
| 90 | + pfClusterTok_target_{ |
| 91 | + consumes<reco::PFClusterCollection>(conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_target"))}, |
| 92 | + pfCaloGPUCompDir_{conf.getUntrackedParameter<std::string>("name")} {} |
| 93 | + |
| 94 | +void PFHcalGPUComparisonTask::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& r, edm::EventSetup const& es) { |
| 95 | + _subsystem = "ParticleFlow"; |
| 96 | + ibooker.setCurrentFolder("ParticleFlow/" + pfCaloGPUCompDir_); |
| 97 | + DQTask::bookHistograms(ibooker, r, es); |
| 98 | + // Book monitoring elements |
| 99 | + const char* histo; |
| 100 | + |
| 101 | + histo = "pfCluster_Multiplicity_HostvsDevice"; |
| 102 | + const char* histoAxis = "pfCluster_Multiplicity_HostvsDevice;Multiplicity Device;Multiplicity Device"; |
| 103 | + pfCluster_Multiplicity_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 1000, 0, 1000, 1000, 0, 1000); |
| 104 | + |
| 105 | + histo = "pfCluster_Energy_HostvsDevice"; |
| 106 | + histoAxis = "pfCluster_Energy_HostvsDevice;Energy Host [GeV];Energy Device [GeV]"; |
| 107 | + pfCluster_Energy_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 500, 0, 500, 500, 0, 500); |
| 108 | + |
| 109 | + histo = "pfCluster_RecHitMultiplicity_HostvsDevice"; |
| 110 | + histoAxis = "pfCluster_RecHitMultiplicity_HostvsDevice;RecHit Multiplicity Host;RecHit Multiplicity Device"; |
| 111 | + pfCluster_RecHitMultiplicity_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 100, 0, 100, 100, 0, 100); |
| 112 | + |
| 113 | + histo = "pfCluster_Layer_HostvsDevice"; |
| 114 | + histoAxis = "pfCluster_Layer_HostvsDevice;Cluster Layer Host;Cluster Layer Device"; |
| 115 | + pfCluster_Layer_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 4, 0, 3, 4, 0, 3); |
| 116 | + |
| 117 | + histo = "pfCluster_Depth_HostvsDevice"; |
| 118 | + histoAxis = "pfCluster_Depth_HostvsDevice;Cluster Depth Host;Cluster Depth Device"; |
| 119 | + pfCluster_Depth_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 8, 0, 7, 8, 0, 7); |
| 120 | + |
| 121 | + histo = "pfCluster_Eta_HostvsDevice"; |
| 122 | + histoAxis = "pfCluster_Eta_HostvsDevice;Cluster #eta Host;Cluster #eta Device"; |
| 123 | + pfCluster_Eta_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 100, -5.f, 5.f, 100, -5.f, 5.f); |
| 124 | + |
| 125 | + histo = "pfCluster_Phi_HostvsDevice"; |
| 126 | + histoAxis = "pfCluster_Phi_HostvsDevice;Cluster #phi Host;Cluster #phi Device"; |
| 127 | + pfCluster_Phi_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 100, -M_PI, M_PI, 100, -M_PI, M_PI); |
| 128 | + |
| 129 | + histo = "pfCluster_DuplicateMatches_HostvsDevice"; |
| 130 | + histoAxis = "pfCluster_Duplicates_HostvsDevice;Cluster Duplicates Host;Cluster Duplicates Device"; |
| 131 | + pfCluster_DuplicateMatches_HostvsDevice_ = ibooker.book1I(histo, histoAxis, 100, 0., 1000); |
| 132 | +} |
| 133 | + |
| 134 | +void PFHcalGPUComparisonTask::_resetMonitors(hcaldqm::UpdateFreq uf) { DQTask::_resetMonitors(uf); } |
| 135 | + |
| 136 | +void PFHcalGPUComparisonTask::_process(edm::Event const& event, edm::EventSetup const&) { |
| 137 | + edm::Handle<reco::PFClusterCollection> pfClusters_ref; |
| 138 | + event.getByToken(pfClusterTok_ref_, pfClusters_ref); |
| 139 | + |
| 140 | + edm::Handle<reco::PFClusterCollection> pfClusters_target; |
| 141 | + event.getByToken(pfClusterTok_target_, pfClusters_target); |
| 142 | + |
| 143 | + auto lumiCache = luminosityBlockCache(event.getLuminosityBlock().index()); |
| 144 | + _currentLS = lumiCache->currentLS; |
| 145 | + // Compare per-event PF cluster multiplicity |
| 146 | + |
| 147 | + if (pfClusters_ref->size() != pfClusters_target->size()) |
| 148 | + LOGVERB("PFCaloGPUComparisonTask") << " PFCluster multiplicity " << pfClusters_ref->size() << " " |
| 149 | + << pfClusters_target->size(); |
| 150 | + pfCluster_Multiplicity_HostvsDevice_->Fill((float)pfClusters_ref->size(), (float)pfClusters_target->size()); |
| 151 | + |
| 152 | + // |
| 153 | + // Find matching PF cluster pairs |
| 154 | + std::vector<int> matched_idx; |
| 155 | + matched_idx.reserve(pfClusters_ref->size()); |
| 156 | + for (unsigned i = 0; i < pfClusters_ref->size(); ++i) { |
| 157 | + bool matched = false; |
| 158 | + for (unsigned j = 0; j < pfClusters_target->size(); ++j) { |
| 159 | + if (pfClusters_ref->at(i).seed() == pfClusters_target->at(j).seed()) { |
| 160 | + if (!matched) { |
| 161 | + matched = true; |
| 162 | + matched_idx.push_back((int)j); |
| 163 | + } else { |
| 164 | + edm::LogWarning("PFCaloGPUComparisonTask") << "Found duplicate match"; |
| 165 | + pfCluster_DuplicateMatches_HostvsDevice_->Fill((int)j); |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + if (!matched) |
| 170 | + matched_idx.push_back(-1); // if you don't find a match, put a dummy number |
| 171 | + } |
| 172 | + |
| 173 | + // |
| 174 | + // Plot matching PF cluster variables |
| 175 | + for (unsigned i = 0; i < pfClusters_ref->size(); ++i) { |
| 176 | + if (matched_idx[i] >= 0) { |
| 177 | + unsigned int j = matched_idx[i]; |
| 178 | + int ref_energy_bin = |
| 179 | + pfCluster_Energy_HostvsDevice_->getTH2F()->GetXaxis()->FindBin(pfClusters_ref->at(i).energy()); |
| 180 | + int target_energy_bin = |
| 181 | + pfCluster_Energy_HostvsDevice_->getTH2F()->GetXaxis()->FindBin(pfClusters_target->at(j).energy()); |
| 182 | + if (ref_energy_bin != target_energy_bin) |
| 183 | + edm::LogPrint("PFCaloGPUComparisonTask") |
| 184 | + << "Off-diagonal energy bin entries: " << pfClusters_ref->at(i).energy() << " " |
| 185 | + << pfClusters_ref->at(i).eta() << " " << pfClusters_ref->at(i).phi() << " " |
| 186 | + << pfClusters_target->at(j).energy() << " " << pfClusters_target->at(j).eta() << " " |
| 187 | + << pfClusters_target->at(j).phi() << std::endl; |
| 188 | + pfCluster_Energy_HostvsDevice_->Fill(pfClusters_ref->at(i).energy(), pfClusters_target->at(j).energy()); |
| 189 | + pfCluster_Layer_HostvsDevice_->Fill(pfClusters_ref->at(i).layer(), pfClusters_target->at(j).layer()); |
| 190 | + pfCluster_Eta_HostvsDevice_->Fill(pfClusters_ref->at(i).eta(), pfClusters_target->at(j).eta()); |
| 191 | + pfCluster_Phi_HostvsDevice_->Fill(pfClusters_ref->at(i).phi(), pfClusters_target->at(j).phi()); |
| 192 | + pfCluster_Depth_HostvsDevice_->Fill(pfClusters_ref->at(i).depth(), pfClusters_target->at(j).depth()); |
| 193 | + pfCluster_RecHitMultiplicity_HostvsDevice_->Fill((float)pfClusters_ref->at(i).recHitFractions().size(), |
| 194 | + (float)pfClusters_target->at(j).recHitFractions().size()); |
| 195 | + } |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +std::shared_ptr<hcaldqm::Cache> PFHcalGPUComparisonTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& lb, |
| 200 | + edm::EventSetup const& es) const { |
| 201 | + return DQTask::globalBeginLuminosityBlock(lb, es); |
| 202 | +} |
| 203 | + |
| 204 | +void PFHcalGPUComparisonTask::globalEndLuminosityBlock(edm::LuminosityBlock const& lb, edm::EventSetup const& es) { |
| 205 | + if (_ptype != fOnline) |
| 206 | + return; |
| 207 | + |
| 208 | + auto lumiCache = luminosityBlockCache(lb.index()); |
| 209 | + _currentLS = lumiCache->currentLS; |
| 210 | + |
| 211 | + // in the end always do the DQTask::endLumi |
| 212 | + DQTask::globalEndLuminosityBlock(lb, es); |
| 213 | +} |
| 214 | + |
| 215 | +void PFHcalGPUComparisonTask::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 216 | + edm::ParameterSetDescription desc; |
| 217 | + desc.addUntracked<std::string>("name", "pfCaloGPUCompDir"); |
| 218 | + desc.addUntracked<edm::InputTag>("pfClusterToken_ref", edm::InputTag("hltParticleFlowClusterHCALSerialSync")); |
| 219 | + desc.addUntracked<edm::InputTag>("pfClusterToken_target", edm::InputTag("hltParticleFlowClusterHCAL")); |
| 220 | + descriptions.addWithDefaultLabel(desc); |
| 221 | +} |
| 222 | + |
| 223 | +DEFINE_FWK_MODULE(PFHcalGPUComparisonTask); |
0 commit comments