File indexing completed on 2024-06-13 03:23:36
0001
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 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0018 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0019 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0020 #include "DataFormats/CaloTowers/interface/CaloTowerDetId.h"
0021 #include "DataFormats/Common/interface/Handle.h"
0022 #include "DataFormats/DetId/interface/DetId.h"
0023 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0024 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0025 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0026 #include "DataFormats/Math/interface/Vector3D.h"
0027 #include "DataFormats/Math/interface/deltaR.h"
0028 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0029 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
0030 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementCluster.h"
0031 #include "DataFormats/ParticleFlowReco/interface/PFBlockElementTrack.h"
0032 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0033 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0034 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
0035 #include "DataFormats/ParticleFlowReco/interface/PFRecHit.h"
0036 #include "DataFormats/ParticleFlowReco/interface/PFRecHitFraction.h"
0037 #include "FWCore/Framework/interface/Event.h"
0038 #include "FWCore/Framework/interface/EventSetup.h"
0039 #include "FWCore/Framework/interface/Frameworkfwd.h"
0040 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0041 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0042 #include "FWCore/PluginManager/interface/ModuleDef.h"
0043 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0044
0045 #include <cmath>
0046 #ifdef PFLOW_DEBUG
0047 #define LOGVERB(x) edm::LogVerbatim(x)
0048 #else
0049 #define LOGVERB(x) LogTrace(x)
0050 #endif
0051
0052 using namespace hcaldqm;
0053 using namespace hcaldqm::constants;
0054 using namespace hcaldqm::filter;
0055
0056 class PFHcalGPUComparisonTask : public hcaldqm::DQTask {
0057 public:
0058 PFHcalGPUComparisonTask(edm::ParameterSet const&);
0059 ~PFHcalGPUComparisonTask() override = default;
0060
0061 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0062 std::shared_ptr<hcaldqm::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0063 edm::EventSetup const&) const override;
0064 void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0065 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0066
0067 private:
0068 void _process(edm::Event const&, edm::EventSetup const&) override;
0069 void _resetMonitors(hcaldqm::UpdateFreq) override;
0070
0071 edm::EDGetTokenT<reco::PFClusterCollection> pfClusterTok_ref_;
0072 edm::EDGetTokenT<reco::PFClusterCollection> pfClusterTok_target_;
0073
0074 MonitorElement* pfCluster_Multiplicity_HostvsDevice_;
0075 MonitorElement* pfCluster_Energy_HostvsDevice_;
0076 MonitorElement* pfCluster_RecHitMultiplicity_HostvsDevice_;
0077 MonitorElement* pfCluster_Layer_HostvsDevice_;
0078 MonitorElement* pfCluster_Depth_HostvsDevice_;
0079 MonitorElement* pfCluster_Eta_HostvsDevice_;
0080 MonitorElement* pfCluster_Phi_HostvsDevice_;
0081 MonitorElement* pfCluster_DuplicateMatches_HostvsDevice_;
0082
0083 std::string pfCaloGPUCompDir_;
0084 };
0085
0086 PFHcalGPUComparisonTask::PFHcalGPUComparisonTask(edm::ParameterSet const& conf)
0087 : DQTask(conf),
0088 pfClusterTok_ref_{
0089 consumes<reco::PFClusterCollection>(conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_ref"))},
0090 pfClusterTok_target_{
0091 consumes<reco::PFClusterCollection>(conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_target"))},
0092 pfCaloGPUCompDir_{conf.getUntrackedParameter<std::string>("name")} {}
0093
0094 void PFHcalGPUComparisonTask::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& r, edm::EventSetup const& es) {
0095 _subsystem = "ParticleFlow";
0096 ibooker.setCurrentFolder("ParticleFlow/" + pfCaloGPUCompDir_);
0097 DQTask::bookHistograms(ibooker, r, es);
0098
0099 const char* histo;
0100
0101 histo = "pfCluster_Multiplicity_HostvsDevice";
0102 const char* histoAxis = "pfCluster_Multiplicity_HostvsDevice;Multiplicity Device;Multiplicity Device";
0103 pfCluster_Multiplicity_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 1000, 0, 1000, 1000, 0, 1000);
0104
0105 histo = "pfCluster_Energy_HostvsDevice";
0106 histoAxis = "pfCluster_Energy_HostvsDevice;Energy Host [GeV];Energy Device [GeV]";
0107 pfCluster_Energy_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 500, 0, 500, 500, 0, 500);
0108
0109 histo = "pfCluster_RecHitMultiplicity_HostvsDevice";
0110 histoAxis = "pfCluster_RecHitMultiplicity_HostvsDevice;RecHit Multiplicity Host;RecHit Multiplicity Device";
0111 pfCluster_RecHitMultiplicity_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 100, 0, 100, 100, 0, 100);
0112
0113 histo = "pfCluster_Layer_HostvsDevice";
0114 histoAxis = "pfCluster_Layer_HostvsDevice;Cluster Layer Host;Cluster Layer Device";
0115 pfCluster_Layer_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 4, 0, 3, 4, 0, 3);
0116
0117 histo = "pfCluster_Depth_HostvsDevice";
0118 histoAxis = "pfCluster_Depth_HostvsDevice;Cluster Depth Host;Cluster Depth Device";
0119 pfCluster_Depth_HostvsDevice_ = ibooker.book2I(histo, histoAxis, 8, 0, 7, 8, 0, 7);
0120
0121 histo = "pfCluster_Eta_HostvsDevice";
0122 histoAxis = "pfCluster_Eta_HostvsDevice;Cluster #eta Host;Cluster #eta Device";
0123 pfCluster_Eta_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 100, -5.f, 5.f, 100, -5.f, 5.f);
0124
0125 histo = "pfCluster_Phi_HostvsDevice";
0126 histoAxis = "pfCluster_Phi_HostvsDevice;Cluster #phi Host;Cluster #phi Device";
0127 pfCluster_Phi_HostvsDevice_ = ibooker.book2D(histo, histoAxis, 100, -M_PI, M_PI, 100, -M_PI, M_PI);
0128
0129 histo = "pfCluster_DuplicateMatches_HostvsDevice";
0130 histoAxis = "pfCluster_Duplicates_HostvsDevice;Cluster Duplicates Host;Cluster Duplicates Device";
0131 pfCluster_DuplicateMatches_HostvsDevice_ = ibooker.book1I(histo, histoAxis, 100, 0., 1000);
0132 }
0133
0134 void PFHcalGPUComparisonTask::_resetMonitors(hcaldqm::UpdateFreq uf) { DQTask::_resetMonitors(uf); }
0135
0136 void PFHcalGPUComparisonTask::_process(edm::Event const& event, edm::EventSetup const&) {
0137 edm::Handle<reco::PFClusterCollection> pfClusters_ref;
0138 event.getByToken(pfClusterTok_ref_, pfClusters_ref);
0139
0140 edm::Handle<reco::PFClusterCollection> pfClusters_target;
0141 event.getByToken(pfClusterTok_target_, pfClusters_target);
0142
0143 auto lumiCache = luminosityBlockCache(event.getLuminosityBlock().index());
0144 _currentLS = lumiCache->currentLS;
0145
0146
0147 if (pfClusters_ref->size() != pfClusters_target->size())
0148 LOGVERB("PFCaloGPUComparisonTask") << " PFCluster multiplicity " << pfClusters_ref->size() << " "
0149 << pfClusters_target->size();
0150 pfCluster_Multiplicity_HostvsDevice_->Fill((float)pfClusters_ref->size(), (float)pfClusters_target->size());
0151
0152
0153
0154 std::vector<int> matched_idx;
0155 matched_idx.reserve(pfClusters_ref->size());
0156 for (unsigned i = 0; i < pfClusters_ref->size(); ++i) {
0157 bool matched = false;
0158 for (unsigned j = 0; j < pfClusters_target->size(); ++j) {
0159 if (pfClusters_ref->at(i).seed() == pfClusters_target->at(j).seed()) {
0160 if (!matched) {
0161 matched = true;
0162 matched_idx.push_back((int)j);
0163 } else {
0164 edm::LogWarning("PFCaloGPUComparisonTask") << "Found duplicate match";
0165 pfCluster_DuplicateMatches_HostvsDevice_->Fill((int)j);
0166 }
0167 }
0168 }
0169 if (!matched)
0170 matched_idx.push_back(-1);
0171 }
0172
0173
0174
0175 for (unsigned i = 0; i < pfClusters_ref->size(); ++i) {
0176 if (matched_idx[i] >= 0) {
0177 unsigned int j = matched_idx[i];
0178 int ref_energy_bin =
0179 pfCluster_Energy_HostvsDevice_->getTH2F()->GetXaxis()->FindBin(pfClusters_ref->at(i).energy());
0180 int target_energy_bin =
0181 pfCluster_Energy_HostvsDevice_->getTH2F()->GetXaxis()->FindBin(pfClusters_target->at(j).energy());
0182 if (ref_energy_bin != target_energy_bin)
0183 edm::LogPrint("PFCaloGPUComparisonTask")
0184 << "Off-diagonal energy bin entries: " << pfClusters_ref->at(i).energy() << " "
0185 << pfClusters_ref->at(i).eta() << " " << pfClusters_ref->at(i).phi() << " "
0186 << pfClusters_target->at(j).energy() << " " << pfClusters_target->at(j).eta() << " "
0187 << pfClusters_target->at(j).phi() << std::endl;
0188 pfCluster_Energy_HostvsDevice_->Fill(pfClusters_ref->at(i).energy(), pfClusters_target->at(j).energy());
0189 pfCluster_Layer_HostvsDevice_->Fill(pfClusters_ref->at(i).layer(), pfClusters_target->at(j).layer());
0190 pfCluster_Eta_HostvsDevice_->Fill(pfClusters_ref->at(i).eta(), pfClusters_target->at(j).eta());
0191 pfCluster_Phi_HostvsDevice_->Fill(pfClusters_ref->at(i).phi(), pfClusters_target->at(j).phi());
0192 pfCluster_Depth_HostvsDevice_->Fill(pfClusters_ref->at(i).depth(), pfClusters_target->at(j).depth());
0193 pfCluster_RecHitMultiplicity_HostvsDevice_->Fill((float)pfClusters_ref->at(i).recHitFractions().size(),
0194 (float)pfClusters_target->at(j).recHitFractions().size());
0195 }
0196 }
0197 }
0198
0199 std::shared_ptr<hcaldqm::Cache> PFHcalGPUComparisonTask::globalBeginLuminosityBlock(edm::LuminosityBlock const& lb,
0200 edm::EventSetup const& es) const {
0201 return DQTask::globalBeginLuminosityBlock(lb, es);
0202 }
0203
0204 void PFHcalGPUComparisonTask::globalEndLuminosityBlock(edm::LuminosityBlock const& lb, edm::EventSetup const& es) {
0205 if (_ptype != fOnline)
0206 return;
0207
0208 auto lumiCache = luminosityBlockCache(lb.index());
0209 _currentLS = lumiCache->currentLS;
0210
0211
0212 DQTask::globalEndLuminosityBlock(lb, es);
0213 }
0214
0215 void PFHcalGPUComparisonTask::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0216 edm::ParameterSetDescription desc;
0217 desc.addUntracked<std::string>("name", "pfCaloGPUCompDir");
0218 desc.addUntracked<edm::InputTag>("pfClusterToken_ref", edm::InputTag("hltParticleFlowClusterHCALSerialSync"));
0219 desc.addUntracked<edm::InputTag>("pfClusterToken_target", edm::InputTag("hltParticleFlowClusterHCAL"));
0220 descriptions.addWithDefaultLabel(desc);
0221 }
0222
0223 DEFINE_FWK_MODULE(PFHcalGPUComparisonTask);