CMS 3D CMS Logo

PFCaloGPUComparisonTask.cc
Go to the documentation of this file.
31 
32 #include <algorithm>
33 #include <cmath>
34 #include <iostream>
35 #include <string>
36 #include <utility>
37 #include <vector>
38 
39 #ifdef PFLOW_DEBUG
40 #define LOGVERB(x) edm::LogVerbatim(x)
41 #else
42 #define LOGVERB(x) LogTrace(x)
43 #endif
44 
46 public:
48  ~PFCaloGPUComparisonTask() override = default;
49  void analyze(edm::Event const& e, edm::EventSetup const& c) override;
50  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
51 
52 private:
55 
64 
66 };
67 
69  : pfClusterTok_ref_{consumes<reco::PFClusterCollection>(
70  conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_ref"))},
71  pfClusterTok_target_{
72  consumes<reco::PFClusterCollection>(conf.getUntrackedParameter<edm::InputTag>("pfClusterToken_target"))},
73  pfCaloGPUCompDir_{conf.getUntrackedParameter<std::string>("pfCaloGPUCompDir")} {}
74 
76  edm::Run const& irun,
77  edm::EventSetup const& isetup) {
78  const char* histo;
79 
80  ibooker.setCurrentFolder("ParticleFlow/" + pfCaloGPUCompDir_);
81 
82  histo = "pfCluster_Multiplicity_GPUvsCPU";
83  pfCluster_Multiplicity_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 2000, 100, 0, 2000);
84 
85  histo = "pfCluster_Energy_GPUvsCPU";
86  pfCluster_Energy_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 500, 100, 0, 500);
87 
88  histo = "pfCluster_RecHitMultiplicity_GPUvsCPU";
89  pfCluster_RecHitMultiplicity_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 100, 100, 0, 100);
90 
91  histo = "pfCluster_Layer_GPUvsCPU";
92  pfCluster_Layer_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 100, 100, 0, 100);
93 
94  histo = "pfCluster_Depth_GPUvsCPU";
95  pfCluster_Depth_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 100, 100, 0, 100);
96 
97  histo = "pfCluster_Eta_GPUvsCPU";
98  pfCluster_Eta_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 100, 100, 0, 100);
99 
100  histo = "pfCluster_Phi_GPUvsCPU";
101  pfCluster_Phi_GPUvsCPU_ = ibooker.book2D(histo, histo, 100, 0, 100, 100, 0, 100);
102 
103  histo = "pfCluster_DuplicateMatches_GPUvsCPU";
104  pfCluster_DuplicateMatches_GPUvsCPU_ = ibooker.book1D(histo, histo, 100, 0., 1000);
105 }
108  event.getByToken(pfClusterTok_ref_, pfClusters_ref);
109 
110  edm::Handle<reco::PFClusterCollection> pfClusters_target;
111  event.getByToken(pfClusterTok_target_, pfClusters_target);
112 
113  //
114  // Compare per-event PF cluster multiplicity
115 
116  if (pfClusters_ref->size() != pfClusters_target->size())
117  LOGVERB("PFCaloGPUComparisonTask") << " PFCluster multiplicity " << pfClusters_ref->size() << " "
118  << pfClusters_target->size();
119  pfCluster_Multiplicity_GPUvsCPU_->Fill((float)pfClusters_ref->size(), (float)pfClusters_target->size());
120 
121  //
122  // Find matching PF cluster pairs
123  std::vector<int> matched_idx;
124  matched_idx.reserve(pfClusters_ref->size());
125  for (unsigned i = 0; i < pfClusters_ref->size(); ++i) {
126  bool matched = false;
127  for (unsigned j = 0; j < pfClusters_target->size(); ++j) {
128  if (pfClusters_ref->at(i).seed() == pfClusters_target->at(j).seed()) {
129  if (!matched) {
130  matched = true;
131  matched_idx.push_back((int)j);
132  } else {
133  edm::LogWarning("PFCaloGPUComparisonTask") << "Found duplicate match";
135  }
136  }
137  }
138  if (!matched)
139  matched_idx.push_back(-1); // if you don't find a match, put a dummy number
140  }
141 
142  //
143  // Plot matching PF cluster variables
144  for (unsigned i = 0; i < pfClusters_ref->size(); ++i) {
145  if (matched_idx[i] >= 0) {
146  unsigned int j = matched_idx[i];
147  int ref_energy_bin = pfCluster_Energy_GPUvsCPU_->getTH2F()->GetXaxis()->FindBin(pfClusters_ref->at(i).energy());
148  int target_energy_bin =
149  pfCluster_Energy_GPUvsCPU_->getTH2F()->GetXaxis()->FindBin(pfClusters_target->at(j).energy());
150  if (ref_energy_bin != target_energy_bin)
151  edm::LogPrint("PFCaloGPUComparisonTask")
152  << "Off-diagonal energy bin entries: " << pfClusters_ref->at(i).energy() << " "
153  << pfClusters_ref->at(i).eta() << " " << pfClusters_ref->at(i).phi() << " "
154  << pfClusters_target->at(j).energy() << " " << pfClusters_target->at(j).eta() << " "
155  << pfClusters_target->at(j).phi() << std::endl;
156  pfCluster_Energy_GPUvsCPU_->Fill(pfClusters_ref->at(i).energy(), pfClusters_target->at(j).energy());
157  pfCluster_Layer_GPUvsCPU_->Fill(pfClusters_ref->at(i).layer(), pfClusters_target->at(j).layer());
158  pfCluster_Eta_GPUvsCPU_->Fill(pfClusters_ref->at(i).eta(), pfClusters_target->at(j).eta());
159  pfCluster_Phi_GPUvsCPU_->Fill(pfClusters_ref->at(i).phi(), pfClusters_target->at(j).phi());
160  pfCluster_Depth_GPUvsCPU_->Fill(pfClusters_ref->at(i).depth(), pfClusters_target->at(j).depth());
161  pfCluster_RecHitMultiplicity_GPUvsCPU_->Fill((float)pfClusters_ref->at(i).recHitFractions().size(),
162  (float)pfClusters_target->at(j).recHitFractions().size());
163  }
164  }
165 }
166 
MonitorElement * pfCluster_Phi_GPUvsCPU_
MonitorElement * pfCluster_Multiplicity_GPUvsCPU_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
MonitorElement * pfCluster_Depth_GPUvsCPU_
T getUntrackedParameter(std::string const &, T const &) const
PFCaloGPUComparisonTask(edm::ParameterSet const &conf)
void Fill(long long x)
~PFCaloGPUComparisonTask() override=default
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Warning, true > LogPrint
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterTok_ref_
MonitorElement * pfCluster_RecHitMultiplicity_GPUvsCPU_
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
MonitorElement * pfCluster_Eta_GPUvsCPU_
MonitorElement * pfCluster_DuplicateMatches_GPUvsCPU_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void analyze(edm::Event const &e, edm::EventSetup const &c) override
MonitorElement * pfCluster_Layer_GPUvsCPU_
#define LOGVERB(x)
MonitorElement * pfCluster_Energy_GPUvsCPU_
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterTok_target_
Definition: event.py:1
Definition: Run.h:45