Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-09 08:12:13

0001 std::pair<int,int> get_DeltaPhi_SingleBin(TH1D * hist_in, std::pair<double, double> range_in)
0002 {
0003     int bin_min = hist_in -> FindBin(range_in.first);
0004     
0005     int bin_max = hist_in -> FindBin(range_in.second);
0006     bin_max = (fabs(hist_in -> GetXaxis() -> GetBinLowEdge(bin_max) - range_in.second) < 1e-9) ? bin_max - 1 : bin_max;
0007 
0008     std::cout<<std::endl;
0009     std::cout<<"Input range : "<<range_in.first<<", "<<range_in.second<<std::endl;
0010     std::cout<<"Final selected bins: "<<bin_min<<", "<<bin_max<<std::endl;
0011     std::cout<<"Output range : "<<hist_in -> GetXaxis() -> GetBinLowEdge(bin_min)<<", "<<hist_in -> GetXaxis() -> GetBinUpEdge(bin_max)<<std::endl;
0012 
0013     return std::make_pair(bin_min, bin_max);
0014 }
0015 
0016 double get_EvtCount(TH2D * hist_in, int centrality_bin_in)
0017 {
0018     double count = 0;
0019 
0020     // note : X : vtxZ
0021     // note : Y : centrality
0022 
0023     
0024     if (true) {
0025         for (int xi = 3; xi <= 6; xi++){ // note : vtxZ bin
0026 
0027             // if (vtxZ_index_map.find(xi - 1) == vtxZ_index_map.end()){
0028             //     continue;
0029             // }
0030 
0031             count += hist_in -> GetBinContent(xi, centrality_bin_in + 1);
0032         }
0033     }
0034 
0035     return count;
0036 
0037 }
0038 
0039 // int DeltaPhi()
0040 // {
0041 //     // int Mbin = 0;
0042 //     std::string mother_directory = "/sphenix/tg/tg01/commissioning/INTT/work/cwshih/seflgendata/run_54280_HR_Feb102025/Run6_EvtZFitWidthChange/EvtVtxZ/FinalResult_10cm_Pol2BkgFit/completed";
0043     
0044     
0045 //     TCanvas * c = new TCanvas("c", "c", 800, 600);
0046 //     c -> Print("DeltaPhi.pdf(");
0047 
0048 //     TF1 * line = new TF1("line", "pol1",-10,10);
0049 //     line -> SetParameters(0,1);
0050 //     line -> SetLineStyle(2);
0051 //     line -> SetLineWidth(1);
0052 //     line -> SetLineColor(kRed);
0053 
0054 //     vector<TGraph*> eta_correlation; eta_correlation.clear();
0055 
0056 //     for (int i = 0; i < 15; i++) // note : 0 to 14, the Mbin;
0057 //     {
0058 //         std::string Mbin_folder_name = Form("vtxZ_-10_10cm_MBin%d",i);
0059 //         std::string data_file = Form("Data_PreparedNdEtaEach_AlphaCorr_AllSensor_VtxZ10_Mbin%d_00054280_00000_DeltaPhi.root",i);
0060 //         std::string MC_file = Form("MC_PreparedNdEtaEach_AllSensor_VtxZ10_Mbin%d_00001_DeltaPhi.root",i);
0061 
0062 //         TFile * file_data = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), data_file.c_str()));
0063 //         TFile * file_MC = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), MC_file.c_str()));
0064 
0065 //         for (int eta_i = 7; eta_i <= 19; eta_i++)
0066 //         {
0067 //             std::string hist_name = Form("h1D_RotatedBkg_DeltaPhi_Signal_Eta%d", eta_i);
0068 //             TH1D * data = (TH1D*)file_data->Get(hist_name.c_str());
0069 //             TH1D * MC = (TH1D*)file_MC->Get(hist_name.c_str());
0070 
0071 //             data->Scale(1.0/data->Integral());
0072 //             MC->Scale(1.0/MC->Integral());
0073 
0074 //             eta_correlation.push_back(new TGraph());
0075 //             eta_correlation.back()->SetTitle(Form(";Data;MC"));
0076 //             eta_correlation.back()->SetMarkerStyle(20);
0077 //             eta_correlation.back()->SetMarkerSize(0.5);
0078 //             eta_correlation.back()->SetMarkerColor(eta_i-7 + 1);
0079 //             eta_correlation.back()->SetLineColor(eta_i-7 + 1);
0080 
0081 //             for (int delta_phi_i = 0; delta_phi_i < 27; delta_phi_i++){
0082 //                 std::pair<double,double> delta_phi_range = {
0083 //                     -0.018 - 0.002 * delta_phi_i,
0084 //                     0.018 + 0.002 * delta_phi_i
0085 //                 };
0086 //                 std::pair<int,int> delta_phi_bin = get_DeltaPhi_SingleBin(data, delta_phi_range);
0087 
0088 //                 eta_correlation.back()->SetPoint(
0089 //                     delta_phi_i, 
0090 //                     data->Integral(delta_phi_bin.first, delta_phi_bin.second),
0091 //                     MC->Integral(delta_phi_bin.first, delta_phi_bin.second)
0092 //                 );
0093 //             }
0094 
0095 //             eta_correlation.back()->GetYaxis()->SetRangeUser(0.7,1);
0096 //             eta_correlation.back()->GetXaxis()->SetLimits(0.7,1);
0097 
0098 //             c->cd();
0099 //             if (eta_i == 7) eta_correlation.back()->Draw("APL");
0100 //             else eta_correlation.back()->Draw("PL same");
0101 //         }
0102 
0103 //         line -> Draw("lsame");
0104 //         c -> Print("DeltaPhi.pdf");
0105 //         c -> Clear();
0106 //         eta_correlation.clear();
0107 //     }
0108 
0109 //     c -> Print("DeltaPhi.pdf)");
0110 
0111 //     return 0;
0112 // }
0113 
0114 int DeltaPhi()
0115 {
0116     std::string mother_directory = "/sphenix/tg/tg01/commissioning/INTT/work/cwshih/seflgendata/run_54280_HR_Feb102025/Run6_EvtZFitWidthChange/EvtVtxZ/FinalResult_10cm_Pol2BkgFit/completed";
0117     
0118     double nominal_deltaphi = 0.026;
0119     double vary_deltaphi = 0.04;
0120     
0121     TCanvas * c1 = new TCanvas("c1", "c1", 800, 1000);
0122     c1 -> Print("DeltaPhi_dNdEta.pdf(");
0123 
0124     TF1 * line = new TF1("line", "pol1",-10,10);
0125     line -> SetParameters(0,1);
0126     line -> SetLineStyle(2);
0127     line -> SetLineWidth(1);
0128     line -> SetLineColor(kRed);
0129 
0130     vector<TH1D*> h1D_nominal_data_RecoTracklet_vec; h1D_nominal_data_RecoTracklet_vec.clear();
0131     vector<TH1D*> h1D_nominal_MC_RecoTracklet_vec; h1D_nominal_MC_RecoTracklet_vec.clear();
0132     vector<TH1D*> h1D_nominal_correction_vec; h1D_nominal_correction_vec.clear(); 
0133 
0134     vector<TH1D*> h1D_vary_data_RecoTracklet_vec; h1D_vary_data_RecoTracklet_vec.clear();
0135     vector<TH1D*> h1D_vary_MC_RecoTracklet_vec; h1D_vary_MC_RecoTracklet_vec.clear();
0136     vector<TH1D*> h1D_vary_correction_vec; h1D_vary_correction_vec.clear(); 
0137 
0138     for (int i = 0; i < 15; i++) // note : 0 to 14, the Mbin
0139     {
0140         std::string Mbin_folder_name = Form("vtxZ_-10_10cm_MBin%d",i);
0141         
0142         std::string data_file = Form("Data_PreparedNdEtaEach_AlphaCorr_AllSensor_VtxZ10_Mbin%d_00054280_00000_DeltaPhi.root",i);
0143         std::string data_event_file = Form("Data_PreparedNdEtaEach_AlphaCorr_AllSensor_VtxZ10_Mbin%d_00054280_00000_dNdEta.root",i);
0144 
0145         std::string MC_file = Form("MC_PreparedNdEtaEach_AllSensor_VtxZ10_Mbin%d_00001_DeltaPhi.root",i);
0146         std::string MC_event_file = Form("MC_PreparedNdEtaEach_AllSensor_VtxZ10_Mbin%d_00001_dNdEta.root",i);
0147         std::string TruthHadron_file = Form("MC_PreparedNdEtaEach_AllSensor_VtxZ10_Mbin%d_00001_dNdEta.root",i);
0148 
0149         std::string recoevt_hist_name = "h2D_RecoEvtCount_vtxZCentrality";
0150         std::string TruthHadron_hist_name = "h1D_TruedNdEta";
0151         std::string data_dNdEta = "h1D_RotatedBkg_RecoTrackletEtaPerEvtPostAC";
0152 
0153         TFile * file_data = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), data_file.c_str()));
0154         TFile * file_data_event = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), data_event_file.c_str()));
0155         TH2D * data_recoevt = (TH2D*)file_data_event->Get(recoevt_hist_name.c_str());
0156         TH1D * h1D_data_dNdEta = (TH1D*)file_data_event->Get(data_dNdEta.c_str());
0157 
0158         TFile * file_MC = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), MC_file.c_str()));
0159         TFile * file_MC_event = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), MC_event_file.c_str()));
0160         TH2D * MC_recoevt = (TH2D*)file_MC_event->Get(recoevt_hist_name.c_str());
0161 
0162         TFile * file_TruthHadron = TFile::Open(Form("%s/%s/Folder_BaseLine/Run_0/completed/%s", mother_directory.c_str(), Mbin_folder_name.c_str(), TruthHadron_file.c_str()));
0163         TH1D * TruthHadron = (TH1D*)file_TruthHadron->Get(TruthHadron_hist_name.c_str());
0164 
0165 
0166         h1D_nominal_data_RecoTracklet_vec.push_back(new TH1D(Form("h1D_nominal_data_RecoTracklet_Mbin%d",i), "", 27, -2.7, 2.7));
0167         h1D_nominal_MC_RecoTracklet_vec.push_back(new TH1D(Form("h1D_nominal_MC_RecoTracklet_Mbin%d",i), "", 27, -2.7, 2.7));
0168         
0169         h1D_vary_data_RecoTracklet_vec.push_back(new TH1D(Form("h1D_vary_data_RecoTracklet_Mbin%d",i), "", 27, -2.7, 2.7));
0170         h1D_vary_MC_RecoTracklet_vec.push_back(new TH1D(Form("h1D_vary_MC_RecoTracklet_Mbin%d",i), "", 27, -2.7, 2.7));
0171         
0172 
0173         for (int eta_i = 7; eta_i <= 19; eta_i++)
0174         {
0175             std::string hist_name = Form("h1D_RotatedBkg_DeltaPhi_Signal_Eta%d", eta_i);
0176             TH1D * data = (TH1D*)file_data->Get(hist_name.c_str());
0177             TH1D * MC = (TH1D*)file_MC->Get(hist_name.c_str());
0178 
0179             std::pair<int,int> nominal_delta_phi_bin = get_DeltaPhi_SingleBin(data, {-1*nominal_deltaphi, nominal_deltaphi});
0180             std::pair<int,int> vary_delta_phi_bin = get_DeltaPhi_SingleBin(data, {-1*vary_deltaphi, vary_deltaphi});
0181 
0182             h1D_nominal_data_RecoTracklet_vec.back() -> SetBinContent(eta_i + 1, data -> Integral(nominal_delta_phi_bin.first, nominal_delta_phi_bin.second));
0183             h1D_nominal_MC_RecoTracklet_vec.back() -> SetBinContent(eta_i + 1, MC -> Integral(nominal_delta_phi_bin.first, nominal_delta_phi_bin.second));
0184 
0185             h1D_vary_data_RecoTracklet_vec.back() -> SetBinContent(eta_i + 1, data -> Integral(vary_delta_phi_bin.first, vary_delta_phi_bin.second));
0186             h1D_vary_MC_RecoTracklet_vec.back() -> SetBinContent(eta_i + 1, MC -> Integral(vary_delta_phi_bin.first, vary_delta_phi_bin.second));
0187         }
0188 
0189         h1D_nominal_data_RecoTracklet_vec.back() -> Scale(1. / (get_EvtCount(data_recoevt,i) * h1D_nominal_data_RecoTracklet_vec.back() -> GetBinWidth(1)));
0190         h1D_nominal_MC_RecoTracklet_vec.back() -> Scale(1. / (get_EvtCount(MC_recoevt, i) * h1D_nominal_MC_RecoTracklet_vec.back() -> GetBinWidth(1)));
0191 
0192         h1D_vary_data_RecoTracklet_vec.back() -> Scale(1. / (get_EvtCount(data_recoevt,i) * h1D_vary_data_RecoTracklet_vec.back() -> GetBinWidth(1)));
0193         h1D_vary_MC_RecoTracklet_vec.back() -> Scale(1. / (get_EvtCount(MC_recoevt, i) * h1D_vary_MC_RecoTracklet_vec.back() -> GetBinWidth(1)));
0194 
0195 
0196         h1D_nominal_correction_vec.push_back((TH1D*) TruthHadron -> Clone(Form("h1D_nominal_correction_Mbin%d",i)));
0197         h1D_vary_correction_vec.push_back((TH1D*) TruthHadron -> Clone(Form("h1D_vary_correction_Mbin%d",i)));
0198         
0199         h1D_nominal_correction_vec.back() -> Divide(h1D_nominal_MC_RecoTracklet_vec.back(), TruthHadron);
0200         h1D_vary_correction_vec.back() -> Divide(h1D_vary_MC_RecoTracklet_vec.back(), TruthHadron);
0201 
0202         h1D_nominal_data_RecoTracklet_vec.back() -> Divide(h1D_nominal_correction_vec.back()); 
0203         h1D_vary_data_RecoTracklet_vec.back() -> Divide(h1D_vary_correction_vec.back());
0204 
0205         c1 -> cd();
0206 
0207         TPad * pad1 = new TPad("pad1", "pad1", 0, 0.4, 1, 1);
0208         pad1 -> Draw();
0209         pad1 -> cd();
0210 
0211         h1D_nominal_data_RecoTracklet_vec.back() -> SetLineColor(kBlack);
0212         h1D_vary_data_RecoTracklet_vec.back() -> SetMarkerStyle(20);
0213         h1D_vary_data_RecoTracklet_vec.back() -> SetMarkerColor(kRed);
0214 
0215         h1D_data_dNdEta -> SetMarkerStyle(20);
0216         h1D_data_dNdEta -> SetMarkerColor(kBlue);
0217 
0218         h1D_nominal_data_RecoTracklet_vec.back() -> Draw("hist");
0219         h1D_vary_data_RecoTracklet_vec.back() -> Draw("ep same");
0220         h1D_data_dNdEta -> Draw("ep same");
0221 
0222         c1 -> cd();
0223         TPad * pad2 = new TPad("pad2", "pad2", 0, 0, 1, 0.35);
0224         pad2 -> Draw();
0225         pad2 -> cd();
0226         
0227         TH1D * ratio = (TH1D*) h1D_vary_data_RecoTracklet_vec.back() -> Clone(Form("ratio_Mbin%d",i));
0228         ratio -> Sumw2(true);
0229         ratio -> Divide(h1D_nominal_data_RecoTracklet_vec.back());
0230 
0231         ratio -> SetMinimum(0.95);
0232         ratio -> SetMaximum(1.05);
0233 
0234         ratio -> SetMarkerSize(2);
0235         ratio -> SetMarkerStyle(20);
0236         ratio -> SetMarkerColor(kBlack);
0237 
0238         ratio -> Draw("hist text90");
0239 
0240         TLine * line = new TLine(-2.7, 1, 2.7, 1);
0241         line -> SetLineColor(kBlack);
0242         line -> SetLineStyle(2);
0243 
0244         line -> Draw("same");
0245 
0246 
0247         c1 -> Print("DeltaPhi_dNdEta.pdf");
0248     }
0249 
0250     c1 -> Print("DeltaPhi_dNdEta.pdf)");
0251 
0252 
0253     return 888;
0254 }