CMS 3D CMS Logo

PFHcalGPUComparisonTask.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 
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 
57 public:
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 
73 
82 
84 };
85 
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 
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 
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";
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 
200  edm::EventSetup const& es) const {
201  return DQTask::globalBeginLuminosityBlock(lb, es);
202 }
203 
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 
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 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void _process(edm::Event const &, edm::EventSetup const &) override
PFHcalGPUComparisonTask(edm::ParameterSet const &)
MonitorElement * book1I(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:186
MonitorElement * pfCluster_Multiplicity_HostvsDevice_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
#define LOGVERB(x)
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterTok_ref_
MonitorElement * pfCluster_Layer_HostvsDevice_
UpdateFreq
Definition: DQTask.h:32
MonitorElement * pfCluster_RecHitMultiplicity_HostvsDevice_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * pfCluster_Phi_HostvsDevice_
example_stream void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
ProcessingType _ptype
Definition: DQModule.h:44
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Warning, true > LogPrint
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterTok_target_
#define M_PI
std::shared_ptr< hcaldqm::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
MonitorElement * pfCluster_Depth_HostvsDevice_
MonitorElement * pfCluster_Energy_HostvsDevice_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
LuminosityBlockIndex index() const
MonitorElement * pfCluster_Eta_HostvsDevice_
std::string _subsystem
Definition: DQModule.h:49
MonitorElement * pfCluster_DuplicateMatches_HostvsDevice_
Log< level::Warning, false > LogWarning
MonitorElement * book2I(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:305
void _resetMonitors(hcaldqm::UpdateFreq) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: event.py:1
Definition: Run.h:45