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