Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:15

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