Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:50

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/Common/interface/Wrapper.h"
0014 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0015 
0016 int main(int argc, char* argv[]) {
0017   if (argc < 3) {
0018     std::cout << "run with: ./<exe> <path to input file> <path to output file>\n";
0019     exit(0);
0020   }
0021 
0022   // branches to use
0023   edm::Wrapper<EBDigiCollection>*wgpuEB = nullptr, *wcpuEB = nullptr;
0024   edm::Wrapper<EEDigiCollection>*wgpuEE = nullptr, *wcpuEE = nullptr;
0025 
0026   std::string inFileName{argv[1]};
0027   std::string outFileName{argv[2]};
0028 
0029   // prep output
0030   TFile rfout{outFileName.c_str(), "recreate"};
0031 
0032   int const nbins = 400;
0033   float const last = 4096.;
0034   auto hADCEBGPU = new TH1D("hADCEBGPU", "hADCEBGPU", nbins, 0, last);
0035   auto hADCEBCPU = new TH1D("hADCEBCPU", "hADCEBCPU", nbins, 0, last);
0036   auto hADCEEGPU = new TH1D("hADCEEGPU", "hADCEEGPU", nbins, 0, last);
0037   auto hADCEECPU = new TH1D("hADCEECPU", "hADCEECPU", nbins, 0, last);
0038 
0039   auto hGainEBGPU = new TH1D("hGainEBGPU", "hGainEBGPU", 4, 0, 4);
0040   auto hGainEBCPU = new TH1D("hGainEBCPU", "hGainEBCPU", 4, 0, 4);
0041   auto hGainEEGPU = new TH1D("hGainEEGPU", "hGainEEGPU", 4, 0, 4);
0042   auto hGainEECPU = new TH1D("hGainEECPU", "hGainEECPU", 4, 0, 4);
0043 
0044   auto hADCEBGPUvsCPU = new TH2D("hADCEBGPUvsCPU", "hADCEBGPUvsCPU", nbins, 0, last, nbins, 0, last);
0045   auto hADCEEGPUvsCPU = new TH2D("hADCEEGPUvsCPU", "hADCEEGPUvsCPU", nbins, 0, last, nbins, 0, last);
0046   auto hGainEBGPUvsCPU = new TH2D("hGainEBGPUvsCPU", "hGainEBGPUvsCPU", 4, 0, 4, 4, 0, 4);
0047   auto hGainEEGPUvsCPU = new TH2D("hGainEEGPUvsCPU", "hGainEEGPUvsCPU", 4, 0, 4, 4, 0, 4);
0048 
0049   // prep input
0050   TFile rfin{inFileName.c_str()};
0051   TTree* rt = (TTree*)rfin.Get("Events");
0052   rt->SetBranchAddress("EBDigiCollection_ecalCPUDigisProducer_ebDigis_RECO.", &wgpuEB);
0053   rt->SetBranchAddress("EEDigiCollection_ecalCPUDigisProducer_eeDigis_RECO.", &wgpuEE);
0054   rt->SetBranchAddress("EBDigiCollection_ecalDigis_ebDigis_RECO.", &wcpuEB);
0055   rt->SetBranchAddress("EEDigiCollection_ecalDigis_eeDigis_RECO.", &wcpuEE);
0056 
0057   // accumulate
0058   auto const nentries = rt->GetEntries();
0059   std::cout << ">>> nentries = " << nentries << std::endl;
0060   for (int ie = 0; ie < nentries; ++ie) {
0061     rt->GetEntry(ie);
0062 
0063     auto const ngpuebs = wgpuEB->bareProduct().size();
0064     auto const ncpuebs = wcpuEB->bareProduct().size();
0065     auto const ngpuees = wgpuEE->bareProduct().size();
0066     auto const ncpuees = wcpuEE->bareProduct().size();
0067 
0068     if (ngpuebs != ncpuebs or ngpuees != ncpuees) {
0069       std::cerr << "*** mismatch in ndigis: "
0070                 << "ie = " << ie << "  ngpuebs = " << ngpuebs << "  ncpuebs = " << ncpuebs << "  ngpuees = " << ngpuees
0071                 << "  ncpuees = " << ncpuees << std::endl;
0072 
0073       // this is a must for now
0074       //assert(ngpuebs==ncpuebs);
0075       //assert(ngpuees==ncpuees);
0076     }
0077 
0078     // assume identical sizes
0079     auto const& idsgpuEB = wgpuEB->bareProduct().ids();
0080     auto const& datagpuEB = wgpuEB->bareProduct().data();
0081     auto const& idscpuEB = wcpuEB->bareProduct().ids();
0082     auto const& datacpuEB = wcpuEB->bareProduct().data();
0083     for (uint32_t ieb = 0; ieb < ngpuebs; ++ieb) {
0084       auto const& idgpu = idsgpuEB[ieb];
0085       auto iter2idcpu = std::find(idscpuEB.begin(), idscpuEB.end(), idgpu);
0086       // FIXME
0087       assert(idgpu == *iter2idcpu);
0088 
0089       auto const ptrdiff = iter2idcpu - idscpuEB.begin();
0090       for (uint32_t s = 0u; s < 10u; s++) {
0091         EcalMGPASample sampleGPU{datagpuEB[ieb * 10 + s]};
0092         EcalMGPASample sampleCPU{datacpuEB[ptrdiff * 10 + s]};
0093 
0094         hADCEBGPU->Fill(sampleGPU.adc());
0095         hGainEBGPU->Fill(sampleGPU.gainId());
0096         hADCEBCPU->Fill(sampleCPU.adc());
0097         hGainEBCPU->Fill(sampleCPU.gainId());
0098         hADCEBGPUvsCPU->Fill(sampleCPU.adc(), sampleGPU.adc());
0099         hGainEBGPUvsCPU->Fill(sampleCPU.gainId(), sampleGPU.gainId());
0100       }
0101     }
0102 
0103     auto const& idsgpuEE = wgpuEE->bareProduct().ids();
0104     auto const& datagpuEE = wgpuEE->bareProduct().data();
0105     auto const& idscpuEE = wcpuEE->bareProduct().ids();
0106     auto const& datacpuEE = wcpuEE->bareProduct().data();
0107     for (uint32_t iee = 0; iee < ngpuees; ++iee) {
0108       auto const& idgpu = idsgpuEE[iee];
0109       auto iter2idcpu = std::find(idscpuEE.begin(), idscpuEE.end(), idgpu);
0110       // FIXME
0111       assert(idgpu == *iter2idcpu);
0112 
0113       // get the digis
0114       auto const ptrdiff = iter2idcpu - idscpuEE.begin();
0115       for (uint32_t s = 0u; s < 10u; s++) {
0116         EcalMGPASample sampleGPU{datagpuEE[iee * 10 + s]};
0117         EcalMGPASample sampleCPU{datacpuEE[ptrdiff * 10 + s]};
0118 
0119         hADCEEGPU->Fill(sampleGPU.adc());
0120         hGainEEGPU->Fill(sampleGPU.gainId());
0121         hADCEECPU->Fill(sampleCPU.adc());
0122         hGainEECPU->Fill(sampleCPU.gainId());
0123         hADCEEGPUvsCPU->Fill(sampleCPU.adc(), sampleGPU.adc());
0124         hGainEEGPUvsCPU->Fill(sampleCPU.gainId(), sampleGPU.gainId());
0125       }
0126     }
0127   }
0128 
0129   {
0130     TCanvas c{"plots", "plots", 4200, 6200};
0131     c.Divide(2, 4);
0132     c.cd(1);
0133     {
0134       gPad->SetLogy();
0135       hADCEBCPU->SetLineColor(kBlack);
0136       hADCEBCPU->SetLineWidth(1.);
0137       hADCEBCPU->Draw("");
0138       hADCEBGPU->SetLineColor(kBlue);
0139       hADCEBGPU->SetLineWidth(1.);
0140       hADCEBGPU->Draw("sames");
0141       gPad->Update();
0142       auto stats = (TPaveStats*)hADCEBGPU->FindObject("stats");
0143       auto y2 = stats->GetY2NDC();
0144       auto y1 = stats->GetY1NDC();
0145       stats->SetY2NDC(y1);
0146       stats->SetY1NDC(y1 - (y2 - y1));
0147     }
0148     c.cd(2);
0149     {
0150       gPad->SetLogy();
0151       hADCEECPU->SetLineColor(kBlack);
0152       hADCEECPU->SetLineWidth(1.);
0153       hADCEECPU->Draw("");
0154       hADCEEGPU->SetLineColor(kBlue);
0155       hADCEEGPU->SetLineWidth(1.);
0156       hADCEEGPU->Draw("sames");
0157       gPad->Update();
0158       auto stats = (TPaveStats*)hADCEEGPU->FindObject("stats");
0159       auto y2 = stats->GetY2NDC();
0160       auto y1 = stats->GetY1NDC();
0161       stats->SetY2NDC(y1);
0162       stats->SetY1NDC(y1 - (y2 - y1));
0163     }
0164     c.cd(3);
0165     {
0166       gPad->SetLogy();
0167       hGainEBCPU->SetLineColor(kBlack);
0168       hGainEBCPU->SetLineWidth(1.);
0169       hGainEBCPU->Draw("");
0170       hGainEBGPU->SetLineColor(kBlue);
0171       hGainEBGPU->SetLineWidth(1.);
0172       hGainEBGPU->Draw("sames");
0173       gPad->Update();
0174       auto stats = (TPaveStats*)hGainEBGPU->FindObject("stats");
0175       auto y2 = stats->GetY2NDC();
0176       auto y1 = stats->GetY1NDC();
0177       stats->SetY2NDC(y1);
0178       stats->SetY1NDC(y1 - (y2 - y1));
0179     }
0180     c.cd(4);
0181     {
0182       gPad->SetLogy();
0183       hGainEECPU->SetLineColor(kBlack);
0184       hGainEECPU->SetLineWidth(1.);
0185       hGainEECPU->Draw("");
0186       hGainEEGPU->SetLineColor(kBlue);
0187       hGainEEGPU->SetLineWidth(1.);
0188       hGainEEGPU->Draw("sames");
0189       gPad->Update();
0190       auto stats = (TPaveStats*)hGainEEGPU->FindObject("stats");
0191       auto y2 = stats->GetY2NDC();
0192       auto y1 = stats->GetY1NDC();
0193       stats->SetY2NDC(y1);
0194       stats->SetY1NDC(y1 - (y2 - y1));
0195     }
0196     c.cd(5);
0197     hADCEBGPUvsCPU->Draw("colz");
0198     c.cd(6);
0199     hADCEEGPUvsCPU->Draw("colz");
0200     c.cd(7);
0201     hGainEBGPUvsCPU->Draw("colz");
0202     c.cd(8);
0203     hGainEEGPUvsCPU->Draw("colz");
0204     c.SaveAs("plots.pdf");
0205   }
0206 
0207   rfin.Close();
0208   rfout.Write();
0209   rfout.Close();
0210 }