Skip to content

Commit ab23b8e

Browse files
authored
Merge pull request #45079 from waredjeb/DQM_for_PF_NewClient_CMSSW_14_1_0_pre4
Add ParticleFlow Client for Online DQM - GPUvsCPU comparison
2 parents 51b889c + b9a0564 commit ab23b8e

File tree

4 files changed

+378
-0
lines changed

4 files changed

+378
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#-------------------------------------
2+
# PF DQM Application using New DQM Sources/Clients
3+
# Taken from HCAL DQM Client
4+
#-------------------------------------
5+
6+
#-------------------------------------
7+
# Standard Python Imports
8+
#-------------------------------------
9+
import os, sys, socket, string
10+
11+
#-------------------------------------
12+
# Standard CMSSW Imports/Definitions
13+
#-------------------------------------
14+
import FWCore.ParameterSet.Config as cms
15+
from Configuration.Eras.Era_Run3_cff import Run3
16+
process = cms.Process('PFDQM', Run3)
17+
subsystem = 'ParticleFlow'
18+
cmssw = os.getenv("CMSSW_VERSION").split("_")
19+
debugstr = "### PFDQM::cfg::DEBUG: "
20+
warnstr = "### PFDQM::cfg::WARN: "
21+
errorstr = "### PFDQM::cfg::ERROR:"
22+
useOfflineGT = False
23+
useFileInput = False
24+
useMap = False
25+
unitTest = 'unitTest=True' in sys.argv
26+
27+
#-------------------------------------
28+
# Central DQM Stuff imports
29+
#-------------------------------------
30+
from DQM.Integration.config.online_customizations_cfi import *
31+
32+
if useOfflineGT:
33+
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
34+
process.GlobalTag.globaltag = autoCond['run3_data_prompt']
35+
else:
36+
process.load('DQM.Integration.config.FrontierCondition_GT_cfi')
37+
38+
if unitTest:
39+
process.load("DQM.Integration.config.unitteststreamerinputsource_cfi")
40+
from DQM.Integration.config.unitteststreamerinputsource_cfi import options
41+
elif useFileInput:
42+
process.load("DQM.Integration.config.fileinputsource_cfi")
43+
from DQM.Integration.config.fileinputsource_cfi import options
44+
else:
45+
process.load('DQM.Integration.config.inputsource_cfi')
46+
from DQM.Integration.config.inputsource_cfi import options
47+
48+
process.load('DQM.Integration.config.environment_cfi')
49+
50+
#-------------------------------------
51+
# Central DQM Customization
52+
#-------------------------------------
53+
54+
if not useFileInput:
55+
# stream label
56+
if process.runType.getRunType() == process.runType.hi_run:
57+
process.source.streamLabel = "streamHIDQMGPUvsCPU"
58+
else:
59+
process.source.streamLabel = "streamDQMGPUvsCPU"
60+
61+
process.dqmEnv.subSystemFolder = subsystem
62+
process.dqmSaver.tag = 'PFGPU'
63+
process.dqmSaver.runNumber = options.runNumber
64+
process.dqmSaverPB.tag = 'PFGPU'
65+
process.dqmSaverPB.runNumber = options.runNumber
66+
process = customise(process)
67+
process.DQMStore.verbose = 0
68+
if not unitTest and not useFileInput :
69+
if not options.BeamSplashRun :
70+
process.source.minEventsPerLumi = 100
71+
72+
#-------------------------------------
73+
# CMSSW/Hcal non-DQM Related Module import
74+
#-------------------------------------
75+
process.load("Configuration.StandardSequences.GeometryRecoDB_cff")
76+
process.load('FWCore.MessageLogger.MessageLogger_cfi')
77+
78+
#-------------------------------------
79+
# CMSSW/Hcal non-DQM Related Module Settings
80+
# -> runType
81+
# -> Generic Input tag for the Raw Collection
82+
# -> cmssw version
83+
#----------------------------------------------
84+
85+
runType = process.runType.getRunType()
86+
runTypeName = process.runType.getRunTypeName()
87+
isCosmicRun = runTypeName=="cosmic_run" or runTypeName=="cosmic_run_stage1"
88+
isHeavyIon = runTypeName=="hi_run"
89+
cmssw = os.getenv("CMSSW_VERSION").split("_")
90+
91+
92+
#-------------------------------------
93+
# PF DQM Tasks and Harvesters import
94+
# New Style
95+
#-------------------------------------
96+
process.load('DQM.PFTasks.pfHcalGPUComparisonTask_cfi')
97+
98+
#-------------------------------------
99+
# Some Settings before Finishing up
100+
# New Style Modules
101+
#-------------------------------------
102+
oldsubsystem = subsystem
103+
#-------------------------------------
104+
# Hcal DQM Tasks/Clients Sequences Definition
105+
#-------------------------------------
106+
process.tasksPath = cms.Path(
107+
process.pfHcalGPUComparisonTask
108+
)
109+
110+
#-------------------------------------
111+
# Paths/Sequences Definitions
112+
#-------------------------------------
113+
114+
process.dqmPath = cms.EndPath(
115+
process.dqmEnv)
116+
process.dqmPath1 = cms.EndPath(
117+
process.dqmSaver
118+
*process.dqmSaverPB
119+
)
120+
121+
process.schedule = cms.Schedule(
122+
process.tasksPath,
123+
process.dqmPath,
124+
process.dqmPath1
125+
)
126+
127+
#-------------------------------------
128+
# Scheduling and Process Customizations
129+
#-------------------------------------
130+
process.options = cms.untracked.PSet(
131+
Rethrow = cms.untracked.vstring(
132+
"TooManyProducts",
133+
"TooFewProducts"
134+
),
135+
TryToContinue = cms.untracked.vstring('ProductNotFound')
136+
)
137+
process.options.wantSummary = True
138+
139+
# tracer
140+
#process.Tracer = cms.Service("Tracer")
141+
print("Final Source settings:", process.source)
142+
process = customise(process)

DQM/PFTasks/BuildFile.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<use name="FWCore/Framework"/>
2+
<use name="rootmath"/>
3+
<use name="DQM/HcalCommon"/>
4+
<export>
5+
<lib name="PFTasks"/>
6+
</export>

DQM/PFTasks/plugins/BuildFile.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<use name="FWCore/Framework"/>
2+
<use name="DataFormats/ParticleFlowReco"/>
3+
<use name="DataFormats/ParticleFlowCandidate"/>
4+
<use name="rootmath"/>
5+
<use name="DQM/HcalTasks"/>
6+
<use name="DQM/HcalCommon"/>
7+
<flags EDM_PLUGIN="1"/>
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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

Comments
 (0)