CMS 3D CMS Logo

SiPixelPhase1CompareRecHitsSoA.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelPhase1CompareRecHitsSoA
3 // Class: SiPixelPhase1CompareRecHitsSoA
4 //
7 //
8 // Author: Suvankar Roy Chowdhury, Alessandro Rossi
9 //
17 // DQM Histograming
22 // Geometry
29 
31 public:
33  ~SiPixelPhase1CompareRecHitsSoA() override = default;
34  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
35  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
36  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 private:
45  const float mind2cut_;
46  static constexpr uint32_t invalidHit_ = std::numeric_limits<uint32_t>::max();
47  static constexpr float micron_ = 10000.;
48  const TrackerGeometry* tkGeom_ = nullptr;
49  const TrackerTopology* tTopo_ = nullptr;
61  //differences
72 };
73 //
74 // constructors
75 //
76 
79  topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
80  tokenSoAHitsCPU_(consumes<TrackingRecHit2DCPU>(iConfig.getParameter<edm::InputTag>("pixelHitsSrcCPU"))),
81  tokenSoAHitsGPU_(consumes<TrackingRecHit2DCPU>(iConfig.getParameter<edm::InputTag>("pixelHitsSrcGPU"))),
82  topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
83  mind2cut_(iConfig.getParameter<double>("minD2cut")) {}
84 //
85 // Begin Run
86 //
88  tkGeom_ = &iSetup.getData(geomToken_);
89  tTopo_ = &iSetup.getData(topoToken_);
90 }
91 
92 //
93 // -- Analyze
94 //
96  const auto& rhsoaHandleCPU = iEvent.getHandle(tokenSoAHitsCPU_);
97  const auto& rhsoaHandleGPU = iEvent.getHandle(tokenSoAHitsGPU_);
98  if (not rhsoaHandleCPU or not rhsoaHandleGPU) {
99  edm::LogWarning out("SiPixelPhase1CompareRecHitSoA");
100  if (not rhsoaHandleCPU) {
101  out << "reference (cpu) rechits not found; ";
102  }
103  if (not rhsoaHandleGPU) {
104  out << "target (gpu) rechits not found; ";
105  }
106  out << "the comparison will not run.";
107  return;
108  }
109  auto const& rhsoaCPU = *rhsoaHandleCPU;
110  const TrackingRecHit2DSOAView* soa2dCPU = rhsoaCPU.view();
111  auto const& rhsoaGPU = *rhsoaHandleGPU;
112  const TrackingRecHit2DSOAView* soa2dGPU = rhsoaGPU.view();
113 
114  uint32_t nHitsCPU = soa2dCPU->nHits();
115  uint32_t nHitsGPU = soa2dGPU->nHits();
116  hnHits_->Fill(nHitsCPU, nHitsGPU);
117  auto detIds = tkGeom_->detUnitIds();
118  for (uint32_t i = 0; i < nHitsCPU; i++) {
119  float minD = mind2cut_;
120  uint32_t matchedHit = invalidHit_;
121  uint16_t indCPU = soa2dCPU->detectorIndex(i);
122  float xLocalCPU = soa2dCPU->xLocal(i);
123  float yLocalCPU = soa2dCPU->yLocal(i);
124  for (uint32_t j = 0; j < nHitsGPU; j++) {
125  if (soa2dGPU->detectorIndex(j) == indCPU) {
126  float dx = xLocalCPU - soa2dGPU->xLocal(j);
127  float dy = yLocalCPU - soa2dGPU->yLocal(j);
128  float distance = dx * dx + dy * dy;
129  if (distance < minD) {
130  minD = distance;
131  matchedHit = j;
132  }
133  }
134  }
135  DetId id = detIds[indCPU];
136  uint32_t chargeCPU = soa2dCPU->charge(i);
137  int16_t sizeXCPU = std::ceil(float(std::abs(soa2dCPU->clusterSizeX(i)) / 8.));
138  int16_t sizeYCPU = std::ceil(float(std::abs(soa2dCPU->clusterSizeY(i)) / 8.));
139  uint32_t chargeGPU = 0;
140  int16_t sizeXGPU = -99;
141  int16_t sizeYGPU = -99;
142  float xLocalGPU = -999.;
143  float yLocalGPU = -999.;
144  if (matchedHit != invalidHit_) {
145  chargeGPU = soa2dGPU->charge(matchedHit);
146  sizeXGPU = std::ceil(float(std::abs(soa2dGPU->clusterSizeX(matchedHit)) / 8.));
147  sizeYGPU = std::ceil(float(std::abs(soa2dGPU->clusterSizeY(matchedHit)) / 8.));
148  xLocalGPU = soa2dGPU->xLocal(matchedHit);
149  yLocalGPU = soa2dGPU->yLocal(matchedHit);
150  }
151  switch (id.subdetId()) {
153  hBchargeL_[tTopo_->pxbLayer(id) - 1]->Fill(chargeCPU, chargeGPU);
154  hBsizexL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeXCPU, sizeXGPU);
155  hBsizeyL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeYCPU, sizeYGPU);
156  hBposxL_[tTopo_->pxbLayer(id) - 1]->Fill(xLocalCPU, xLocalGPU);
157  hBposyL_[tTopo_->pxbLayer(id) - 1]->Fill(yLocalCPU, yLocalGPU);
158  hBchargeDiff_->Fill(chargeCPU - chargeGPU);
159  hBsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
160  hBsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
161  hBposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
162  hBposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
163  break;
165  hFchargeD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(chargeCPU, chargeGPU);
166  hFsizexD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeXCPU, sizeXGPU);
167  hFsizeyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeYCPU, sizeYGPU);
168  hFposxD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(xLocalCPU, xLocalGPU);
169  hFposyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(yLocalCPU, yLocalGPU);
170  hFchargeDiff_->Fill(chargeCPU - chargeGPU);
171  hFsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
172  hFsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
173  hFposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
174  hFposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
175  break;
176  }
177  }
178 }
179 
180 //
181 // -- Book Histograms
182 //
184  edm::Run const& iRun,
185  edm::EventSetup const& iSetup) {
186  iBook.cd();
188 
189  // clang-format off
190  //Global
191  hnHits_ = iBook.book2I("nHits", "CPUvsGPU RecHits per event;#CPU RecHits;#GPU RecHits", 200, 0, 5000,200, 0, 5000);
192  //Barrel Layer
193  for(unsigned int il=0;il<tkGeom_->numberOfLayers(PixelSubdetector::PixelBarrel);il++){
194  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);
195  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);
196  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);
197  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);
198  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);
199  }
200  //Endcaps
201  //Endcaps Disk
202  for(int is=0;is<2;is++){
203  int sign=is==0? -1:1;
204  for(unsigned int id=0;id<tkGeom_->numberOfLayers(PixelSubdetector::PixelEndcap);id++){
205  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);
206  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);
207  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);
208  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);
209  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);
210  }
211  }
212  //1D differences
213  hBchargeDiff_ = iBook.book1D("rechitChargeDiffBpix","Charge differnce of rechits in BPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
214  hFchargeDiff_ = iBook.book1D("rechitChargeDiffFpix","Charge differnce of rechits in FPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
215  hBsizeXDiff_ = iBook.book1D("rechitsizeXDiffBpix","SizeX difference of rechits in BPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
216  hFsizeXDiff_ = iBook.book1D("rechitsizeXDiffFpix","SizeX difference of rechits in FPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
217  hBsizeYDiff_ = iBook.book1D("rechitsizeYDiffBpix","SizeY difference of rechits in BPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
218  hFsizeYDiff_ = iBook.book1D("rechitsizeYDiffFpix","SizeY difference of rechits in FPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
219  hBposXDiff_ = iBook.book1D("rechitsposXDiffBpix","x-position difference of rechits in BPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
220  hFposXDiff_ = iBook.book1D("rechitsposXDiffFpix","x-position difference of rechits in FPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
221  hBposYDiff_ = iBook.book1D("rechitsposYDiffBpix","y-position difference of rechits in BPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
222  hFposYDiff_ = iBook.book1D("rechitsposYDiffFpix","y-position difference of rechits in FPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
223 }
224 
226  // monitorpixelRecHitsSoA
228  desc.add<edm::InputTag>("pixelHitsSrcCPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cpu"));
229  desc.add<edm::InputTag>("pixelHitsSrcGPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cuda"));
230  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelRecHitsCompareGPUvsCPU");
231  desc.add<double>("minD2cut", 0.0001);
232  descriptions.addWithDefaultLabel(desc);
233 }
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr int32_t ceil(float num)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int pxbLayer(const DetId &id) const
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
unsigned int numberOfLayers(int subdet) const
const edm::EDGetTokenT< TrackingRecHit2DCPU > tokenSoAHitsGPU_
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
void Fill(long long x)
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
int iEvent
Definition: GenABIO.cc:224
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
unsigned int pxfDisk(const DetId &id) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Definition: DetId.h:17
unsigned int pxfSide(const DetId &id) const
const edm::EDGetTokenT< TrackingRecHit2DCPU > tokenSoAHitsCPU_
SiPixelPhase1CompareRecHitsSoA(const edm::ParameterSet &)
~SiPixelPhase1CompareRecHitsSoA() override=default
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
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:212
HLT enums.
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
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:296
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
Definition: Run.h:45