File indexing completed on 2025-12-16 09:18:02
0001 void comparePNcharge()
0002 {
0003
0004 TString file1P_name = "/mnt/e/sphenix/INTT-EMCAL/InttSeedingTrackDev/ParticleGen/output/calo_position_positron.root";
0005 TString file2N_name = "/mnt/e/sphenix/INTT-EMCAL/InttSeedingTrackDev/ParticleGen/output/calo_position_electron.root";
0006
0007
0008 TFile *file1_Pcharge = TFile::Open(file1P_name, "READ");
0009 TFile *file2_Ncharge = TFile::Open(file2N_name, "READ");
0010
0011 if (!file1_Pcharge || file1_Pcharge->IsZombie())
0012 {
0013 std::cerr << "无法打开 " << file1P_name << std::endl;
0014 return;
0015 }
0016 if (!file2_Ncharge || file2_Ncharge->IsZombie())
0017 {
0018 std::cerr << "无法打开 " << file2N_name << std::endl;
0019 return;
0020 }
0021
0022
0023 TH1F *h1_DR_pr1_clustinnr_P = nullptr;
0024 TH1F *h1_DR_pr1_clustinnr_N = nullptr;
0025 file1_Pcharge->GetObject("h1_DR_pr1_clustinnr",h1_DR_pr1_clustinnr_P);
0026 file2_Ncharge->GetObject("h1_DR_pr1_clustinnr",h1_DR_pr1_clustinnr_N);
0027
0028
0029
0030
0031
0032
0033 TProfile *TP_DR_pr1_clustinnr_pt_P = nullptr;
0034 TProfile *TP_DR_pr1_clustinnr_pt_N = nullptr;
0035 file1_Pcharge->GetObject("TP_DR_pr1_clustinnr_pt", TP_DR_pr1_clustinnr_pt_P);
0036 file2_Ncharge->GetObject("TP_DR_pr1_clustinnr_pt", TP_DR_pr1_clustinnr_pt_N);
0037
0038
0039 auto TP_DR_pr1_clustinnr_pt_PN = new TProfile("TP_DR_pr1_clustinnr_pt_PN", "TP_DR_pr1_clustinnr_pt_PN;charge(-e)*pt(GeV);R(cm)", 22, -11, 11, 0, 20);
0040
0041
0042 for (int i = 1; i <= TP_DR_pr1_clustinnr_pt_P->GetNbinsX(); ++i)
0043 {
0044 double x = TP_DR_pr1_clustinnr_pt_P->GetBinCenter(i);
0045 double y = TP_DR_pr1_clustinnr_pt_P->GetBinContent(i);
0046 double ey = TP_DR_pr1_clustinnr_pt_P->GetBinError(i);
0047 double n = TP_DR_pr1_clustinnr_pt_P->GetBinEntries(i);
0048
0049 if (n <= 0) continue;
0050
0051
0052 double rms2 = ey * ey * n;
0053 double rms = std::sqrt(rms2 / n);
0054
0055
0056 for (int j = 0; j < (int)n; ++j)
0057 {
0058 double y_j = gRandom->Gaus(y, rms);
0059 TP_DR_pr1_clustinnr_pt_PN->Fill(x, y);
0060 }
0061 }
0062
0063 TProfile *flipped = new TProfile("flipped_profile", "Flipped profile", 11, 0, 11, 0, 20);
0064
0065 for (int i = 1; i <= TP_DR_pr1_clustinnr_pt_N->GetNbinsX(); ++i)
0066 {
0067
0068 int flipped_bin = TP_DR_pr1_clustinnr_pt_N->GetNbinsX() - i + 1;
0069
0070 double x = TP_DR_pr1_clustinnr_pt_N->GetBinCenter(i);
0071 double flipped_x = -x;
0072 double y = TP_DR_pr1_clustinnr_pt_N->GetBinContent(i);
0073 double ey = TP_DR_pr1_clustinnr_pt_N->GetBinError(i);
0074 double n = TP_DR_pr1_clustinnr_pt_N->GetBinEntries(i);
0075
0076 if (n <= 0) continue;
0077
0078 double rms2 = ey * ey * n;
0079
0080 double rms = ey * ey * n;
0081
0082
0083 for (int j = 0; j < (int)n; ++j)
0084 {
0085 double y_j = gRandom->Gaus(y, rms);
0086 TP_DR_pr1_clustinnr_pt_PN->Fill(flipped_x, y);
0087 }
0088 }
0089 TP_DR_pr1_clustinnr_pt_PN->SetMarkerStyle(29);
0090
0091
0092
0093 TCanvas *c1 = new TCanvas("h1_DR_pr1_clustinnr_PN", "P vs N", 800, 600);
0094 c1->cd();
0095
0096
0097 h1_DR_pr1_clustinnr_P->SetLineColor(kRed);
0098 h1_DR_pr1_clustinnr_P->SetLineWidth(2);
0099 h1_DR_pr1_clustinnr_P->SetTitle("Comparison of e+ and e-");
0100 h1_DR_pr1_clustinnr_P->Draw("");
0101
0102 h1_DR_pr1_clustinnr_N->SetLineColor(kBlue);
0103 h1_DR_pr1_clustinnr_N->SetLineWidth(2);
0104 h1_DR_pr1_clustinnr_N->Draw("SAME");
0105
0106
0107 TLegend *leg1 = new TLegend(0.65, 0.75, 0.88, 0.88);
0108 leg1->AddEntry(h1_DR_pr1_clustinnr_P, "Positron", "l");
0109 leg1->AddEntry(h1_DR_pr1_clustinnr_N, "Electron", "l");
0110 leg1->Draw();
0111
0112
0113 c1->SaveAs("comparePNcharge_R.pdf");
0114
0115 TCanvas *c2 = new TCanvas("h1_dphi_distri_pr1_clustinnr_PN", "P vs N", 800, 600);
0116 c2->cd();
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134 c2->SaveAs("comparePNcharge_dphi.pdf");
0135
0136
0137 TFile *output = new TFile("PNchargeComp.root", "RECREATE");
0138 c1->Write();
0139 c2->Write();
0140 TP_DR_pr1_clustinnr_pt_PN->Write();
0141 output->Close();
0142
0143 std::cout << "完成!新直方图已保存到 output.root 中。" << std::endl;
0144
0145
0146 file1_Pcharge->Close();
0147 file2_Ncharge->Close();
0148 }
0149