CMS 3D CMS Logo

SiPixelCompareRecHitsSoA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelCompareRecHitsSoA
3 // Class: SiPixelCompareRecHitsSoA
4 //
7 //
8 // Author: Suvankar Roy Chowdhury, Alessandro Rossi
9 //
17 // DQM Histograming
23 // Geometry
30 
31 template <typename T>
33 public:
36 
38  ~SiPixelCompareRecHitsSoA() override = default;
39  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
40  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
41  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
47  const edm::EDGetTokenT<HitsOnHost> tokenSoAHitsCPU_; //these two are both on CPU but originally they have been
48  const edm::EDGetTokenT<HitsOnHost> tokenSoAHitsGPU_; //produced on CPU or on GPU
50  const float mind2cut_;
52  static constexpr float micron_ = 10000.;
53  const TrackerGeometry* tkGeom_ = nullptr;
54  const TrackerTopology* tTopo_ = nullptr;
56  MonitorElement* hBchargeL_[4]; // max 4 barrel hits
61  MonitorElement* hFchargeD_[2][12]; // max 12 endcap disks
66  //differences
77 };
78 //
79 // constructors
80 //
81 
82 template <typename T>
85  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
86  tokenSoAHitsCPU_(consumes(iConfig.getParameter<edm::InputTag>("pixelHitsSrcCPU"))),
87  tokenSoAHitsGPU_(consumes(iConfig.getParameter<edm::InputTag>("pixelHitsSrcGPU"))),
88  topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
89  mind2cut_(iConfig.getParameter<double>("minD2cut")) {}
90 //
91 // Begin Run
92 //
93 template <typename T>
95  tkGeom_ = &iSetup.getData(geomToken_);
96  tTopo_ = &iSetup.getData(topoToken_);
97 }
98 
99 //
100 // -- Analyze
101 //
102 template <typename T>
104  const auto& rhsoaHandleCPU = iEvent.getHandle(tokenSoAHitsCPU_);
105  const auto& rhsoaHandleGPU = iEvent.getHandle(tokenSoAHitsGPU_);
106  if (not rhsoaHandleCPU or not rhsoaHandleGPU) {
107  edm::LogWarning out("SiPixelCompareRecHitSoA");
108  if (not rhsoaHandleCPU) {
109  out << "reference (CPU) rechits not found; ";
110  }
111  if (not rhsoaHandleGPU) {
112  out << "target (GPU) rechits not found; ";
113  }
114  out << "the comparison will not run.";
115  return;
116  }
117 
118  auto const& rhsoaCPU = *rhsoaHandleCPU;
119  auto const& rhsoaGPU = *rhsoaHandleGPU;
120 
121  auto const& soa2dCPU = rhsoaCPU.const_view();
122  auto const& soa2dGPU = rhsoaGPU.const_view();
123 
124  uint32_t nHitsCPU = soa2dCPU.nHits();
125  uint32_t nHitsGPU = soa2dGPU.nHits();
126 
127  hnHits_->Fill(nHitsCPU, nHitsGPU);
128  auto detIds = tkGeom_->detUnitIds();
129  for (uint32_t i = 0; i < nHitsCPU; i++) {
130  float minD = mind2cut_;
131  uint32_t matchedHit = invalidHit_;
132  uint16_t indCPU = soa2dCPU[i].detectorIndex();
133  float xLocalCPU = soa2dCPU[i].xLocal();
134  float yLocalCPU = soa2dCPU[i].yLocal();
135  for (uint32_t j = 0; j < nHitsGPU; j++) {
136  if (soa2dGPU.detectorIndex(j) == indCPU) {
137  float dx = xLocalCPU - soa2dGPU[j].xLocal();
138  float dy = yLocalCPU - soa2dGPU[j].yLocal();
139  float distance = dx * dx + dy * dy;
140  if (distance < minD) {
141  minD = distance;
142  matchedHit = j;
143  }
144  }
145  }
146  DetId id = detIds[indCPU];
147  uint32_t chargeCPU = soa2dCPU[i].chargeAndStatus().charge;
148  int16_t sizeXCPU = std::ceil(float(std::abs(soa2dCPU[i].clusterSizeX()) / 8.));
149  int16_t sizeYCPU = std::ceil(float(std::abs(soa2dCPU[i].clusterSizeY()) / 8.));
150  uint32_t chargeGPU = 0;
151  int16_t sizeXGPU = -99;
152  int16_t sizeYGPU = -99;
153  float xLocalGPU = -999.;
154  float yLocalGPU = -999.;
155  if (matchedHit != invalidHit_) {
156  chargeGPU = soa2dGPU[matchedHit].chargeAndStatus().charge;
157  sizeXGPU = std::ceil(float(std::abs(soa2dGPU[matchedHit].clusterSizeX()) / 8.));
158  sizeYGPU = std::ceil(float(std::abs(soa2dGPU[matchedHit].clusterSizeY()) / 8.));
159  xLocalGPU = soa2dGPU[matchedHit].xLocal();
160  yLocalGPU = soa2dGPU[matchedHit].yLocal();
161  }
162  switch (id.subdetId()) {
164  hBchargeL_[tTopo_->pxbLayer(id) - 1]->Fill(chargeCPU, chargeGPU);
165  hBsizexL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeXCPU, sizeXGPU);
166  hBsizeyL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeYCPU, sizeYGPU);
167  hBposxL_[tTopo_->pxbLayer(id) - 1]->Fill(xLocalCPU, xLocalGPU);
168  hBposyL_[tTopo_->pxbLayer(id) - 1]->Fill(yLocalCPU, yLocalGPU);
169  hBchargeDiff_->Fill(chargeCPU - chargeGPU);
170  hBsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
171  hBsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
172  hBposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
173  hBposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
174  break;
176  hFchargeD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(chargeCPU, chargeGPU);
177  hFsizexD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeXCPU, sizeXGPU);
178  hFsizeyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeYCPU, sizeYGPU);
179  hFposxD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(xLocalCPU, xLocalGPU);
180  hFposyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(yLocalCPU, yLocalGPU);
181  hFchargeDiff_->Fill(chargeCPU - chargeGPU);
182  hFsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
183  hFsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
184  hFposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
185  hFposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
186  break;
187  }
188  }
189 }
190 
191 //
192 // -- Book Histograms
193 //
194 template <typename T>
196  edm::Run const& iRun,
197  edm::EventSetup const& iSetup) {
198  iBook.cd();
199  iBook.setCurrentFolder(topFolderName_);
200 
201  // clang-format off
202  //Global
203  hnHits_ = iBook.book2I("nHits", "CPUvsGPU RecHits per event;#CPU RecHits;#GPU RecHits", 200, 0, 5000,200, 0, 5000);
204  //Barrel Layer
205  for(unsigned int il=0;il<tkGeom_->numberOfLayers(PixelSubdetector::PixelBarrel);il++){
206  hBchargeL_[il] = iBook.book2I(Form("recHitsBLay%dCharge",il+1), Form("CPUvsGPU RecHits Charge Barrel Layer%d;CPU Charge;GPU Charge",il+1), 250, 0, 100000, 250, 0, 100000);
207  hBsizexL_[il] = iBook.book2I(Form("recHitsBLay%dSizex",il+1), Form("CPUvsGPU RecHits SizeX Barrel Layer%d;CPU SizeX;GPU SizeX",il+1), 30, 0, 30, 30, 0, 30);
208  hBsizeyL_[il] = iBook.book2I(Form("recHitsBLay%dSizey",il+1), Form("CPUvsGPU RecHits SizeY Barrel Layer%d;CPU SizeY;GPU SizeY",il+1), 30, 0, 30, 30, 0, 30);
209  hBposxL_[il] = iBook.book2D(Form("recHitsBLay%dPosx",il+1), Form("CPUvsGPU RecHits x-pos in Barrel Layer%d;CPU pos x;GPU pos x",il+1), 200, -5, 5, 200,-5,5);
210  hBposyL_[il] = iBook.book2D(Form("recHitsBLay%dPosy",il+1), Form("CPUvsGPU RecHits y-pos in Barrel Layer%d;CPU pos y;GPU pos y",il+1), 200, -5, 5, 200,-5,5);
211  }
212  //Endcaps
213  //Endcaps Disk
214  for(int is=0;is<2;is++){
215  int sign=is==0? -1:1;
216  for(unsigned int id=0;id<tkGeom_->numberOfLayers(PixelSubdetector::PixelEndcap);id++){
217  hFchargeD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dCharge",id*sign+sign), Form("CPUvsGPU RecHits Charge Endcaps Disk%+d;CPU Charge;GPU Charge",id*sign+sign), 250, 0, 100000, 250, 0, 100000);
218  hFsizexD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizex",id*sign+sign), Form("CPUvsGPU RecHits SizeX Endcaps Disk%+d;CPU SizeX;GPU SizeX",id*sign+sign), 30, 0, 30, 30, 0, 30);
219  hFsizeyD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizey",id*sign+sign), Form("CPUvsGPU RecHits SizeY Endcaps Disk%+d;CPU SizeY;GPU SizeY",id*sign+sign), 30, 0, 30, 30, 0, 30);
220  hFposxD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosx",id*sign+sign), Form("CPUvsGPU RecHits x-pos Endcaps Disk%+d;CPU pos x;GPU pos x",id*sign+sign), 200, -5, 5, 200, -5, 5);
221  hFposyD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosy",id*sign+sign), Form("CPUvsGPU RecHits y-pos Endcaps Disk%+d;CPU pos y;GPU pos y",id*sign+sign), 200, -5, 5, 200, -5, 5);
222  }
223  }
224  //1D differences
225  hBchargeDiff_ = iBook.book1D("rechitChargeDiffBpix","Charge differnce of rechits in BPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
226  hFchargeDiff_ = iBook.book1D("rechitChargeDiffFpix","Charge differnce of rechits in FPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
227  hBsizeXDiff_ = iBook.book1D("rechitsizeXDiffBpix","SizeX difference of rechits in BPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
228  hFsizeXDiff_ = iBook.book1D("rechitsizeXDiffFpix","SizeX difference of rechits in FPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
229  hBsizeYDiff_ = iBook.book1D("rechitsizeYDiffBpix","SizeY difference of rechits in BPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
230  hFsizeYDiff_ = iBook.book1D("rechitsizeYDiffFpix","SizeY difference of rechits in FPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
231  hBposXDiff_ = iBook.book1D("rechitsposXDiffBpix","x-position difference of rechits in BPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
232  hFposXDiff_ = iBook.book1D("rechitsposXDiffFpix","x-position difference of rechits in FPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
233  hBposYDiff_ = iBook.book1D("rechitsposYDiffBpix","y-position difference of rechits in BPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
234  hFposYDiff_ = iBook.book1D("rechitsposYDiffFpix","y-position difference of rechits in FPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
235 }
236 
237 template<typename T>
239  // monitorpixelRecHitsSoA
241  desc.add<edm::InputTag>("pixelHitsSrcCPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cpu"));
242  desc.add<edm::InputTag>("pixelHitsSrcGPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cuda"));
243  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelRecHitsCompareGPUvsCPU");
244  desc.add<double>("minD2cut", 0.0001);
245  descriptions.addWithDefaultLabel(desc);
246 }
247 
251 
TrackingRecHitSoAView< T > HitSoA
constexpr int32_t ceil(float num)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static constexpr float micron_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::EDGetTokenT< HitsOnHost > tokenSoAHitsGPU_
SiPixelCompareRecHitsSoA(const edm::ParameterSet &)
MonitorElement * hFsizexD_[2][12]
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
static constexpr uint32_t invalidHit_
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
const TrackerGeometry * tkGeom_
int iEvent
Definition: GenABIO.cc:224
~SiPixelCompareRecHitsSoA() override=default
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
MonitorElement * hFposyD_[2][12]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DetId.h:17
MonitorElement * hFchargeD_[2][12]
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
const TrackerTopology * tTopo_
HLT enums.
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<>::View TrackingRecHitSoAView
const edm::EDGetTokenT< HitsOnHost > tokenSoAHitsCPU_
MonitorElement * hFsizeyD_[2][12]
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
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
MonitorElement * hFposxD_[2][12]
Definition: Run.h:45