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&) {
96  auto const chbhe_ref = e.getHandle(tokHBHE_ref_);
97  auto const chbhe_target = e.getHandle(tokHBHE_target_);
98 
99  if (not(chbhe_ref.isValid() and chbhe_target.isValid())) {
100  edm::LogWarning("HcalGPUComparisonTask")
101  << "Either CPU or GPU RecHit Collection is unavailable, will not fill this event.";
102  return;
103  }
104 
105  auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
106  _currentLS = lumiCache->currentLS;
107 
108  std::map<HcalDetId, double> mRecHitEnergy;
109 
110  for (HBHERecHitCollection::const_iterator it = chbhe_ref->begin(); it != chbhe_ref->end(); ++it) {
111  double energy = it->energy();
112 
113  // Explicit check on the DetIds present in the Collection
114  HcalDetId did = it->id();
115 
116  if (mRecHitEnergy.find(did) == mRecHitEnergy.end())
117  mRecHitEnergy.insert(std::make_pair(did, energy));
118  else
119  edm::LogError("HcalGPUComparisonTask") << "Duplicate Rechit from the same HcalDetId";
120  ;
121  }
122 
123  for (HBHERecHitCollection::const_iterator it = chbhe_target->begin(); it != chbhe_target->end(); ++it) {
124  double energy = it->energy();
125  HcalDetId did = it->id();
126 
127  if (mRecHitEnergy.find(did) != mRecHitEnergy.end()) {
128  energyGPUvsCPU_subdet_.fill(did, mRecHitEnergy[did], energy);
129 
130  if (mRecHitEnergy[did] != 0.) {
131  energyDiffGPUCPU_subdet_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
132  if (energy > 0.1)
133  energyDiffGPUCPU_depth_.fill(did, (energy - mRecHitEnergy[did]) / mRecHitEnergy[did]);
134  } else if (mRecHitEnergy[did] == 0. && energy == 0.) {
136  if (energy > 0.1)
137  energyDiffGPUCPU_depth_.fill(did, 0.);
138  } else {
139  energyDiffGPUCPU_subdet_.fill(did, -1.);
140  if (energy > 0.1)
141  energyDiffGPUCPU_depth_.fill(did, -1.);
142  }
143 
144  mRecHitEnergy.erase(did);
145  } else {
146  if (energy > 2.)
147  edm::LogError("HcalGPUComparisonTask")
148  << "Energetic GPU Rechit exist, but not reconstructed by CPU. DetId = " << did;
149  }
150  }
151  if (!mRecHitEnergy.empty()) {
152  for (auto const& rhpair : mRecHitEnergy) {
153  if (rhpair.second > 2.)
154  edm::LogError("HcalGPUComparisonTask")
155  << "Energetic CPU Rechit exist, but not reconstructed by GPU. DetId = " << rhpair.first;
156  }
157  }
158 }
159 
161  edm::EventSetup const& es) const {
162  return DQTask::globalBeginLuminosityBlock(lb, es);
163 }
164 
166  edm::EventSetup const& es) {
167  if (_ptype != fOnline)
168  return;
169 
170  auto lumiCache = luminosityBlockCache(lb.index());
171  _currentLS = lumiCache->currentLS;
172 
173  // in the end always do the DQTask::endLumi
174  DQTask::globalEndLuminosityBlock(lb, es);
175 }
176 
179  desc.addUntracked<std::string>("name", "HcalGPUComparisonTask");
180  desc.addUntracked<int>("debug", 0);
181  desc.addUntracked<int>("runkeyVal", 0);
182  desc.addUntracked<std::string>("runkeyName", "pp_run");
183  desc.addUntracked<int>("ptype", 1);
184  desc.addUntracked<bool>("mtype", true);
185  desc.addUntracked<std::string>("subsystem", "Hcal");
186  desc.addUntracked<edm::InputTag>("tagHBHE_ref", edm::InputTag("hbhereco@cpu"));
187  desc.addUntracked<edm::InputTag>("tagHBHE_target", edm::InputTag("hbhereco@cuda"));
188  desc.addUntracked<edm::InputTag>("tagRaw", edm::InputTag("rawDataCollector"));
189  descriptions.addWithDefaultLabel(desc);
190 }
191 
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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)
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_
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
Log< level::Warning, false > LogWarning
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