Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:37

0001 #include "InttVtxZQA_Bias.h"
0002 
0003 InttVtxZQA_Bias::InttVtxZQA_Bias(
0004     int process_id_in,
0005     int runnumber_in,
0006     int run_nEvents_in,
0007     std::string input_directory_in,
0008     std::string input_file_name_in,
0009     std::string output_directory_in,
0010 
0011     std::string output_file_name_suffix_in,
0012 
0013     std::pair<bool, int> ApplyEvtBcoFullDiffCut_in
0014 ):
0015     process_id(process_id_in),
0016     runnumber(runnumber_in),
0017     run_nEvents(run_nEvents_in),
0018     input_directory(input_directory_in),
0019     input_file_name(input_file_name_in),
0020     output_directory(output_directory_in),
0021     output_file_name_suffix(output_file_name_suffix_in),
0022     ApplyEvtBcoFullDiffCut(ApplyEvtBcoFullDiffCut_in)
0023 {
0024     PrepareOutPutFileName();
0025     PrepareInputFile();
0026 
0027     run_nEvents = (run_nEvents == -1) ? tree_in->GetEntries() : run_nEvents;
0028     run_nEvents = (run_nEvents > tree_in->GetEntries()) ? tree_in->GetEntries() : run_nEvents;
0029     nCentrality_bin = centrality_edges.size() - 1;
0030 
0031     PrepareOutputFile();
0032     PrepareHist();
0033 
0034 }
0035 
0036 void InttVtxZQA_Bias::PrepareOutPutFileName()
0037 {
0038     std::string job_index = std::to_string( process_id );
0039     int job_index_len = 5;
0040     job_index.insert(0, job_index_len - job_index.size(), '0');
0041 
0042     std::string runnumber_str = std::to_string( runnumber );
0043     if (runnumber != -1){
0044         int runnumber_str_len = 8;
0045         runnumber_str.insert(0, runnumber_str_len - runnumber_str.size(), '0');
0046     }
0047 
0048     if (output_file_name_suffix.size() > 0 && output_file_name_suffix[0] != '_') {
0049         output_file_name_suffix = "_" + output_file_name_suffix;
0050     }
0051 
0052     output_filename = "InttVtxZBias";
0053     output_filename = (runnumber != -1) ? "Data_" + output_filename : "MC_" + output_filename;
0054 
0055     output_filename += (runnumber != -1 && ApplyEvtBcoFullDiffCut.first) ? Form("_EvtBcoFullDiffCut%d", ApplyEvtBcoFullDiffCut.second) : "";
0056 
0057     output_filename += output_file_name_suffix;
0058     output_filename += (runnumber != -1) ? Form("_%s_%s.root",runnumber_str.c_str(),job_index.c_str()) : Form("_%s.root",job_index.c_str());
0059 }
0060 
0061 std::map<std::string, int> InttVtxZQA_Bias::GetInputTreeBranches(TTree * m_tree_in)
0062 {
0063     std::map<std::string, int> branch_map;
0064     TObjArray * branch_list = m_tree_in -> GetListOfBranches();
0065     for (int i = 0; i < branch_list -> GetEntries(); i++)
0066     {
0067         TBranch * branch = dynamic_cast<TBranch*>(branch_list->At(i));
0068         branch_map[branch -> GetName()] = 1;
0069     }
0070     return branch_map;
0071 }
0072 
0073 void InttVtxZQA_Bias::PrepareInputFile()
0074 {
0075     file_in = TFile::Open(Form("%s/%s", input_directory.c_str(), input_file_name.c_str()));
0076     tree_in = (TTree*)file_in->Get(tree_name.c_str());
0077 
0078     std::map<std::string, int> branch_map = GetInputTreeBranches(tree_in);
0079 
0080     tree_in -> SetBranchStatus("*", 0);
0081 
0082     tree_in -> SetBranchStatus("is_min_bias", 1);
0083     tree_in -> SetBranchStatus("MBD_centrality", 1);
0084     tree_in -> SetBranchStatus("MBD_z_vtx", 1);
0085     tree_in -> SetBranchStatus("MBD_charge_sum", 1);
0086 
0087     tree_in -> SetBranchStatus("INTTvtxZ", 1);
0088     tree_in -> SetBranchStatus("INTTvtxZError", 1);
0089     tree_in -> SetBranchStatus("NgroupTrapezoidal", 1);
0090     tree_in -> SetBranchStatus("NgroupCoarse", 1);
0091     tree_in -> SetBranchStatus("TrapezoidalFitWidth", 1);
0092     tree_in -> SetBranchStatus("TrapezoidalFWHM", 1);
0093 
0094     tree_in -> SetBranchStatus("NClus", 1);
0095     tree_in -> SetBranchStatus("NClus_Layer1", 1);
0096     
0097     // note : for data
0098     if (branch_map.find("MBDNSg2") != branch_map.end()) {
0099         tree_in -> SetBranchStatus("MBDNSg2", 1);
0100         m_withTrig = true;
0101     }
0102     if (branch_map.find("MBDNSg2_vtxZ10cm") != branch_map.end()) {tree_in -> SetBranchStatus("MBDNSg2_vtxZ10cm", 1);}
0103     if (branch_map.find("MBDNSg2_vtxZ30cm") != branch_map.end()) {tree_in -> SetBranchStatus("MBDNSg2_vtxZ30cm", 1);}
0104     
0105     if (branch_map.find("InttBcoFullDiff_next") != branch_map.end()) {tree_in -> SetBranchStatus("InttBcoFullDiff_next", 1); }
0106     
0107     // note :for MC
0108     if (branch_map.find("NTruthVtx") != branch_map.end()) {tree_in -> SetBranchStatus("NTruthVtx", 1);}
0109     if (branch_map.find("TruthPV_trig_z") != branch_map.end()) {tree_in -> SetBranchStatus("TruthPV_trig_z", 1);}
0110 
0111     // Division : ---SetBranchAddress-----------------------------------------------------------------------------------------------
0112     tree_in -> SetBranchAddress("is_min_bias", &is_min_bias);
0113     tree_in -> SetBranchAddress("MBD_centrality", &MBD_centrality);
0114     tree_in -> SetBranchAddress("MBD_z_vtx", &MBD_z_vtx);
0115     tree_in -> SetBranchAddress("MBD_charge_sum", &MBD_charge_sum);
0116 
0117     tree_in -> SetBranchAddress("INTTvtxZ", &INTTvtxZ);
0118     tree_in -> SetBranchAddress("INTTvtxZError", &INTTvtxZError);
0119     tree_in -> SetBranchAddress("NgroupTrapezoidal", &NgroupTrapezoidal);
0120     tree_in -> SetBranchAddress("NgroupCoarse", &NgroupCoarse);
0121     tree_in -> SetBranchAddress("TrapezoidalFitWidth", &TrapezoidalFitWidth);
0122     tree_in -> SetBranchAddress("TrapezoidalFWHM", &TrapezoidalFWHM);
0123 
0124     tree_in -> SetBranchAddress("NClus", &NClus);
0125     tree_in -> SetBranchAddress("NClus_Layer1", &NClus_Layer1);
0126 
0127     // note : for data
0128     if (branch_map.find("MBDNSg2") != branch_map.end()) {tree_in -> SetBranchAddress("MBDNSg2", &MBDNSg2);}
0129     if (branch_map.find("MBDNSg2_vtxZ10cm") != branch_map.end()) {tree_in -> SetBranchAddress("MBDNSg2_vtxZ10cm", &MBDNSg2_vtxZ10cm);}
0130     if (branch_map.find("MBDNSg2_vtxZ30cm") != branch_map.end()) {tree_in -> SetBranchAddress("MBDNSg2_vtxZ30cm", &MBDNSg2_vtxZ30cm);}
0131 
0132     if (branch_map.find("InttBcoFullDiff_next") != branch_map.end()) {tree_in -> SetBranchAddress("InttBcoFullDiff_next", &InttBcoFullDiff_next); }
0133 
0134     // note : for MC
0135     if (branch_map.find("NTruthVtx") != branch_map.end()) {tree_in -> SetBranchAddress("NTruthVtx", &NTruthVtx);}
0136     if (branch_map.find("TruthPV_trig_z") != branch_map.end()) {tree_in -> SetBranchAddress("TruthPV_trig_z", &TruthPV_trig_z);}
0137 }
0138 
0139 void InttVtxZQA_Bias::PrepareOutputFile()
0140 {
0141     file_out = new TFile(Form("%s/%s", output_directory.c_str(), output_filename.c_str()), "RECREATE");
0142 }
0143 
0144 void InttVtxZQA_Bias::PrepareHist()
0145 {
0146 
0147     h1D_centrality_bin = new TH1D("h1D_centrality_bin","h1D_centrality_bin;Centrality [%];Entries",nCentrality_bin,&centrality_edges[0]); // note : the 0-5%
0148 
0149     h1D_NoQA_map.clear();
0150     h2D_NoQA_map.clear();
0151 
0152     h1D_NoQA_map.insert(
0153         std::make_pair(
0154             "NoQA_h1D_centrality",
0155             new TH1D("NoQA_h1D_centrality","NoQA_h1D_centrality;Centrality [%];Entries", nCentralityFineBin, CentralityFineEdge_min, CentralityFineEdge_max)
0156         )
0157     );
0158 
0159     for (int i = 0; i < nCentrality_bin; i++)
0160     {
0161         h1D_NoQA_map.insert(
0162             std::make_pair(
0163                 Form("NoQA_h1D_NClus_Mbin%d",i),
0164                 new TH1D(Form("NoQA_h1D_NClus_Mbin%d", i),Form("NoQA_h1D_NClus_Mbin%d;NClus;Entries", i), 50, Mbin_NClus_edges[i].first, Mbin_NClus_edges[i].second)
0165             )
0166         );
0167     }
0168 
0169     h1D_NoQA_map.insert(
0170         std::make_pair(
0171             "NoQA_h1D_NClus",
0172             new TH1D("NoQA_h1D_NClus","NoQA_h1D_NClus;INTT NClus;Entries", 200,0,10000)
0173         )
0174     );
0175 
0176     h1D_NoQA_map.insert(
0177         std::make_pair(
0178             "NoQA_h1D_TrapezoidalFitWidth",
0179             new TH1D("NoQA_h1D_TrapezoidalFitWidth","NoQA_h1D_TrapezoidalFitWidth;INTT vtxZ Dist Fit Width [cm];Entries", 100, 0, 15)
0180         )
0181     );
0182 
0183     h1D_NoQA_map.insert(
0184         std::make_pair(
0185             "NoQA_h1D_TrapezoidalFWHM",
0186             new TH1D("NoQA_h1D_TrapezoidalFWHM","NoQA_h1D_TrapezoidalFWHM;INTT vtxZ Dist FWHM [cm];Entries", 100, 0, 15)
0187         )
0188     );
0189 
0190     h1D_NoQA_map.insert(
0191         std::make_pair(
0192             "NoQA_h1D_INTTvtxZError",
0193             new TH1D("NoQA_h1D_INTTvtxZError","NoQA_h1D_INTTvtxZError;INTT vtxZ StdDev [cm];Entries", 100, 0, 15)
0194         )
0195     );
0196 
0197     h1D_NoQA_map.insert(
0198         std::make_pair(
0199             "NoQA_h1D_NgroupTrapezoidal",
0200             new TH1D("NoQA_h1D_NgroupTrapezoidal","NoQA_h1D_NgroupTrapezoidal;N group (Trapezoidal);Entries", 15, 0, 15)
0201         )
0202     );
0203 
0204     h1D_NoQA_map.insert(
0205         std::make_pair(
0206             "NoQA_h1D_NgroupCoarse",
0207             new TH1D("NoQA_h1D_NgroupCoarse","NoQA_h1D_NgroupCoarse;N group (Coarse);Entries", 15, 0, 15)
0208         )
0209     );
0210 
0211     h1D_NoQA_map.insert(
0212         std::make_pair(
0213             "NoQA_h1D_VtxZDiffMbdIntt",
0214             new TH1D("NoQA_h1D_VtxZDiffMbdIntt","NoQA_h1D_VtxZDiffMbdIntt;MBD vtxZ - INTT vtxZ [cm];Entries", 100, -15, 15)
0215         )
0216     );
0217 
0218     h2D_NoQA_map.insert(
0219         std::make_pair(
0220             "NoQANoINTTz_h2D_MBDvtxZ_centrality",
0221             new TH2D("NoQANoINTTz_h2D_MBDvtxZ_centrality","NoQANoINTTz_h2D_MBDvtxZ_centrality;MBD vtxZ;Centrality [%]", 8, -40,40, nCentralityFineBin, CentralityFineEdge_min, CentralityFineEdge_max)
0222         )
0223     );
0224 
0225     h2D_NoQA_map.insert(
0226         std::make_pair(
0227             "NoQA_h2D_MBDvtxZ_centrality",
0228             new TH2D("NoQA_h2D_MBDvtxZ_centrality","NoQA_h2D_MBDvtxZ_centrality;MBD vtxZ;Centrality [%]", 8, -40,40, nCentralityFineBin, CentralityFineEdge_min, CentralityFineEdge_max)
0229         )
0230     );
0231 
0232     h2D_NoQA_map.insert(
0233         std::make_pair(
0234             "NoQA_h2D_NClus_INTTvtxZ",
0235             new TH2D("NoQA_h2D_NClus_INTTvtxZ","NoQA_h2D_NClus_INTTvtxZ;NClus (INTT);INTT vtxZ [cm]",200, 0, 10000, 200, vtxZ_range.first, vtxZ_range.second)
0236         )
0237     );
0238 
0239     h2D_NoQA_map.insert(
0240         std::make_pair(
0241             "NoQA_h2D_NClus_TrapezoidalFitWidth",
0242             new TH2D("NoQA_h2D_NClus_TrapezoidalFitWidth","NoQA_h2D_NClus_TrapezoidalFitWidth;NClus;INTT vtxZ Dist Fit Width [cm]", 100, 0, 10000, 100, 0, 15)
0243         )
0244     );
0245 
0246     h2D_NoQA_map.insert(
0247         std::make_pair(
0248             "NoQA_h2D_NClus_TrapezoidalFWHM",
0249             new TH2D("NoQA_h2D_NClus_TrapezoidalFWHM","NoQA_h2D_NClus_TrapezoidalFWHM;NClus;INTT vtxZ Dist FWHM [cm]", 100, 0, 10000, 100, 0, 15)
0250         )
0251     );
0252 
0253     h2D_NoQA_map.insert(
0254         std::make_pair(
0255             "NoQA_h2D_NClus_INTTvtxZError",
0256             new TH2D("NoQA_h2D_NClus_INTTvtxZError","NoQA_h2D_NClus_INTTvtxZError;NClus;INTT vtxZ StdDev [cm]", 100, 0, 10000, 100, 0, 15)
0257         )
0258     );
0259 
0260     h2D_NoQA_map.insert(
0261         std::make_pair(
0262             "NoQA_h2D_NClus_VtxZDiffMbdIntt",
0263             new TH2D("NoQA_h2D_NClus_VtxZDiffMbdIntt","NoQA_h2D_NClus_VtxZDiffMbdIntt;NClus;MBD vtxZ - INTT vtxZ [cm]", 100, 0, 10000, 100, -15,15)
0264         )
0265     );
0266 
0267     h2D_NoQA_map.insert(
0268         std::make_pair(
0269             "NoQA_h2D_TrapezoidalFitWidth_TrapezoidalFWHM",
0270             new TH2D("NoQA_h2D_TrapezoidalFitWidth_TrapezoidalFWHM","NoQA_h2D_TrapezoidalFitWidth_TrapezoidalFWHM;INTT vtxZ Dist Fit Width [cm];INTT vtxZ Dist FWHM [cm]", 100, 0, 15, 100, 0, 15)
0271         )
0272     );
0273 
0274     h2D_NoQA_map.insert(
0275         std::make_pair(
0276             "NoQA_h2D_TrapezoidalFitWidth_VtxZDiffMbdIntt",
0277             new TH2D("NoQA_h2D_TrapezoidalFitWidth_VtxZDiffMbdIntt","NoQA_h2D_TrapezoidalFitWidth_VtxZDiffMbdIntt;INTT vtxZ Dist Fit Width [cm];MBD vtxZ - INTT vtxZ [cm]", 100, 0, 15, 100, -15, 15)
0278         )
0279     );
0280 
0281     h2D_NoQA_map.insert(
0282         std::make_pair(
0283             "NoQA_h2D_TrapezoidalFWHM_VtxZDiffMbdIntt",
0284             new TH2D("NoQA_h2D_TrapezoidalFWHM_VtxZDiffMbdIntt","NoQA_h2D_TrapezoidalFWHM_VtxZDiffMbdIntt;INTT vtxZ Dist FWHM [cm];MBD vtxZ - INTT vtxZ [cm]", 100, 0, 15, 100, -15, 15)
0285         )
0286     );
0287 
0288     h2D_NoQA_map.insert(
0289         std::make_pair(
0290             "NoQA_h2D_TrapezoidalFitWidth_INTTvtxZError",
0291             new TH2D("NoQA_h2D_TrapezoidalFitWidth_INTTvtxZError","NoQA_h2D_TrapezoidalFitWidth_INTTvtxZError;INTT vtxZ Dist Fit Width [cm];INTT vtxZ StdDev [cm]", 100, 0, 15, 100, 0, 15)
0292         )
0293     );
0294 
0295     for (auto &hist : h1D_NoQA_map)
0296     {
0297         std::string YTitle = hist.second -> GetYaxis() -> GetTitle();
0298         std::string XTitle = hist.second -> GetXaxis() -> GetTitle();
0299 
0300         std::string YTitle_post;
0301 
0302         if (YTitle.find("Entries") != std::string::npos) // note : found the (Entries)
0303         {
0304             YTitle_post = Form("Entries  (/%.2f)", hist.second -> GetBinWidth(1));
0305             hist.second -> GetYaxis() -> SetTitle(YTitle_post.c_str());
0306         }
0307     }
0308 
0309 
0310     h1D_PostQA_map.clear();
0311     h2D_PostQA_map.clear();
0312 
0313     for (auto &hist : h1D_NoQA_map)
0314     {
0315         h1D_PostQA_map[ReplaceBy(hist.first, "NoQA", "PostQA")] = (TH1D*)hist.second -> Clone(ReplaceBy(hist.first, "NoQA", "PostQA").c_str());
0316         h1D_PostQA_map[ReplaceBy(hist.first, "NoQA", "PostQA")] -> SetTitle(ReplaceBy(hist.second -> GetTitle(), "NoQA", "PostQA").c_str());
0317     }
0318 
0319     for (auto &hist : h2D_NoQA_map)
0320     {
0321         h2D_PostQA_map[ReplaceBy(hist.first, "NoQA", "PostQA")] = (TH2D*)hist.second -> Clone(ReplaceBy(hist.first, "NoQA", "PostQA").c_str());
0322         h2D_PostQA_map[ReplaceBy(hist.first, "NoQA", "PostQA")] -> SetTitle(ReplaceBy(hist.second -> GetTitle(), "NoQA", "PostQA").c_str());
0323     }
0324 
0325 }
0326 
0327 void InttVtxZQA_Bias::PrepareEvent()
0328 {
0329     for (int i = 0; i < run_nEvents; i++)
0330     {
0331         tree_in -> GetEntry(i);
0332 
0333         if (i % 500 == 0) {std::cout << "Processing Event " << i << " / " << run_nEvents << std::endl;}
0334 
0335         // =======================================================================================================================================================
0336         // note : hard cut
0337 
0338         // note : for data
0339         if (runnumber != -1 && ApplyEvtBcoFullDiffCut.first && InttBcoFullDiff_next <= ApplyEvtBcoFullDiffCut.second) {continue;}
0340         if (runnumber != -1 && MBDNSg2 != 1) {continue;} // todo: assume MC no trigger
0341 
0342         // note : for MC
0343         // if (runnumber == -1 && NTruthVtx != 1) {continue;}
0344 
0345         // note : both data and MC
0346         if (is_min_bias != 1) {continue;}
0347         if (MBD_z_vtx != MBD_z_vtx) {continue;}
0348         if (MBD_centrality != MBD_centrality) {continue;}
0349         if (MBD_centrality < 0 || MBD_centrality > 100) {continue;}
0350 
0351         h2D_NoQA_map["NoQANoINTTz_h2D_MBDvtxZ_centrality"] -> Fill(MBD_z_vtx, MBD_centrality);
0352 
0353         if (INTTvtxZ != INTTvtxZ) {continue;}
0354 
0355         h2D_NoQA_map["NoQA_h2D_MBDvtxZ_centrality"] -> Fill(MBD_z_vtx, MBD_centrality);
0356 
0357         if (MBD_z_vtx < -10 || MBD_z_vtx > 10) {continue;} // todo: the hard cut 10 cm 
0358         if (MBD_centrality > 70) {continue;} // todo : the hard cut > 70% centrality interval
0359         // =======================================================================================================================================================
0360 
0361         int Mbin = h1D_centrality_bin -> Fill(MBD_centrality);
0362         Mbin = (Mbin == -1) ? -1 : Mbin - 1;
0363         if (Mbin == -1) {
0364             std::cout << "Mbin == -1, MBD_centrality = " << MBD_centrality << std::endl;
0365             continue;
0366         }
0367 
0368         h1D_NoQA_map[Form("NoQA_h1D_NClus_Mbin%d",Mbin)] -> Fill(NClus);
0369         h1D_NoQA_map["NoQA_h1D_centrality"] -> Fill(MBD_centrality);
0370         h1D_NoQA_map["NoQA_h1D_NClus"] -> Fill(NClus);
0371         h1D_NoQA_map["NoQA_h1D_TrapezoidalFitWidth"] -> Fill(TrapezoidalFitWidth);
0372         h1D_NoQA_map["NoQA_h1D_TrapezoidalFWHM"] -> Fill(TrapezoidalFWHM);
0373         h1D_NoQA_map["NoQA_h1D_INTTvtxZError"] -> Fill(INTTvtxZError);
0374         h1D_NoQA_map["NoQA_h1D_NgroupTrapezoidal"] -> Fill(NgroupTrapezoidal);
0375         h1D_NoQA_map["NoQA_h1D_NgroupCoarse"] -> Fill(NgroupCoarse);
0376         h1D_NoQA_map["NoQA_h1D_VtxZDiffMbdIntt"] -> Fill(MBD_z_vtx - INTTvtxZ);
0377         h2D_NoQA_map["NoQA_h2D_NClus_INTTvtxZ"] -> Fill(NClus, INTTvtxZ);
0378         h2D_NoQA_map["NoQA_h2D_NClus_TrapezoidalFitWidth"] -> Fill(NClus, TrapezoidalFitWidth);
0379         h2D_NoQA_map["NoQA_h2D_NClus_TrapezoidalFWHM"] -> Fill(NClus, TrapezoidalFWHM);
0380         h2D_NoQA_map["NoQA_h2D_NClus_INTTvtxZError"] -> Fill(NClus, INTTvtxZError);
0381         h2D_NoQA_map["NoQA_h2D_NClus_VtxZDiffMbdIntt"] -> Fill(NClus, MBD_z_vtx - INTTvtxZ);
0382 
0383         h2D_NoQA_map["NoQA_h2D_TrapezoidalFitWidth_TrapezoidalFWHM"] -> Fill(TrapezoidalFitWidth, TrapezoidalFWHM);
0384         h2D_NoQA_map["NoQA_h2D_TrapezoidalFitWidth_VtxZDiffMbdIntt"] -> Fill(TrapezoidalFitWidth, MBD_z_vtx - INTTvtxZ);
0385         h2D_NoQA_map["NoQA_h2D_TrapezoidalFWHM_VtxZDiffMbdIntt"] -> Fill(TrapezoidalFWHM, MBD_z_vtx - INTTvtxZ);
0386         h2D_NoQA_map["NoQA_h2D_TrapezoidalFitWidth_INTTvtxZError"] -> Fill(TrapezoidalFitWidth, INTTvtxZError);
0387 
0388         // =======================================================================================================================================================
0389         // note : optional cut
0390         if ((MBD_z_vtx - INTTvtxZ < cut_vtxZDiff.first || MBD_z_vtx - INTTvtxZ > cut_vtxZDiff.second) ) {continue;}
0391         if ((TrapezoidalFitWidth < cut_TrapezoidalFitWidth.first || TrapezoidalFitWidth > cut_TrapezoidalFitWidth.second)){continue;}
0392         if ((TrapezoidalFWHM < cut_TrapezoidalFWHM.first || TrapezoidalFWHM > cut_TrapezoidalFWHM.second)){continue;}
0393         if ((INTTvtxZError < cut_INTTvtxZError.first || INTTvtxZError > cut_INTTvtxZError.second)){continue;}
0394 
0395         // =======================================================================================================================================================
0396 
0397         h1D_PostQA_map[Form("PostQA_h1D_NClus_Mbin%d",Mbin)] -> Fill(NClus);
0398         h1D_PostQA_map["PostQA_h1D_centrality"] -> Fill(MBD_centrality);
0399         h1D_PostQA_map["PostQA_h1D_NClus"] -> Fill(NClus);
0400         h1D_PostQA_map["PostQA_h1D_TrapezoidalFitWidth"] -> Fill(TrapezoidalFitWidth);
0401         h1D_PostQA_map["PostQA_h1D_TrapezoidalFWHM"] -> Fill(TrapezoidalFWHM);
0402         h1D_PostQA_map["PostQA_h1D_INTTvtxZError"] -> Fill(INTTvtxZError);
0403         h1D_PostQA_map["PostQA_h1D_NgroupTrapezoidal"] -> Fill(NgroupTrapezoidal);
0404         h1D_PostQA_map["PostQA_h1D_NgroupCoarse"] -> Fill(NgroupCoarse);
0405         h1D_PostQA_map["PostQA_h1D_VtxZDiffMbdIntt"] -> Fill(MBD_z_vtx - INTTvtxZ);
0406         h2D_PostQA_map["PostQA_h2D_NClus_INTTvtxZ"] -> Fill(NClus, INTTvtxZ);
0407         h2D_PostQA_map["PostQA_h2D_NClus_TrapezoidalFitWidth"] -> Fill(NClus, TrapezoidalFitWidth);
0408         h2D_PostQA_map["PostQA_h2D_NClus_TrapezoidalFWHM"] -> Fill(NClus, TrapezoidalFWHM);
0409         h2D_PostQA_map["PostQA_h2D_NClus_INTTvtxZError"] -> Fill(NClus, INTTvtxZError);
0410         h2D_PostQA_map["PostQA_h2D_NClus_VtxZDiffMbdIntt"] -> Fill(NClus, MBD_z_vtx - INTTvtxZ);
0411 
0412         h2D_PostQA_map["PostQA_h2D_TrapezoidalFitWidth_TrapezoidalFWHM"] -> Fill(TrapezoidalFitWidth, TrapezoidalFWHM);
0413         h2D_PostQA_map["PostQA_h2D_TrapezoidalFitWidth_VtxZDiffMbdIntt"] -> Fill(TrapezoidalFitWidth, MBD_z_vtx - INTTvtxZ);
0414         h2D_PostQA_map["PostQA_h2D_TrapezoidalFWHM_VtxZDiffMbdIntt"] -> Fill(TrapezoidalFWHM, MBD_z_vtx - INTTvtxZ);
0415         h2D_PostQA_map["PostQA_h2D_TrapezoidalFitWidth_INTTvtxZError"] -> Fill(TrapezoidalFitWidth, INTTvtxZError);
0416  
0417     } // note : end of the event loop
0418 }
0419 
0420 void InttVtxZQA_Bias::EndRun()
0421 {
0422     file_out -> cd();
0423     for (auto &hist : h1D_NoQA_map)
0424     {
0425         hist.second -> Write();
0426     }
0427 
0428     for (auto &hist : h2D_NoQA_map)
0429     {
0430         hist.second -> Write();
0431     }
0432 
0433     for (auto &hist : h1D_PostQA_map)
0434     {
0435         hist.second -> Write();
0436     }
0437 
0438     for (auto &hist : h2D_PostQA_map)
0439     {
0440         hist.second -> Write();
0441     }
0442 
0443 
0444     file_out -> Close();
0445 }
0446 
0447 std::string InttVtxZQA_Bias::ReplaceBy(const std::string& input_str, const std::string& target_str, const std::string& new_str) {
0448     if (target_str.empty()) {
0449         return input_str; // Avoid infinite loop when replacing empty string
0450     }
0451 
0452 
0453 
0454     std::string output_str = input_str;
0455     size_t pos = 0;
0456 
0457     while ((pos = output_str.find(target_str, pos)) != std::string::npos) {
0458         output_str.replace(pos, target_str.length(), new_str);
0459         pos += new_str.length(); // Move past the replaced part
0460     }
0461 
0462     std::cout << "ReplaceBy: " << input_str << " -> " << output_str << std::endl;
0463 
0464     return output_str;
0465 }