Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-21 03:38:47

0001 // -*- C++ -*-
0002 // Package:    SiPixelPhase1CompareRecHitsSoA
0003 // Class:      SiPixelPhase1CompareRecHitsSoA
0004 //
0005 /**\class SiPixelPhase1CompareRecHitsSoA SiPixelPhase1CompareRecHitsSoA.cc 
0006 */
0007 //
0008 // Author: Suvankar Roy Chowdhury, Alessandro Rossi
0009 //
0010 #include "DataFormats/Math/interface/approx_atan2.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 // DQM Histograming
0018 #include "DQMServices/Core/interface/MonitorElement.h"
0019 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0020 #include "DQMServices/Core/interface/DQMStore.h"
0021 #include "CUDADataFormats/TrackingRecHit/interface/TrackingRecHit2DHeterogeneous.h"
0022 // Geometry
0023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0024 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0025 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0026 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0027 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0028 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0029 
0030 class SiPixelPhase1CompareRecHitsSoA : public DQMEDAnalyzer {
0031 public:
0032   explicit SiPixelPhase1CompareRecHitsSoA(const edm::ParameterSet&);
0033   ~SiPixelPhase1CompareRecHitsSoA() override = default;
0034   void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0035   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
0036   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0037   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0038 
0039 private:
0040   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0041   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0042   const edm::EDGetTokenT<TrackingRecHit2DCPU> tokenSoAHitsCPU_;
0043   const edm::EDGetTokenT<TrackingRecHit2DCPU> tokenSoAHitsGPU_;
0044   const std::string topFolderName_;
0045   const float mind2cut_;
0046   static constexpr uint32_t invalidHit_ = std::numeric_limits<uint32_t>::max();
0047   static constexpr float micron_ = 10000.;
0048   const TrackerGeometry* tkGeom_ = nullptr;
0049   const TrackerTopology* tTopo_ = nullptr;
0050   MonitorElement* hnHits_;
0051   MonitorElement* hBchargeL_[4];
0052   MonitorElement* hBsizexL_[4];
0053   MonitorElement* hBsizeyL_[4];
0054   MonitorElement* hBposxL_[4];
0055   MonitorElement* hBposyL_[4];
0056   MonitorElement* hFchargeD_[2][3];
0057   MonitorElement* hFsizexD_[2][3];
0058   MonitorElement* hFsizeyD_[2][3];
0059   MonitorElement* hFposxD_[2][3];
0060   MonitorElement* hFposyD_[2][3];
0061   //differences
0062   MonitorElement* hBchargeDiff_;
0063   MonitorElement* hFchargeDiff_;
0064   MonitorElement* hBsizeXDiff_;
0065   MonitorElement* hFsizeXDiff_;
0066   MonitorElement* hBsizeYDiff_;
0067   MonitorElement* hFsizeYDiff_;
0068   MonitorElement* hBposXDiff_;
0069   MonitorElement* hFposXDiff_;
0070   MonitorElement* hBposYDiff_;
0071   MonitorElement* hFposYDiff_;
0072 };
0073 //
0074 // constructors
0075 //
0076 
0077 SiPixelPhase1CompareRecHitsSoA::SiPixelPhase1CompareRecHitsSoA(const edm::ParameterSet& iConfig)
0078     : geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0079       topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
0080       tokenSoAHitsCPU_(consumes<TrackingRecHit2DCPU>(iConfig.getParameter<edm::InputTag>("pixelHitsSrcCPU"))),
0081       tokenSoAHitsGPU_(consumes<TrackingRecHit2DCPU>(iConfig.getParameter<edm::InputTag>("pixelHitsSrcGPU"))),
0082       topFolderName_(iConfig.getParameter<std::string>("topFolderName")),
0083       mind2cut_(iConfig.getParameter<double>("minD2cut")) {}
0084 //
0085 // Begin Run
0086 //
0087 void SiPixelPhase1CompareRecHitsSoA::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0088   tkGeom_ = &iSetup.getData(geomToken_);
0089   tTopo_ = &iSetup.getData(topoToken_);
0090 }
0091 
0092 //
0093 // -- Analyze
0094 //
0095 void SiPixelPhase1CompareRecHitsSoA::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0096   const auto& rhsoaHandleCPU = iEvent.getHandle(tokenSoAHitsCPU_);
0097   const auto& rhsoaHandleGPU = iEvent.getHandle(tokenSoAHitsGPU_);
0098   if (not rhsoaHandleCPU or not rhsoaHandleGPU) {
0099     edm::LogWarning out("SiPixelPhase1CompareRecHitSoA");
0100     if (not rhsoaHandleCPU) {
0101       out << "reference (cpu) rechits not found; ";
0102     }
0103     if (not rhsoaHandleGPU) {
0104       out << "target (gpu) rechits not found; ";
0105     }
0106     out << "the comparison will not run.";
0107     return;
0108   }
0109   auto const& rhsoaCPU = *rhsoaHandleCPU;
0110   const TrackingRecHit2DSOAView* soa2dCPU = rhsoaCPU.view();
0111   auto const& rhsoaGPU = *rhsoaHandleGPU;
0112   const TrackingRecHit2DSOAView* soa2dGPU = rhsoaGPU.view();
0113 
0114   uint32_t nHitsCPU = soa2dCPU->nHits();
0115   uint32_t nHitsGPU = soa2dGPU->nHits();
0116   hnHits_->Fill(nHitsCPU, nHitsGPU);
0117   auto detIds = tkGeom_->detUnitIds();
0118   for (uint32_t i = 0; i < nHitsCPU; i++) {
0119     float minD = mind2cut_;
0120     uint32_t matchedHit = invalidHit_;
0121     uint16_t indCPU = soa2dCPU->detectorIndex(i);
0122     float xLocalCPU = soa2dCPU->xLocal(i);
0123     float yLocalCPU = soa2dCPU->yLocal(i);
0124     for (uint32_t j = 0; j < nHitsGPU; j++) {
0125       if (soa2dGPU->detectorIndex(j) == indCPU) {
0126         float dx = xLocalCPU - soa2dGPU->xLocal(j);
0127         float dy = yLocalCPU - soa2dGPU->yLocal(j);
0128         float distance = dx * dx + dy * dy;
0129         if (distance < minD) {
0130           minD = distance;
0131           matchedHit = j;
0132         }
0133       }
0134     }
0135     DetId id = detIds[indCPU];
0136     uint32_t chargeCPU = soa2dCPU->charge(i);
0137     int16_t sizeXCPU = std::ceil(float(std::abs(soa2dCPU->clusterSizeX(i)) / 8.));
0138     int16_t sizeYCPU = std::ceil(float(std::abs(soa2dCPU->clusterSizeY(i)) / 8.));
0139     uint32_t chargeGPU = 0;
0140     int16_t sizeXGPU = -99;
0141     int16_t sizeYGPU = -99;
0142     float xLocalGPU = -999.;
0143     float yLocalGPU = -999.;
0144     if (matchedHit != invalidHit_) {
0145       chargeGPU = soa2dGPU->charge(matchedHit);
0146       sizeXGPU = std::ceil(float(std::abs(soa2dGPU->clusterSizeX(matchedHit)) / 8.));
0147       sizeYGPU = std::ceil(float(std::abs(soa2dGPU->clusterSizeY(matchedHit)) / 8.));
0148       xLocalGPU = soa2dGPU->xLocal(matchedHit);
0149       yLocalGPU = soa2dGPU->yLocal(matchedHit);
0150     }
0151     switch (id.subdetId()) {
0152       case PixelSubdetector::PixelBarrel:
0153         hBchargeL_[tTopo_->pxbLayer(id) - 1]->Fill(chargeCPU, chargeGPU);
0154         hBsizexL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeXCPU, sizeXGPU);
0155         hBsizeyL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeYCPU, sizeYGPU);
0156         hBposxL_[tTopo_->pxbLayer(id) - 1]->Fill(xLocalCPU, xLocalGPU);
0157         hBposyL_[tTopo_->pxbLayer(id) - 1]->Fill(yLocalCPU, yLocalGPU);
0158         hBchargeDiff_->Fill(chargeCPU - chargeGPU);
0159         hBsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
0160         hBsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
0161         hBposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
0162         hBposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
0163         break;
0164       case PixelSubdetector::PixelEndcap:
0165         hFchargeD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(chargeCPU, chargeGPU);
0166         hFsizexD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeXCPU, sizeXGPU);
0167         hFsizeyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeYCPU, sizeYGPU);
0168         hFposxD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(xLocalCPU, xLocalGPU);
0169         hFposyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(yLocalCPU, yLocalGPU);
0170         hFchargeDiff_->Fill(chargeCPU - chargeGPU);
0171         hFsizeXDiff_->Fill(sizeXCPU - sizeXGPU);
0172         hFsizeYDiff_->Fill(sizeYCPU - sizeYGPU);
0173         hFposXDiff_->Fill(micron_ * (xLocalCPU - xLocalGPU));
0174         hFposYDiff_->Fill(micron_ * (yLocalCPU - yLocalGPU));
0175         break;
0176     }
0177   }
0178 }
0179 
0180 //
0181 // -- Book Histograms
0182 //
0183 void SiPixelPhase1CompareRecHitsSoA::bookHistograms(DQMStore::IBooker& iBook,
0184                                                     edm::Run const& iRun,
0185                                                     edm::EventSetup const& iSetup) {
0186   iBook.cd();
0187   iBook.setCurrentFolder(topFolderName_);
0188 
0189   // clang-format off
0190   //Global
0191   hnHits_ = iBook.book2I("nHits", "CPUvsGPU RecHits per event;#CPU RecHits;#GPU RecHits", 200, 0, 5000,200, 0, 5000);
0192   //Barrel Layer
0193   for(unsigned int il=0;il<tkGeom_->numberOfLayers(PixelSubdetector::PixelBarrel);il++){
0194     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);
0195     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);
0196     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);
0197     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);
0198     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);
0199   }
0200   //Endcaps
0201   //Endcaps Disk
0202   for(int is=0;is<2;is++){
0203     int sign=is==0? -1:1;
0204     for(unsigned int id=0;id<tkGeom_->numberOfLayers(PixelSubdetector::PixelEndcap);id++){
0205       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);
0206       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);
0207       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);
0208       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);
0209       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);
0210     }
0211   }
0212   //1D differences
0213   hBchargeDiff_ = iBook.book1D("rechitChargeDiffBpix","Charge differnce of rechits in BPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
0214   hFchargeDiff_ = iBook.book1D("rechitChargeDiffFpix","Charge differnce of rechits in FPix; rechit charge difference (CPU - GPU)", 101, -50.5, 50.5);
0215   hBsizeXDiff_ = iBook.book1D("rechitsizeXDiffBpix","SizeX difference of rechits in BPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
0216   hFsizeXDiff_ = iBook.book1D("rechitsizeXDiffFpix","SizeX difference of rechits in FPix; rechit sizex difference (CPU - GPU)", 21, -10.5, 10.5);
0217   hBsizeYDiff_ = iBook.book1D("rechitsizeYDiffBpix","SizeY difference of rechits in BPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
0218   hFsizeYDiff_ = iBook.book1D("rechitsizeYDiffFpix","SizeY difference of rechits in FPix; rechit sizey difference (CPU - GPU)", 21, -10.5, 10.5);
0219   hBposXDiff_ = iBook.book1D("rechitsposXDiffBpix","x-position difference of rechits in BPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
0220   hFposXDiff_ = iBook.book1D("rechitsposXDiffFpix","x-position difference of rechits in FPix; rechit x-pos difference (CPU - GPU)", 1000, -10, 10);
0221   hBposYDiff_ = iBook.book1D("rechitsposYDiffBpix","y-position difference of rechits in BPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
0222   hFposYDiff_ = iBook.book1D("rechitsposYDiffFpix","y-position difference of rechits in FPix; rechit y-pos difference (CPU - GPU)", 1000, -10, 10);
0223 }
0224 
0225 void SiPixelPhase1CompareRecHitsSoA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0226   // monitorpixelRecHitsSoA
0227   edm::ParameterSetDescription desc;
0228   desc.add<edm::InputTag>("pixelHitsSrcCPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cpu"));
0229   desc.add<edm::InputTag>("pixelHitsSrcGPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cuda"));
0230   desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelRecHitsCompareGPUvsCPU");
0231   desc.add<double>("minD2cut", 0.0001);
0232   descriptions.addWithDefaultLabel(desc);
0233 }
0234 DEFINE_FWK_MODULE(SiPixelPhase1CompareRecHitsSoA);