CMS 3D CMS Logo

HcalGPUComparisonTask.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 
15 
16 #include <cmath>
17 
18 using namespace hcaldqm;
19 using namespace hcaldqm::constants;
20 using namespace hcaldqm::filter;
21 
23 public:
25  ~HcalGPUComparisonTask() override = default;
26 
27  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
28  std::shared_ptr<hcaldqm::Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
29  edm::EventSetup const&) const override;
30  void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
31  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
32 
33 private:
34  void _process(edm::Event const&, edm::EventSetup const&) override;
35  void _resetMonitors(hcaldqm::UpdateFreq) override;
36 
37  edm::InputTag tagHBHE_ref_; //CPU version
42 
43  // GPU reco test verification
47 };
48 
50  : DQTask(ps),
51  tagHBHE_ref_(ps.getUntrackedParameter<edm::InputTag>("tagHBHE_ref", edm::InputTag("hltHbhereco@cpu"))),
52  tagHBHE_target_(ps.getUntrackedParameter<edm::InputTag>("tagHBHE_target", edm::InputTag("hltHbhereco@cuda"))),
53  tokHBHE_ref_(consumes<HBHERecHitCollection>(tagHBHE_ref_)),
54  tokHBHE_target_(consumes<HBHERecHitCollection>(tagHBHE_target_)),
55  hcalDbServiceToken_(esConsumes<HcalDbService, HcalDbRecord, edm::Transition::BeginRun>()) {}
56 
58  edm::Run const& r,
59  edm::EventSetup const& es) {
61 
62  // GET WHAT YOU NEED
64  _emap = dbs->getHcalMapping();
65 
66  // Book monitoring elements
68  "EnergyGPUvsCPU",
73  0);
75  "EnergyDiffGPUCPU",
79  0);
81  "EnergyDiffGPUCPU",
86  0);
87 
91 }
92 
93 /* virtual */ void HcalGPUComparisonTask::_resetMonitors(hcaldqm::UpdateFreq uf) { DQTask::_resetMonitors(uf); }
94 
95 /* virtual */ void HcalGPUComparisonTask::_process(edm::Event const& e, edm::EventSetup const&) {
98 
99  if (!(e.getByToken(tokHBHE_ref_, chbhe_ref)))
100  _logger.dqmthrow("The CPU HBHERecHitCollection \"" + tagHBHE_ref_.encode() + "\" is not available");
101  if (!(e.getByToken(tokHBHE_target_, chbhe_target)))
102  _logger.dqmthrow("The GPU HBHERecHitCollection \"" + tagHBHE_target_.encode() + "\" is not available");
103 
104  auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
105  _currentLS = lumiCache->currentLS;
106 
107  std::map<HcalDetId, double> mRecHitEnergy;
108 
109  for (HBHERecHitCollection::const_iterator it = chbhe_ref->begin(); it != chbhe_ref->end(); ++it) {
110  double energy = it->energy();
111 
112  // Explicit check on the DetIds present in the Collection
113  HcalDetId did = it->id();
114 
115  if (mRecHitEnergy.find(did) == mRecHitEnergy.end())
116  mRecHitEnergy.insert(std::make_pair(did, energy));
117  else
118  edm::LogError("HcalDQM|RechitTask") << "Duplicate Rechit from the same HcalDetId";
119  }
120 
121  for (HBHERecHitCollection::const_iterator it = chbhe_target->begin(); it != chbhe_target->end(); ++it) {
122  double energy = it->energy();
123  HcalDetId did = it->id();
124 
125  if (mRecHitEnergy.find(did) != mRecHitEnergy.end()) {
126  energyGPUvsCPU_subdet_.fill(did, mRecHitEnergy[did], energy);
127 
128  if (mRecHitEnergy[did] != 0.) {
129  energyDiffGPUCPU_subdet_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
130  if (energy > 0.1)
131  energyDiffGPUCPU_depth_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
132  } else if (mRecHitEnergy[did] == 0. && energy == 0.) {
134  if (energy > 0.1)
135  energyDiffGPUCPU_depth_.fill(did, 0.);
136  } else {
137  energyDiffGPUCPU_subdet_.fill(did, -1.);
138  if (energy > 0.1)
139  energyDiffGPUCPU_depth_.fill(did, -1.);
140  }
141 
142  mRecHitEnergy.erase(did);
143  } else
144  edm::LogError("HcalDQM|RechitTask") << "GPU Rechit id not found in CPU Rechit id collection";
145  }
146  if (!mRecHitEnergy.empty())
147  edm::LogError("HcalDQM|RechitTask") << "CPU Rechit id not found in GPU Rechit id collection";
148 }
149 
151  edm::EventSetup const& es) const {
152  return DQTask::globalBeginLuminosityBlock(lb, es);
153 }
154 
156  edm::EventSetup const& es) {
157  if (_ptype != fOnline)
158  return;
159 
160  auto lumiCache = luminosityBlockCache(lb.index());
161  _currentLS = lumiCache->currentLS;
162 
163  // in the end always do the DQTask::endLumi
164  DQTask::globalEndLuminosityBlock(lb, es);
165 }
166 
169  desc.addUntracked<std::string>("name", "HcalGPUComparisonTask");
170  desc.addUntracked<int>("debug", 0);
171  desc.addUntracked<int>("runkeyVal", 0);
172  desc.addUntracked<std::string>("runkeyName", "pp_run");
173  desc.addUntracked<int>("ptype", 1);
174  desc.addUntracked<bool>("mtype", true);
175  desc.addUntracked<std::string>("subsystem", "Hcal");
176  desc.addUntracked<edm::InputTag>("tagHBHE_ref", edm::InputTag("hbhereco@cpu"));
177  desc.addUntracked<edm::InputTag>("tagHBHE_target", edm::InputTag("hbhereco@cuda"));
178  desc.addUntracked<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
179  descriptions.addWithDefaultLabel(desc);
180 }
181 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual void initialize(std::string const &folder, hashfunctions::HashType, quantity::Quantity *, quantity::Quantity *qy=new quantity::ValueQuantity(quantity::fN), int debug=0)
Definition: Container1D.cc:33
void fill(HcalDetId const &) override
std::string encode() const
Definition: InputTag.cc:159
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void dqmthrow(std::string const &msg) const
Definition: Logger.h:12
void _resetMonitors(hcaldqm::UpdateFreq) override
UpdateFreq
Definition: DQTask.h:32
std::vector< T >::const_iterator const_iterator
HcalGPUComparisonTask(edm::ParameterSet const &)
const HcalElectronicsMap * getHcalMapping() const
void _process(edm::Event const &, edm::EventSetup const &) override
hcaldqm::Container2D energyGPUvsCPU_subdet_
Log< level::Error, false > LogError
edm::EDGetTokenT< HBHERecHitCollection > tokHBHE_target_
example_stream void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
ProcessingType _ptype
Definition: DQModule.h:44
virtual void fill(uint32_t)
Definition: Container1D.cc:73
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Transition
Definition: Transition.h:12
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Logger _logger
Definition: DQModule.h:55
const_iterator begin() const
std::string _name
Definition: DQModule.h:42
HcalElectronicsMap const * _emap
Definition: DQTask.h:81
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
edm::EDGetTokenT< HBHERecHitCollection > tokHBHE_ref_
const_iterator end() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void book(DQMStore::IBooker &, HcalElectronicsMap const *, std::string subsystem="Hcal", std::string aux="")
Definition: Container1D.cc:592
virtual void initialize(std::string const &folder, hashfunctions::HashType, quantity::Quantity *, quantity::Quantity *, quantity::Quantity *qz=new quantity::ValueQuantity(quantity::fN), int debug=0)
Definition: Container2D.cc:25
edm::ESGetToken< HcalDbService, HcalDbRecord > hcalDbServiceToken_
hcaldqm::ContainerProf2D energyDiffGPUCPU_depth_
void book(DQMStore::IBooker &, HcalElectronicsMap const *, std::string subsystem="Hcal", std::string aux="") override
void initialize(std::string const &folder, hashfunctions::HashType, quantity::Quantity *, quantity::Quantity *, quantity::Quantity *qz=new quantity::ValueQuantity(quantity::fEnergy), int debug=0) override
LuminosityBlockIndex index() const
HLT enums.
void fill(HcalDetId const &) override
Definition: Container2D.cc:52
std::string _subsystem
Definition: DQModule.h:49
hcaldqm::Container1D energyDiffGPUCPU_subdet_
std::shared_ptr< hcaldqm::Cache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
void book(DQMStore::IBooker &, HcalElectronicsMap const *, std::string subsystem="Hcal", std::string aux="") override
Definition: Container2D.cc:567
Definition: Run.h:45
ib
Definition: cuy.py:661