Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:30:35

0001 #include <iomanip>
0002 #include <iostream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include <TCanvas.h>
0007 #include <TFile.h>
0008 #include <TH1D.h>
0009 #include <TH2D.h>
0010 #include <TTree.h>
0011 #include <TPaveStats.h>
0012 
0013 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0014 //#include "CUDADataFormats/HcalRecHitSoA/interface/RecHitCollection.h"
0015 
0016 #define CREATE_HIST_1D(varname, nbins, first, last) auto varname = new TH1D(#varname, #varname, nbins, first, last)
0017 
0018 #define CREATE_HIST_2D(varname, nbins, first, last) \
0019   auto varname = new TH2D(#varname, #varname, nbins, first, last, nbins, first, last)
0020 
0021 int main(int argc, char* argv[]) {
0022   if (argc < 3) {
0023     std::cout << "run with: ./<exe> <path to input file> <path to output file>\n";
0024     exit(0);
0025   }
0026 
0027   std::string inFileName{argv[1]};
0028   std::string outFileName{argv[2]};
0029 
0030   // branches to use
0031   edm::Wrapper<HBHERecHitCollection>* wcpu = nullptr;
0032   edm::Wrapper<HBHERecHitCollection>* wgpu = nullptr;
0033   //    edm::Wrapper<hcal::RecHitCollection<calo::common::VecStoragePolicy<calo::common::CUDAHostAllocatorAlias>>> *wgpu=nullptr;
0034 
0035   // prep output
0036   TFile rfout{outFileName.c_str(), "recreate"};
0037 
0038   CREATE_HIST_1D(hEnergyM0HBGPU, 1000, 0, 100);
0039   CREATE_HIST_1D(hEnergyM0HEGPU, 1000, 0, 100);
0040   CREATE_HIST_1D(hEnergyM0HBCPU, 1000, 0, 100);
0041   CREATE_HIST_1D(hEnergyM0HECPU, 1000, 0, 100);
0042 
0043   CREATE_HIST_1D(hEnergyHBGPU, 1000, 0, 100);
0044   CREATE_HIST_1D(hEnergyHBCPU, 1000, 0, 100);
0045   CREATE_HIST_1D(hEnergyHEGPU, 1000, 0, 100);
0046   CREATE_HIST_1D(hEnergyHECPU, 1000, 0, 100);
0047 
0048   CREATE_HIST_1D(hChi2HBGPU, 1000, 0, 100);
0049   CREATE_HIST_1D(hChi2HBCPU, 1000, 0, 100);
0050   CREATE_HIST_1D(hChi2HEGPU, 1000, 0, 100);
0051   CREATE_HIST_1D(hChi2HECPU, 1000, 0, 100);
0052 
0053   CREATE_HIST_2D(hEnergyHBGPUvsCPU, 1000, 0, 100);
0054   CREATE_HIST_2D(hEnergyHEGPUvsCPU, 1000, 0, 100);
0055   CREATE_HIST_2D(hChi2HBGPUvsCPU, 1000, 0, 100);
0056   CREATE_HIST_2D(hChi2HEGPUvsCPU, 1000, 0, 100);
0057 
0058   CREATE_HIST_2D(hEnergyM0HBGPUvsCPU, 1000, 0, 100);
0059   CREATE_HIST_2D(hEnergyM0HEGPUvsCPU, 1000, 0, 100);
0060 
0061   // prep input
0062   TFile rfin{inFileName.c_str()};
0063   TTree* rt = (TTree*)rfin.Get("Events");
0064   rt->SetBranchAddress("HBHERecHitsSorted_hcalCPURecHitsProducer_recHitsLegacyHBHE_RECO.", &wgpu);
0065   //    rt->SetBranchAddress("hcalCUDAHostAllocatorAliashcalcommonVecStoragePolicyhcalRecHitCollection_hcalCPURecHitsProducer_recHitsM0LabelOut_RECO.", &wgpu);
0066   rt->SetBranchAddress("HBHERecHitsSorted_hbheprereco__RECO.", &wcpu);
0067 
0068   // accumulate
0069   auto const nentries = rt->GetEntries();
0070   std::cout << ">>> nentries = " << nentries << std::endl;
0071   for (int ie = 0; ie < nentries; ++ie) {
0072     rt->GetEntry(ie);
0073 
0074     auto const& gpuProduct = wgpu->bareProduct();
0075     auto const& cpuProduct = wcpu->bareProduct();
0076 
0077     auto const ncpu = cpuProduct.size();
0078     auto const ngpu = gpuProduct.size();
0079     //        auto const ngpu = gpuProduct.energy.size();
0080 
0081     if (ngpu != ncpu) {
0082       std::cerr << "*** mismatch in number of rec hits for event " << ie << std::endl
0083                 << ">>> ngpu = " << ngpu << std::endl
0084                 << ">>> ncpu = " << ncpu << std::endl;
0085     }
0086 
0087     for (uint32_t ich = 0; ich < ncpu; ich++) {
0088       auto const& cpurh = cpuProduct[ich];
0089       auto const& did = cpurh.id();
0090       auto iter2gpu = gpuProduct.find(did);
0091       //            auto iter2idgpu = std::find(
0092       //                gpuProduct.did.begin(), gpuProduct.did.end(), did.rawId());
0093 
0094       if (iter2gpu == gpuProduct.end()) {
0095         std::cerr << "missing " << did << std::endl;
0096         continue;
0097       }
0098 
0099       assert(iter2gpu->id().rawId() == did.rawId());
0100 
0101       auto const gpu_energy_m0 = iter2gpu->eraw();
0102       auto const cpu_energy_m0 = cpurh.eraw();
0103       auto const gpu_energy = iter2gpu->energy();
0104       auto const cpu_energy = cpurh.energy();
0105       auto const gpu_chi2 = iter2gpu->chi2();
0106       auto const cpu_chi2 = cpurh.chi2();
0107 
0108       if (did.subdetId() == HcalBarrel) {
0109         hEnergyM0HBGPU->Fill(gpu_energy_m0);
0110         hEnergyM0HBCPU->Fill(cpu_energy_m0);
0111         hEnergyM0HBGPUvsCPU->Fill(cpu_energy_m0, gpu_energy_m0);
0112 
0113         hEnergyHBGPU->Fill(gpu_energy);
0114         hEnergyHBCPU->Fill(cpu_energy);
0115         hEnergyHBGPUvsCPU->Fill(cpu_energy, gpu_energy);
0116         hChi2HBGPU->Fill(gpu_chi2);
0117         hChi2HBCPU->Fill(cpu_chi2);
0118         hChi2HBGPUvsCPU->Fill(cpu_chi2, gpu_chi2);
0119       } else if (did.subdetId() == HcalEndcap) {
0120         hEnergyM0HEGPU->Fill(gpu_energy_m0);
0121         hEnergyM0HECPU->Fill(cpu_energy_m0);
0122         hEnergyM0HEGPUvsCPU->Fill(cpu_energy_m0, gpu_energy_m0);
0123 
0124         hEnergyHEGPU->Fill(gpu_energy);
0125         hEnergyHECPU->Fill(cpu_energy);
0126         hEnergyHEGPUvsCPU->Fill(cpu_energy, gpu_energy);
0127 
0128         hChi2HEGPU->Fill(gpu_chi2);
0129         hChi2HECPU->Fill(cpu_chi2);
0130         hChi2HEGPUvsCPU->Fill(cpu_chi2, gpu_chi2);
0131       }
0132     }
0133   }
0134 
0135   {
0136     TCanvas c{"plots", "plots", 4200, 6200};
0137     c.Divide(4, 3);
0138     c.cd(1);
0139     {
0140       gPad->SetLogy();
0141       hEnergyM0HBCPU->SetLineColor(kBlack);
0142       hEnergyM0HBCPU->SetLineWidth(1.);
0143       hEnergyM0HBCPU->Draw("");
0144       hEnergyM0HBGPU->SetLineColor(kBlue);
0145       hEnergyM0HBGPU->SetLineWidth(1.);
0146       hEnergyM0HBGPU->Draw("sames");
0147       gPad->Update();
0148       auto stats = (TPaveStats*)hEnergyM0HBGPU->FindObject("stats");
0149       auto y2 = stats->GetY2NDC();
0150       auto y1 = stats->GetY1NDC();
0151       stats->SetY2NDC(y1);
0152       stats->SetY1NDC(y1 - (y2 - y1));
0153     }
0154     c.cd(2);
0155     {
0156       gPad->SetLogz();
0157       hEnergyM0HBGPUvsCPU->GetXaxis()->SetTitle("cpu");
0158       hEnergyM0HBGPUvsCPU->GetYaxis()->SetTitle("gpu");
0159       hEnergyM0HBGPUvsCPU->Draw("colz");
0160     }
0161     c.cd(3);
0162     {
0163       gPad->SetLogy();
0164       hEnergyM0HECPU->SetLineColor(kBlack);
0165       hEnergyM0HECPU->SetLineWidth(1.);
0166       hEnergyM0HECPU->Draw("");
0167       hEnergyM0HEGPU->SetLineColor(kBlue);
0168       hEnergyM0HEGPU->SetLineWidth(1.);
0169       hEnergyM0HEGPU->Draw("sames");
0170       gPad->Update();
0171       auto stats = (TPaveStats*)hEnergyM0HEGPU->FindObject("stats");
0172       auto y2 = stats->GetY2NDC();
0173       auto y1 = stats->GetY1NDC();
0174       stats->SetY2NDC(y1);
0175       stats->SetY1NDC(y1 - (y2 - y1));
0176     }
0177     c.cd(4);
0178     {
0179       gPad->SetLogz();
0180       hEnergyM0HEGPUvsCPU->GetXaxis()->SetTitle("cpu");
0181       hEnergyM0HEGPUvsCPU->GetYaxis()->SetTitle("gpu");
0182       hEnergyM0HEGPUvsCPU->Draw("colz");
0183     }
0184     c.cd(5);
0185     {
0186       gPad->SetLogy();
0187       hEnergyHBCPU->SetLineColor(kBlack);
0188       hEnergyHBCPU->SetLineWidth(1.);
0189       hEnergyHBCPU->Draw("");
0190       hEnergyHBGPU->SetLineColor(kBlue);
0191       hEnergyHBGPU->SetLineWidth(1.);
0192       hEnergyHBGPU->Draw("sames");
0193       gPad->Update();
0194       auto stats = (TPaveStats*)hEnergyHBGPU->FindObject("stats");
0195       auto y2 = stats->GetY2NDC();
0196       auto y1 = stats->GetY1NDC();
0197       stats->SetY2NDC(y1);
0198       stats->SetY1NDC(y1 - (y2 - y1));
0199     }
0200     c.cd(6);
0201     {
0202       gPad->SetLogz();
0203       hEnergyHBGPUvsCPU->GetXaxis()->SetTitle("cpu");
0204       hEnergyHBGPUvsCPU->GetYaxis()->SetTitle("gpu");
0205       hEnergyHBGPUvsCPU->Draw("colz");
0206     }
0207     c.cd(7);
0208     {
0209       gPad->SetLogy();
0210       hEnergyHECPU->SetLineColor(kBlack);
0211       hEnergyHECPU->SetLineWidth(1.);
0212       hEnergyHECPU->Draw("");
0213       hEnergyHEGPU->SetLineColor(kBlue);
0214       hEnergyHEGPU->SetLineWidth(1.);
0215       hEnergyHEGPU->Draw("sames");
0216       gPad->Update();
0217       auto stats = (TPaveStats*)hEnergyHEGPU->FindObject("stats");
0218       auto y2 = stats->GetY2NDC();
0219       auto y1 = stats->GetY1NDC();
0220       stats->SetY2NDC(y1);
0221       stats->SetY1NDC(y1 - (y2 - y1));
0222     }
0223     c.cd(8);
0224     {
0225       gPad->SetLogz();
0226       hEnergyHEGPUvsCPU->GetXaxis()->SetTitle("cpu");
0227       hEnergyHEGPUvsCPU->GetYaxis()->SetTitle("gpu");
0228       hEnergyHEGPUvsCPU->Draw("colz");
0229     }
0230     c.cd(9);
0231     {
0232       gPad->SetLogy();
0233       hChi2HBCPU->SetLineColor(kBlack);
0234       hChi2HBCPU->SetLineWidth(1.);
0235       hChi2HBCPU->Draw("");
0236       hChi2HBGPU->SetLineColor(kBlue);
0237       hChi2HBGPU->SetLineWidth(1.);
0238       hChi2HBGPU->Draw("sames");
0239       gPad->Update();
0240       auto stats = (TPaveStats*)hChi2HBGPU->FindObject("stats");
0241       auto y2 = stats->GetY2NDC();
0242       auto y1 = stats->GetY1NDC();
0243       stats->SetY2NDC(y1);
0244       stats->SetY1NDC(y1 - (y2 - y1));
0245     }
0246     c.cd(10);
0247     {
0248       gPad->SetLogz();
0249       hChi2HBGPUvsCPU->GetXaxis()->SetTitle("cpu");
0250       hChi2HBGPUvsCPU->GetYaxis()->SetTitle("gpu");
0251       hChi2HBGPUvsCPU->Draw("colz");
0252     }
0253     c.cd(11);
0254     {
0255       gPad->SetLogy();
0256       hChi2HECPU->SetLineColor(kBlack);
0257       hChi2HECPU->SetLineWidth(1.);
0258       hChi2HECPU->Draw("");
0259       hChi2HEGPU->SetLineColor(kBlue);
0260       hChi2HEGPU->SetLineWidth(1.);
0261       hChi2HEGPU->Draw("sames");
0262       gPad->Update();
0263       auto stats = (TPaveStats*)hChi2HEGPU->FindObject("stats");
0264       auto y2 = stats->GetY2NDC();
0265       auto y1 = stats->GetY1NDC();
0266       stats->SetY2NDC(y1);
0267       stats->SetY1NDC(y1 - (y2 - y1));
0268     }
0269     c.cd(12);
0270     {
0271       gPad->SetLogz();
0272       hChi2HEGPUvsCPU->GetXaxis()->SetTitle("cpu");
0273       hChi2HEGPUvsCPU->GetYaxis()->SetTitle("gpu");
0274       hChi2HEGPUvsCPU->Draw("colz");
0275     }
0276     c.SaveAs("plots.pdf");
0277   }
0278 
0279   rfin.Close();
0280   rfout.Write();
0281   rfout.Close();
0282 }