Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:56:00

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> tokenSoAHitsHost_;    //these two are both on Host but originally they have been
0048   const edm::EDGetTokenT<HitsOnHost> tokenSoAHitsDevice_;  //produced on Host or on Device
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       tokenSoAHitsHost_(consumes(iConfig.getParameter<edm::InputTag>("pixelHitsSrcCPU"))),
0087       tokenSoAHitsDevice_(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& rhsoaHandleHost = iEvent.getHandle(tokenSoAHitsHost_);
0105   const auto& rhsoaHandleDevice = iEvent.getHandle(tokenSoAHitsDevice_);
0106   if (not rhsoaHandleHost or not rhsoaHandleDevice) {
0107     edm::LogWarning out("SiPixelCompareRecHitSoA");
0108     if (not rhsoaHandleHost) {
0109       out << "reference (Host) rechits not found; ";
0110     }
0111     if (not rhsoaHandleDevice) {
0112       out << "target (Device) rechits not found; ";
0113     }
0114     out << "the comparison will not run.";
0115     return;
0116   }
0117 
0118   auto const& rhsoaHost = *rhsoaHandleHost;
0119   auto const& rhsoaDevice = *rhsoaHandleDevice;
0120 
0121   auto const& soa2dHost = rhsoaHost.const_view();
0122   auto const& soa2dDevice = rhsoaDevice.const_view();
0123 
0124   uint32_t nHitsHost = soa2dHost.nHits();
0125   uint32_t nHitsDevice = soa2dDevice.nHits();
0126 
0127   hnHits_->Fill(nHitsHost, nHitsDevice);
0128   auto detIds = tkGeom_->detUnitIds();
0129   for (uint32_t i = 0; i < nHitsHost; i++) {
0130     float minD = mind2cut_;
0131     uint32_t matchedHit = invalidHit_;
0132     uint16_t indHost = soa2dHost[i].detectorIndex();
0133     float xLocalHost = soa2dHost[i].xLocal();
0134     float yLocalHost = soa2dHost[i].yLocal();
0135     for (uint32_t j = 0; j < nHitsDevice; j++) {
0136       if (soa2dDevice.detectorIndex(j) == indHost) {
0137         float dx = xLocalHost - soa2dDevice[j].xLocal();
0138         float dy = yLocalHost - soa2dDevice[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[indHost];
0147     uint32_t chargeHost = soa2dHost[i].chargeAndStatus().charge;
0148     int16_t sizeXHost = std::ceil(float(std::abs(soa2dHost[i].clusterSizeX()) / 8.));
0149     int16_t sizeYHost = std::ceil(float(std::abs(soa2dHost[i].clusterSizeY()) / 8.));
0150     uint32_t chargeDevice = 0;
0151     int16_t sizeXDevice = -99;
0152     int16_t sizeYDevice = -99;
0153     float xLocalDevice = -999.;
0154     float yLocalDevice = -999.;
0155     if (matchedHit != invalidHit_) {
0156       chargeDevice = soa2dDevice[matchedHit].chargeAndStatus().charge;
0157       sizeXDevice = std::ceil(float(std::abs(soa2dDevice[matchedHit].clusterSizeX()) / 8.));
0158       sizeYDevice = std::ceil(float(std::abs(soa2dDevice[matchedHit].clusterSizeY()) / 8.));
0159       xLocalDevice = soa2dDevice[matchedHit].xLocal();
0160       yLocalDevice = soa2dDevice[matchedHit].yLocal();
0161     }
0162     switch (id.subdetId()) {
0163       case PixelSubdetector::PixelBarrel:
0164         hBchargeL_[tTopo_->pxbLayer(id) - 1]->Fill(chargeHost, chargeDevice);
0165         hBsizexL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeXHost, sizeXDevice);
0166         hBsizeyL_[tTopo_->pxbLayer(id) - 1]->Fill(sizeYHost, sizeYDevice);
0167         hBposxL_[tTopo_->pxbLayer(id) - 1]->Fill(xLocalHost, xLocalDevice);
0168         hBposyL_[tTopo_->pxbLayer(id) - 1]->Fill(yLocalHost, yLocalDevice);
0169         hBchargeDiff_->Fill(chargeHost - chargeDevice);
0170         hBsizeXDiff_->Fill(sizeXHost - sizeXDevice);
0171         hBsizeYDiff_->Fill(sizeYHost - sizeYDevice);
0172         hBposXDiff_->Fill(micron_ * (xLocalHost - xLocalDevice));
0173         hBposYDiff_->Fill(micron_ * (yLocalHost - yLocalDevice));
0174         break;
0175       case PixelSubdetector::PixelEndcap:
0176         hFchargeD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(chargeHost, chargeDevice);
0177         hFsizexD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeXHost, sizeXDevice);
0178         hFsizeyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(sizeYHost, sizeYDevice);
0179         hFposxD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(xLocalHost, xLocalDevice);
0180         hFposyD_[tTopo_->pxfSide(id) - 1][tTopo_->pxfDisk(id) - 1]->Fill(yLocalHost, yLocalDevice);
0181         hFchargeDiff_->Fill(chargeHost - chargeDevice);
0182         hFsizeXDiff_->Fill(sizeXHost - sizeXDevice);
0183         hFsizeYDiff_->Fill(sizeYHost - sizeYDevice);
0184         hFposXDiff_->Fill(micron_ * (xLocalHost - xLocalDevice));
0185         hFposYDiff_->Fill(micron_ * (yLocalHost - yLocalDevice));
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", "HostvsDevice RecHits per event;#Host RecHits;#Device 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("HostvsDevice RecHits Charge Barrel Layer%d;Host Charge;Device Charge",il+1), 250, 0, 100000, 250, 0, 100000);
0207     hBsizexL_[il] = iBook.book2I(Form("recHitsBLay%dSizex",il+1), Form("HostvsDevice RecHits SizeX Barrel Layer%d;Host SizeX;Device SizeX",il+1), 30, 0, 30, 30, 0, 30);
0208     hBsizeyL_[il] = iBook.book2I(Form("recHitsBLay%dSizey",il+1), Form("HostvsDevice RecHits SizeY Barrel Layer%d;Host SizeY;Device SizeY",il+1), 30, 0, 30, 30, 0, 30);
0209     hBposxL_[il] = iBook.book2D(Form("recHitsBLay%dPosx",il+1), Form("HostvsDevice RecHits x-pos in Barrel Layer%d;Host pos x;Device pos x",il+1), 200, -5, 5, 200,-5,5);
0210     hBposyL_[il] = iBook.book2D(Form("recHitsBLay%dPosy",il+1), Form("HostvsDevice RecHits y-pos in Barrel Layer%d;Host pos y;Device 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("HostvsDevice RecHits Charge Endcaps Disk%+d;Host Charge;Device Charge",id*sign+sign), 250, 0, 100000, 250, 0, 100000);
0218       hFsizexD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizex",id*sign+sign), Form("HostvsDevice RecHits SizeX Endcaps Disk%+d;Host SizeX;Device SizeX",id*sign+sign), 30, 0, 30, 30, 0, 30);
0219       hFsizeyD_[is][id] = iBook.book2I(Form("recHitsFDisk%+dSizey",id*sign+sign), Form("HostvsDevice RecHits SizeY Endcaps Disk%+d;Host SizeY;Device SizeY",id*sign+sign), 30, 0, 30, 30, 0, 30);
0220       hFposxD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosx",id*sign+sign), Form("HostvsDevice RecHits x-pos Endcaps Disk%+d;Host pos x;Device pos x",id*sign+sign), 200, -5, 5, 200, -5, 5);
0221       hFposyD_[is][id] = iBook.book2D(Form("recHitsFDisk%+dPosy",id*sign+sign), Form("HostvsDevice RecHits y-pos Endcaps Disk%+d;Host pos y;Device 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 (Host - Device)", 101, -50.5, 50.5);
0226   hFchargeDiff_ = iBook.book1D("rechitChargeDiffFpix","Charge differnce of rechits in FPix; rechit charge difference (Host - Device)", 101, -50.5, 50.5);
0227   hBsizeXDiff_ = iBook.book1D("rechitsizeXDiffBpix","SizeX difference of rechits in BPix; rechit sizex difference (Host - Device)", 21, -10.5, 10.5);
0228   hFsizeXDiff_ = iBook.book1D("rechitsizeXDiffFpix","SizeX difference of rechits in FPix; rechit sizex difference (Host - Device)", 21, -10.5, 10.5);
0229   hBsizeYDiff_ = iBook.book1D("rechitsizeYDiffBpix","SizeY difference of rechits in BPix; rechit sizey difference (Host - Device)", 21, -10.5, 10.5);
0230   hFsizeYDiff_ = iBook.book1D("rechitsizeYDiffFpix","SizeY difference of rechits in FPix; rechit sizey difference (Host - Device)", 21, -10.5, 10.5);
0231   hBposXDiff_ = iBook.book1D("rechitsposXDiffBpix","x-position difference of rechits in BPix; rechit x-pos difference (Host - Device)", 1000, -10, 10);
0232   hFposXDiff_ = iBook.book1D("rechitsposXDiffFpix","x-position difference of rechits in FPix; rechit x-pos difference (Host - Device)", 1000, -10, 10);
0233   hBposYDiff_ = iBook.book1D("rechitsposYDiffBpix","y-position difference of rechits in BPix; rechit y-pos difference (Host - Device)", 1000, -10, 10);
0234   hFposYDiff_ = iBook.book1D("rechitsposYDiffFpix","y-position difference of rechits in FPix; rechit y-pos difference (Host - Device)", 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@Host"));
0242   desc.add<edm::InputTag>("pixelHitsSrcGPU", edm::InputTag("siPixelRecHitsPreSplittingSoA@cuda"));
0243   desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelRecHitsCompareDevicevsHost");
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 
0251 DEFINE_FWK_MODULE(SiPixelPhase1CompareRecHitsSoA);
0252 DEFINE_FWK_MODULE(SiPixelPhase2CompareRecHitsSoA);