Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 vector<string> read_list(string folder_direction, string MC_list_name)
0002 {
0003     vector<string> file_list;
0004     string list_buffer;
0005     ifstream data_list;
0006     data_list.open((folder_direction + "/" + MC_list_name).c_str());
0007 
0008    file_list.clear();
0009 
0010     while (1)
0011     {
0012         data_list >> list_buffer;
0013         if (!data_list.good())
0014         {
0015             break;
0016         }
0017 
0018         if (list_buffer[0] == '#') {continue;}
0019 
0020         file_list.push_back(list_buffer);
0021     }
0022     cout<<"size in the" <<MC_list_name<<": "<<file_list.size()<<endl;
0023 
0024     return file_list;
0025 }
0026 
0027 std::map<std::string, int> GetInputTreeBranchesMap(TChain * m_tree_in)
0028 {
0029     std::map<std::string, int> branch_map;
0030     TObjArray * branch_list = m_tree_in -> GetListOfBranches();
0031     for (int i = 0; i < branch_list -> GetEntries(); i++)
0032     {
0033         TBranch * branch = dynamic_cast<TBranch*>(branch_list->At(i));
0034         branch_map[branch -> GetName()] = 1;
0035     }
0036     return branch_map;
0037 }
0038 
0039 
0040 float SystUncRange()
0041 {
0042     std::string file_list_directory = "/sphenix/user/ChengWei/sPH_dNdeta/Run24AuAuMC/Sim_HIJING_MDC2_ana472_20250307/Run7/EvtVtxZ/FinalResult_10cm_Pol2BkgFit_DeltaPhi0p026/completed";
0043     // std::string file_list_directory = "/sphenix/tg/tg01/commissioning/INTT/work/cwshih/seflgendata/run_54280_HR_Feb102025/Run6_EvtZFitWidthChange/EvtVtxZ/FinalResult_10cm_Pol2BkgFit/completed";
0044     std::string file_list_name = "file_list.txt";
0045 
0046     std::vector<std::string> file_list = read_list(file_list_directory, file_list_name);
0047 
0048     TChain * chain = new TChain("tree");
0049     for (int i = 0; i < file_list.size(); i++)
0050     {
0051         chain -> Add(file_list[i].c_str());
0052     }
0053 
0054     cout<<"chain -> GetEntries() : "<<chain -> GetEntries()<<endl;
0055 
0056     std::pair<double,double> *UncRange_StatUnc = 0;
0057     std::pair<double,double> *UncRange_RunSegment = 0;
0058     std::pair<double,double> *UncRange_ClusAdc = 0;
0059     std::pair<double,double> *UncRange_GeoOffset = 0;
0060     std::pair<double,double> *UncRange_DeltaPhi = 0;
0061     std::pair<double,double> *UncRange_ClusPhiSize = 0;
0062     std::pair<double,double> *UncRange_Strangeness = 0;
0063     std::pair<double,double> *UncRange_Generator = 0;
0064     std::pair<double,double> *UncRange_Final = 0;
0065 
0066     std::map<std::string, int> branch_map = GetInputTreeBranchesMap(chain);
0067 
0068     if(branch_map.find("UncRange_StatUnc") != branch_map.end()) {chain -> SetBranchAddress("UncRange_StatUnc", &UncRange_StatUnc);}
0069     if(branch_map.find("UncRange_RunSegment") != branch_map.end()) {chain -> SetBranchAddress("UncRange_RunSegment", &UncRange_RunSegment);}
0070     if(branch_map.find("UncRange_ClusAdc") != branch_map.end()) {chain -> SetBranchAddress("UncRange_ClusAdc", &UncRange_ClusAdc);}
0071     if(branch_map.find("UncRange_GeoOffset") != branch_map.end()) {chain -> SetBranchAddress("UncRange_GeoOffset", &UncRange_GeoOffset);}
0072     if(branch_map.find("UncRange_DeltaPhi") != branch_map.end()) {chain -> SetBranchAddress("UncRange_DeltaPhi", &UncRange_DeltaPhi);}
0073     if(branch_map.find("UncRange_ClusPhiSize") != branch_map.end()) {chain -> SetBranchAddress("UncRange_ClusPhiSize", &UncRange_ClusPhiSize);}
0074     if(branch_map.find("UncRange_Strangeness") != branch_map.end()) {chain -> SetBranchAddress("UncRange_Strangeness", &UncRange_Strangeness);}
0075     if(branch_map.find("UncRange_Generator") != branch_map.end()) {chain -> SetBranchAddress("UncRange_Generator", &UncRange_Generator);}
0076     if(branch_map.find("UncRange_Final") != branch_map.end()) {chain -> SetBranchAddress("UncRange_Final", &UncRange_Final);}
0077 
0078     std::pair<double,double> MinMax_StatUnc = {9999999, -9999999};
0079     std::pair<double,double> MinMax_RunSegment = {9999999, -9999999};
0080     std::pair<double,double> MinMax_ClusAdc = {9999999, -9999999};
0081     std::pair<double,double> MinMax_GeoOffset = {9999999, -9999999};
0082     std::pair<double,double> MinMax_DeltaPhi = {9999999, -9999999};
0083     std::pair<double,double> MinMax_ClusPhiSize = {9999999, -9999999};
0084     std::pair<double,double> MinMax_Strangeness = {9999999, -9999999};
0085     std::pair<double,double> MinMax_Generator = {9999999, -9999999};
0086     std::pair<double,double> MinMax_Final = {9999999, -9999999};
0087 
0088     for (int i = 0; i < chain -> GetEntries(); i++)
0089     {
0090         chain -> GetEntry(i);
0091 
0092         cout<<"i: "<<i<<", file: "<<file_list[i]<<endl;
0093 
0094         if (branch_map.find("UncRange_StatUnc") != branch_map.end()) 
0095         {
0096             if (UncRange_StatUnc->first != UncRange_StatUnc->first || UncRange_StatUnc->second != UncRange_StatUnc->second)
0097             {
0098                 std::cout<<"In file: "<<file_list[i]<<", UncRange_StatUnc is nan"<<std::endl;
0099             }
0100 
0101             if (MinMax_StatUnc.first > UncRange_StatUnc -> first)
0102             {
0103                 MinMax_StatUnc.first = UncRange_StatUnc -> first;
0104             }
0105             if (MinMax_StatUnc.second < UncRange_StatUnc -> second)
0106             {
0107                 MinMax_StatUnc.second = UncRange_StatUnc -> second;
0108             }
0109         }
0110 
0111         // Division: -----------------------------------------------------------------------------------------------------------------------------
0112 
0113         if (branch_map.find("UncRange_RunSegment") != branch_map.end()) 
0114         {
0115             if (UncRange_RunSegment->first != UncRange_RunSegment->first || UncRange_RunSegment->second != UncRange_RunSegment->second)
0116             {
0117                 std::cout<<"In file: "<<file_list[i]<<", UncRange_RunSegment is nan"<<std::endl;
0118             }
0119 
0120             if (MinMax_RunSegment.first > UncRange_RunSegment -> first)
0121             {
0122                 MinMax_RunSegment.first = UncRange_RunSegment -> first;
0123             }
0124             if (MinMax_RunSegment.second < UncRange_RunSegment -> second)
0125             {
0126                 MinMax_RunSegment.second = UncRange_RunSegment -> second;
0127             }
0128         }
0129 
0130         // Division: -----------------------------------------------------------------------------------------------------------------------------
0131 
0132         if (branch_map.find("UncRange_ClusAdc") != branch_map.end()) 
0133         {
0134             if (UncRange_ClusAdc->first != UncRange_ClusAdc->first || UncRange_ClusAdc->second != UncRange_ClusAdc->second)
0135             {
0136                 std::cout<<"In file: "<<file_list[i]<<", UncRange_ClusAdc is nan"<<std::endl;
0137             }
0138 
0139             if (MinMax_ClusAdc.first > UncRange_ClusAdc -> first)
0140             {
0141                 MinMax_ClusAdc.first = UncRange_ClusAdc -> first;
0142             }
0143             if (MinMax_ClusAdc.second < UncRange_ClusAdc -> second)
0144             {
0145                 MinMax_ClusAdc.second = UncRange_ClusAdc -> second;
0146             }
0147         }
0148 
0149         // Division: -----------------------------------------------------------------------------------------------------------------------------
0150 
0151         if (branch_map.find("UncRange_GeoOffset") != branch_map.end()) 
0152         {
0153             if (UncRange_GeoOffset->first != UncRange_GeoOffset->first || UncRange_GeoOffset->second != UncRange_GeoOffset->second)
0154             {
0155                 std::cout<<"In file: "<<file_list[i]<<", UncRange_GeoOffset is nan"<<std::endl;
0156             }
0157 
0158             if (MinMax_GeoOffset.first > UncRange_GeoOffset -> first)
0159             {
0160                 MinMax_GeoOffset.first = UncRange_GeoOffset -> first;
0161             }
0162             if (MinMax_GeoOffset.second < UncRange_GeoOffset -> second)
0163             {
0164                 MinMax_GeoOffset.second = UncRange_GeoOffset -> second;
0165             }
0166         }
0167 
0168         // Division: -----------------------------------------------------------------------------------------------------------------------------
0169 
0170         if (branch_map.find("UncRange_DeltaPhi") != branch_map.end()) 
0171         {
0172             if (UncRange_DeltaPhi->first != UncRange_DeltaPhi->first || UncRange_DeltaPhi->second != UncRange_DeltaPhi->second)
0173             {
0174                 std::cout<<"In file: "<<file_list[i]<<", UncRange_DeltaPhi is nan"<<std::endl;
0175             }
0176 
0177             if (MinMax_DeltaPhi.first > UncRange_DeltaPhi -> first)
0178             {
0179                 MinMax_DeltaPhi.first = UncRange_DeltaPhi -> first;
0180             }
0181             if (MinMax_DeltaPhi.second < UncRange_DeltaPhi -> second)
0182             {
0183                 MinMax_DeltaPhi.second = UncRange_DeltaPhi -> second;
0184             }
0185         }
0186 
0187         // Division: -----------------------------------------------------------------------------------------------------------------------------
0188 
0189         if (branch_map.find("UncRange_ClusPhiSize") != branch_map.end()) 
0190         {
0191             if (UncRange_ClusPhiSize->first != UncRange_ClusPhiSize->first || UncRange_ClusPhiSize->second != UncRange_ClusPhiSize->second)
0192             {
0193                 std::cout<<"In file: "<<file_list[i]<<", UncRange_ClusPhiSize is nan"<<std::endl;
0194             }
0195 
0196             if (MinMax_ClusPhiSize.first > UncRange_ClusPhiSize -> first)
0197             {
0198                 MinMax_ClusPhiSize.first = UncRange_ClusPhiSize -> first;
0199             }
0200             if (MinMax_ClusPhiSize.second < UncRange_ClusPhiSize -> second)
0201             {
0202                 MinMax_ClusPhiSize.second = UncRange_ClusPhiSize -> second;
0203             }
0204         }
0205 
0206         // Division: -----------------------------------------------------------------------------------------------------------------------------
0207 
0208         if (branch_map.find("UncRange_Strangeness") != branch_map.end()) 
0209         {
0210             if (UncRange_Strangeness->first != UncRange_Strangeness->first || UncRange_Strangeness->second != UncRange_Strangeness->second)
0211             {
0212                 std::cout<<"In file: "<<file_list[i]<<", UncRange_Strangeness is nan"<<std::endl;
0213             }
0214 
0215             if (MinMax_Strangeness.first > UncRange_Strangeness -> first)
0216             {
0217                 MinMax_Strangeness.first = UncRange_Strangeness -> first;
0218             }
0219             if (MinMax_Strangeness.second < UncRange_Strangeness -> second)
0220             {
0221                 MinMax_Strangeness.second = UncRange_Strangeness -> second;
0222             }
0223         }
0224 
0225         // Division: -----------------------------------------------------------------------------------------------------------------------------
0226 
0227         if (branch_map.find("UncRange_Generator") != branch_map.end()) 
0228         {
0229             if (UncRange_Generator->first != UncRange_Generator->first || UncRange_Generator->second != UncRange_Generator->second)
0230             {
0231                 std::cout<<"In file: "<<file_list[i]<<", UncRange_Generator is nan"<<std::endl;
0232             }
0233 
0234             if (MinMax_Generator.first > UncRange_Generator -> first)
0235             {
0236                 MinMax_Generator.first = UncRange_Generator -> first;
0237             }
0238             if (MinMax_Generator.second < UncRange_Generator -> second)
0239             {
0240                 MinMax_Generator.second = UncRange_Generator -> second;
0241             }
0242         }
0243 
0244 
0245 
0246         // Division: -----------------------------------------------------------------------------------------------------------------------------
0247         
0248         if (branch_map.find("UncRange_Final") != branch_map.end()) 
0249         {
0250             if (UncRange_Final->first != UncRange_Final->first || UncRange_Final->second != UncRange_Final->second)
0251             {
0252                 std::cout<<"In file: "<<file_list[i]<<", UncRange_Final is nan"<<std::endl;
0253             }
0254 
0255             if (MinMax_Final.first > UncRange_Final -> first)
0256             {
0257                 MinMax_Final.first = UncRange_Final -> first;
0258             }
0259             if (MinMax_Final.second < UncRange_Final -> second)
0260             {
0261                 MinMax_Final.second = UncRange_Final -> second;
0262             }
0263         }
0264     }
0265 
0266     std::cout<<"========================================================================================="<<std::endl;
0267     std::cout<<Form("StatUnc,     min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_StatUnc.first, 100 * MinMax_StatUnc.second, 100 * MinMax_StatUnc.first, 100 * MinMax_StatUnc.second)<<std::endl;
0268     std::cout<<Form("RunSegment,  min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_RunSegment.first, 100 * MinMax_RunSegment.second, 100 * MinMax_RunSegment.first, 100 * MinMax_RunSegment.second)<<std::endl;
0269     std::cout<<Form("ClusAdc,     min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_ClusAdc.first, 100 * MinMax_ClusAdc.second, 100 * MinMax_ClusAdc.first, 100 * MinMax_ClusAdc.second)<<std::endl;
0270     std::cout<<Form("GeoOffset,   min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_GeoOffset.first, 100 * MinMax_GeoOffset.second, 100 * MinMax_GeoOffset.first, 100 * MinMax_GeoOffset.second)<<std::endl;
0271     std::cout<<Form("DeltaPhi,    min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_DeltaPhi.first, 100 * MinMax_DeltaPhi.second, 100 * MinMax_DeltaPhi.first, 100 * MinMax_DeltaPhi.second)<<std::endl;
0272     std::cout<<Form("ClusPhiSize, min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_ClusPhiSize.first, 100 * MinMax_ClusPhiSize.second, 100 * MinMax_ClusPhiSize.first, 100 * MinMax_ClusPhiSize.second)<<std::endl;
0273     std::cout<<Form("Strangeness, min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_Strangeness.first, 100 * MinMax_Strangeness.second, 100 * MinMax_Strangeness.first, 100 * MinMax_Strangeness.second)<<std::endl;
0274     std::cout<<Form("Generator,   min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_Generator.first, 100 * MinMax_Generator.second, 100 * MinMax_Generator.first, 100 * MinMax_Generator.second)<<std::endl;
0275     std::cout<<Form("Final,       min: %.4f%%, max: %.4f%%, [%.4f--%.4f]", 100 * MinMax_Final.first, 100 * MinMax_Final.second, 100 * MinMax_Final.first, 100 * MinMax_Final.second)<<std::endl;
0276     std::cout<<"========================================================================================="<<std::endl;
0277 
0278     return 6.6667;
0279 }