Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:11:28

0001 #ifndef KSHORT_SCALEWIDTHDIFFERENTIAL_C
0002 #define KSHORT_SCALEWIDTHDIFFERENTIAL_C
0003 
0004 #include <algorithm>
0005 #include <cctype>
0006 #include <cstdint>
0007 #include <format>
0008 #include <functional>
0009 #include <iomanip>
0010 #include <iostream>
0011 #include <regex>
0012 #include <sstream>
0013 #include <string>
0014 #include <vector>
0015 
0016 #include <TCut.h>
0017 #include <TSystem.h>
0018 
0019 #include "./RDataframeToRoofit.C"
0020 #include "./RDataframeToRoofit_SOnly.C"
0021 #include "./fitutil.h"
0022 
0023 namespace
0024 {
0025 inline void replace_all(std::string &s, const std::string &from, const std::string &to)
0026 {
0027     if (from.empty())
0028         return;
0029     size_t pos = 0;
0030     while ((pos = s.find(from, pos)) != std::string::npos)
0031     {
0032         s.replace(pos, from.size(), to);
0033         pos += to.size();
0034     }
0035 }
0036 
0037 inline std::string to_hex_u64(std::uint64_t v)
0038 {
0039     std::ostringstream oss;
0040     oss << std::hex << std::setw(16) << std::setfill('0') << v;
0041     return oss.str();
0042 }
0043 
0044 inline std::string shorten_tag_if_needed(const std::string &tag, std::size_t maxlen = 180)
0045 {
0046     if (tag.size() <= maxlen)
0047         return tag;
0048 
0049     const std::uint64_t h = static_cast<std::uint64_t>(std::hash<std::string>{}(tag));
0050     const std::string suffix = "_h" + to_hex_u64(h);
0051 
0052     const std::size_t keep = (maxlen > suffix.size()) ? (maxlen - suffix.size()) : 0;
0053     return tag.substr(0, keep) + suffix;
0054 }
0055 
0056 inline std::string trim_number(const std::string &text)
0057 {
0058     std::ostringstream oss;
0059     oss << std::fixed << std::setprecision(6) << std::stod(text);
0060 
0061     std::string out = oss.str();
0062     while (out.size() > 1 && out.back() == '0')
0063         out.pop_back();
0064     if (!out.empty() && out.back() == '.')
0065         out.push_back('0');
0066     return out;
0067 }
0068 
0069 struct CutRangeText
0070 {
0071     bool has_low = false;
0072     bool has_high = false;
0073     std::string low;
0074     std::string high;
0075     std::string low_bracket = "[";
0076     std::string high_bracket = ")";
0077 };
0078 
0079 inline CutRangeText parse_cut_range(const std::string &cut_string, const std::string &variable)
0080 {
0081     CutRangeText range;
0082     const std::regex re(variable + R"(\s*(>=|<=|==|>|<)\s*([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))");
0083 
0084     for (std::sregex_iterator it(cut_string.begin(), cut_string.end(), re), end; it != end; ++it)
0085     {
0086         const std::string op = (*it)[1].str();
0087         const std::string value = trim_number((*it)[2].str());
0088 
0089         if (op == ">=" || op == ">")
0090         {
0091             range.has_low = true;
0092             range.low = value;
0093             range.low_bracket = (op == ">=") ? "[" : "(";
0094         }
0095         else if (op == "<=" || op == "<")
0096         {
0097             range.has_high = true;
0098             range.high = value;
0099             range.high_bracket = (op == "<=") ? "]" : ")";
0100         }
0101         else if (op == "==")
0102         {
0103             range.has_low = true;
0104             range.has_high = true;
0105             range.low = value;
0106             range.high = value;
0107             range.low_bracket = "[";
0108             range.high_bracket = "]";
0109         }
0110     }
0111 
0112     return range;
0113 }
0114 
0115 inline void add_range_text(std::vector<std::string> &entries, const CutRangeText &range, const std::string &label, const std::string &separator, const std::string &unit)
0116 {
0117     if (range.has_low && range.has_high)
0118     {
0119         entries.push_back(label + " = " + range.low_bracket + range.low + separator + range.high + range.high_bracket + unit);
0120     }
0121     else if (range.has_low)
0122     {
0123         entries.push_back(label + " #geq " + range.low + unit);
0124     }
0125     else if (range.has_high)
0126     {
0127         entries.push_back(label + " < " + range.high + unit);
0128     }
0129 }
0130 
0131 inline std::vector<std::string> make_cut_legend_entries(const std::string &cut_string)
0132 {
0133     std::vector<std::string> entries;
0134 
0135     add_range_text(entries, parse_cut_range(cut_string, "Lambda0_pT"), "p_{T}", "-", " GeV");
0136     add_range_text(entries, parse_cut_range(cut_string, "Lambda0_pseudorapidity"), "#eta", ", ", "");
0137     add_range_text(entries, parse_cut_range(cut_string, "Lambda0_phi"), "#phi", ", ", " rad");
0138 
0139     const std::regex min_track_pt_re(R"(min\s*\(\s*track_1_pT\s*,\s*track_2_pT\s*\)\s*(>=|<=|==|>|<)\s*([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))");
0140     std::smatch min_track_pt_match;
0141     if (std::regex_search(cut_string, min_track_pt_match, min_track_pt_re))
0142     {
0143         const std::string op = min_track_pt_match[1].str();
0144         const std::string value = trim_number(min_track_pt_match[2].str());
0145         if (op == ">=")
0146             entries.push_back("min track p_{T} " + value + " GeV");
0147         else
0148             entries.push_back("min track p_{T} " + op + " " + value + " GeV");
0149     }
0150 
0151     return entries;
0152 }
0153 } // namespace
0154 
0155 std::string modify(std::string str)
0156 {
0157     replace_all(str, ">=", "geq");
0158     replace_all(str, "<=", "leq");
0159     replace_all(str, "==", "eq");
0160     replace_all(str, "&&", "AND");
0161     replace_all(str, "||", "OR");
0162     replace_all(str, ">", "gt");
0163     replace_all(str, "<", "lt");
0164 
0165     std::replace(str.begin(), str.end(), '.', 'p'); // decimal point
0166     std::replace(str.begin(), str.end(), '-', 'm'); // minus sign (negative numbers)
0167     std::replace(str.begin(), str.end(), '+', 'p'); // plus sign
0168 
0169     for (char &c : str)
0170     {
0171         const bool ok = (std::isalnum(static_cast<unsigned char>(c)) != 0) || (c == '_');
0172         if (!ok)
0173             c = '_';
0174     }
0175 
0176     std::string out;
0177     out.reserve(str.size());
0178     bool prev_us = false;
0179     for (char c : str)
0180     {
0181         if (c == '_')
0182         {
0183             if (!prev_us)
0184                 out.push_back(c);
0185             prev_us = true;
0186         }
0187         else
0188         {
0189             out.push_back(c);
0190             prev_us = false;
0191         }
0192     }
0193 
0194     // Trim leading/trailing underscores
0195     while (!out.empty() && out.front() == '_')
0196         out.erase(out.begin());
0197     while (!out.empty() && out.back() == '_')
0198         out.pop_back();
0199 
0200     return out;
0201 }
0202 
0203 void configure_fitparam(const std::string cutstring, fitparam_config &fit_conf)
0204 {
0205     if (cutstring == "Lambda0_pT>=0.50&&Lambda0_pT<0.60")
0206     {
0207         fit_conf.minMass = 1.113;
0208         fit_conf.maxMass = 1.15;
0209         fit_conf.nBins = 37; // ~5 MeV bins
0210 
0211         fit_conf.sigmodel = "Gaussian";
0212         fit_conf.mean = 1.1160e+00;
0213         fit_conf.mean_low = 1.113;
0214         fit_conf.mean_high = 1.125;
0215 
0216         fit_conf.sigma = 2.7158e-03;
0217         fit_conf.sigma_low = 1e-4;
0218         fit_conf.sigma_high = 0.005;
0219 
0220         fit_conf.bkgmodel = "Polynomial3";
0221         fit_conf.p1 = -8.5720e+00;
0222         fit_conf.p1_low = -10.;
0223         fit_conf.p1_high = 10.;
0224 
0225         fit_conf.p2 = 1.4117e+00;
0226         fit_conf.p2_low = -10.;
0227         fit_conf.p2_high = 10.;
0228 
0229         fit_conf.p3 = 4.9278e+00;
0230         fit_conf.p3_low = -10.;
0231         fit_conf.p3_high = 10.;
0232 
0233         fit_conf.nSig = 1.3395e+03;  // if > 0, will be used as fixed starting value
0234         fit_conf.nSig_low = 1300.0;  // if > 0, will be used as fixed starting value
0235         fit_conf.nBkg_high = 1500.0; // if > 0, will be used as fixed starting value
0236         fit_conf.nBkg = 0.0;
0237     }
0238     else if (cutstring == "Lambda0_pT>=0.60&&Lambda0_pT<0.70")
0239     {
0240         fit_conf.minMass = 1.105;
0241         fit_conf.maxMass = 1.15;
0242         fit_conf.nBins = 45; // ~5 MeV bins
0243 
0244         fit_conf.sigmodel = "Gaussian";
0245         fit_conf.mean = 1.1160e+00;
0246         fit_conf.mean_low = 1.113;
0247         fit_conf.mean_high = 1.125;
0248 
0249         fit_conf.sigma = 2.7158e-03;
0250         fit_conf.sigma_low = 1e-4;
0251         fit_conf.sigma_high = 0.005;
0252 
0253         fit_conf.bkgmodel = "Polynomial3";
0254         fit_conf.p1 = -8.5720e+00;
0255         fit_conf.p1_low = -10.;
0256         fit_conf.p1_high = 10.;
0257 
0258         fit_conf.p2 = 1.4117e+00;
0259         fit_conf.p2_low = -10.;
0260         fit_conf.p2_high = 10.;
0261 
0262         fit_conf.p3 = 4.9278e+00;
0263         fit_conf.p3_low = -10.;
0264         fit_conf.p3_high = 10.;
0265 
0266         fit_conf.nSig = 0;          // if > 0, will be used as fixed starting value
0267         fit_conf.nSig_low = 1300.0; // if > 0, will be used as fixed starting value
0268         fit_conf.nBkg_high = 0;     // if > 0, will be used as fixed starting value
0269         fit_conf.nBkg = 0.0;
0270     }
0271     else if (cutstring.find("Lambda0_pT>=0.70&&Lambda0_pT<0.80") != std::string::npos)
0272     {
0273         fit_conf.minMass = 1.1;
0274         fit_conf.maxMass = 1.15;
0275         fit_conf.nBins = 50; // ~5 MeV bins
0276 
0277         fit_conf.sigmodel = "Gaussian";
0278         fit_conf.mean = 1.1160e+00;
0279         fit_conf.mean_low = 1.113;
0280         fit_conf.mean_high = 1.125;
0281 
0282         fit_conf.sigma = 2.7158e-03;
0283         fit_conf.sigma_low = 1e-4;
0284         fit_conf.sigma_high = 0.01;
0285 
0286         if (cutstring.find("Lambda0_phi>=2.00&&Lambda0_phi<3.15") != std::string::npos)
0287         {
0288             fit_conf.mean = 1.1130e+00;
0289             fit_conf.mean_low = 1.11;
0290             fit_conf.mean_high = 1.115;
0291 
0292             fit_conf.sigma = 2.87e-03;
0293             fit_conf.sigma_low = 1.5e-3;
0294             fit_conf.sigma_high = 3.0e-3;
0295         }
0296         else if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0297         {
0298             fit_conf.mean = 1.1140e+00;
0299             fit_conf.mean_low = 1.11;
0300             fit_conf.mean_high = 1.115;
0301 
0302             fit_conf.sigma = 3e-03;
0303             fit_conf.sigma_low = 1.5e-3;
0304             fit_conf.sigma_high = 3.0e-3;
0305         }
0306 
0307         fit_conf.bkgmodel = "Polynomial3";
0308         fit_conf.p1 = -8.5720e+00;
0309         fit_conf.p1_low = -10.;
0310         fit_conf.p1_high = 10.;
0311 
0312         fit_conf.p2 = 1.4117e+00;
0313         fit_conf.p2_low = -10.;
0314         fit_conf.p2_high = 10.;
0315 
0316         fit_conf.p3 = 4.9278e+00;
0317         if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0318         {
0319             fit_conf.p3 = 0;
0320         }
0321         fit_conf.p3_low = -10.;
0322         fit_conf.p3_high = 10.;
0323 
0324         fit_conf.nSig = 0;          // if > 0, will be used as fixed starting value
0325         fit_conf.nSig_low = 1300.0; // if > 0, will be used as fixed starting value
0326         fit_conf.nBkg_high = 0;     // if > 0, will be used as fixed starting value
0327         fit_conf.nBkg = 0.0;
0328         if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0329         {
0330             fit_conf.nSig = 4500;       // if > 0, will be used as fixed starting value
0331             fit_conf.nSig_low = 1300.0; // if > 0, will be used as fixed starting value
0332             fit_conf.nBkg_high = 0;     // if > 0, will be used as fixed starting value
0333             fit_conf.nBkg = 0.0;
0334         }
0335     }
0336     else if (cutstring.find("Lambda0_pT>=0.80&&Lambda0_pT<0.90") != std::string::npos)
0337     {
0338         fit_conf.minMass = 1.095;
0339         fit_conf.maxMass = 1.14;
0340         fit_conf.nBins = 45; // ~5 MeV bins
0341 
0342         fit_conf.sigmodel = "Gaussian";
0343         fit_conf.mean = 1.1160e+00;
0344         fit_conf.mean_low = 1.113;
0345         fit_conf.mean_high = 1.125;
0346         if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0347         {
0348             fit_conf.mean = 1.1160e+00;
0349             fit_conf.mean_low = 1.113;
0350             fit_conf.mean_high = 1.12;
0351         }
0352 
0353         fit_conf.sigma = 2.7158e-03;
0354         fit_conf.sigma_low = 1e-4;
0355         fit_conf.sigma_high = 0.01;
0356         if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0357         {
0358             fit_conf.sigma = 2.7158e-03;
0359             fit_conf.sigma_low = 1e-4;
0360             fit_conf.sigma_high = 0.005;
0361         }
0362         else if (cutstring.find("Lambda0_phi>=1.00&&Lambda0_phi<2.00") != std::string::npos)
0363         {
0364             fit_conf.sigma = 2.5e-03;
0365             fit_conf.sigma_low = 0.002;
0366             fit_conf.sigma_high = 5e-3;
0367         }
0368         else if (cutstring.find("Lambda0_phi>=2.00&&Lambda0_phi<3.15") != std::string::npos)
0369         {
0370             fit_conf.sigma = 2.5e-03;
0371             fit_conf.sigma_low = 0.002;
0372             fit_conf.sigma_high = 5e-3;
0373         }
0374 
0375         fit_conf.bkgmodel = "Polynomial3";
0376         fit_conf.p1 = -8.5720e+00;
0377         fit_conf.p1_low = -10.;
0378         fit_conf.p1_high = 10.;
0379 
0380         fit_conf.p2 = 1.4117e+00;
0381         fit_conf.p2_low = -10.;
0382         fit_conf.p2_high = 10.;
0383 
0384         fit_conf.p3 = 4.9278e+00;
0385         fit_conf.p3_low = -10.;
0386         fit_conf.p3_high = 10.;
0387 
0388         fit_conf.nSig = 0;          // if > 0, will be used as fixed starting value
0389         fit_conf.nSig_low = 1300.0; // if > 0, will be used as fixed starting value
0390         fit_conf.nBkg_high = 0;     // if > 0, will be used as fixed starting value
0391         fit_conf.nBkg = 0.0;
0392     }
0393     else if (cutstring.find("Lambda0_pT>=0.90&&Lambda0_pT<1.00") != std::string::npos)
0394     {
0395         std::cout << "Using custom fit config for Lambda0_pT>=0.90&&Lambda0_pT<1.00" << std::endl;
0396         fit_conf.minMass = 1.095;
0397         fit_conf.maxMass = 1.14;
0398         fit_conf.nBins = 45; // ~5 MeV bins
0399 
0400         fit_conf.sigmodel = "Gaussian";
0401         fit_conf.mean = 1.1180e+00;
0402         fit_conf.mean_low = 1.113;
0403         fit_conf.mean_high = 1.123;
0404 
0405         fit_conf.sigma = 2.61e-03;
0406         fit_conf.sigma_low = 1e-4;
0407         fit_conf.sigma_high = 5.0e-03;
0408         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0409         {
0410             fit_conf.mean = 1.1150e+00;
0411             fit_conf.mean_low = 1.11;
0412             fit_conf.mean_high = 1.118;
0413 
0414             fit_conf.sigma = 2.5e-03;
0415             fit_conf.sigma_low = 0.002;
0416             fit_conf.sigma_high = 0.01;
0417         }
0418         else if (cutstring.find("Lambda0_phi>=2.00&&Lambda0_phi<3.15") != std::string::npos)
0419         {
0420             fit_conf.mean = 1.1180e+00;
0421             fit_conf.mean_low = 1.113;
0422             fit_conf.mean_high = 1.123;
0423 
0424             fit_conf.sigma = 2.5e-03;
0425             fit_conf.sigma_low = 0.002;
0426             fit_conf.sigma_high = 0.01;
0427         }
0428         else if (cutstring.find("Lambda0_phi>=-2.00&&Lambda0_phi<-1.00") != std::string::npos)
0429         {
0430             fit_conf.mean = 1.1160e+00;
0431             fit_conf.mean_low = 1.113;
0432             fit_conf.mean_high = 1.12;
0433 
0434             fit_conf.sigma = 2.7158e-03;
0435             fit_conf.sigma_low = 1e-4;
0436             fit_conf.sigma_high = 4.5e-3;
0437         }
0438 
0439         fit_conf.bkgmodel = "Polynomial3";
0440         fit_conf.p1 = -8.5720e+00;
0441         fit_conf.p1_low = -10.;
0442         fit_conf.p1_high = 10.;
0443 
0444         fit_conf.p2 = 1.4117e+00;
0445         fit_conf.p2_low = -10.;
0446         fit_conf.p2_high = 10.;
0447 
0448         fit_conf.p3 = 4.9278e+00;
0449         fit_conf.p3_low = -10.;
0450         fit_conf.p3_high = 10.;
0451 
0452         fit_conf.nSig = 0;          // if > 0, will be used as fixed starting value
0453         fit_conf.nSig_low = 1300.0; // if > 0, will be used as fixed starting value
0454         fit_conf.nBkg_high = 0;     // if > 0, will be used as fixed starting value
0455         fit_conf.nBkg = 0.0;
0456     }
0457     else if (cutstring.find("Lambda0_pT>=1.00&&Lambda0_pT<1.10") != std::string::npos)
0458     {
0459         fit_conf.minMass = 1.09;
0460         fit_conf.maxMass = 1.14;
0461         fit_conf.nBins = 50; // ~5 MeV bins
0462 
0463         fit_conf.sigmodel = "Gaussian";
0464         fit_conf.mean = 1.1160e+00;
0465         fit_conf.mean_low = 1.113;
0466         fit_conf.mean_high = 1.125;
0467         fit_conf.sigma = 2.7158e-03;
0468         fit_conf.sigma_low = 1e-4;
0469         fit_conf.sigma_high = 0.005;
0470         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0471         {
0472             fit_conf.mean = 1.1130e+00;
0473             fit_conf.mean_low = 1.11;
0474             fit_conf.mean_high = 1.115;
0475 
0476             fit_conf.sigma = 2.87e-03;
0477             fit_conf.sigma_low = 0.0023;
0478             fit_conf.sigma_high = 0.003;
0479         }
0480 
0481         fit_conf.bkgmodel = "Polynomial3";
0482         fit_conf.p1 = -8.5720e+00;
0483         fit_conf.p1_low = -10.;
0484         fit_conf.p1_high = 10.;
0485 
0486         fit_conf.p2 = 1.4117e+00;
0487         fit_conf.p2_low = -10.;
0488         fit_conf.p2_high = 10.;
0489 
0490         fit_conf.p3 = 4.9278e+00;
0491         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0492         {
0493             fit_conf.p3 = 0;
0494         }
0495         fit_conf.p3_low = -10.;
0496         fit_conf.p3_high = 10.;
0497 
0498         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0499         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0500         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0501         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0502         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0503         {
0504             fit_conf.nSig = 8500.0;     // if > 0, will be used as fixed starting value
0505             fit_conf.nSig_low = 3000.0; // if > 0, will be used as fixed starting value
0506         }
0507     }
0508     else if (cutstring.find("Lambda0_pT>=1.10&&Lambda0_pT<1.20&&Lambda0_phi>=0.00&&Lambda0_phi<1.00") != std::string::npos)
0509     {
0510         fit_conf.minMass = 1.09;
0511         fit_conf.maxMass = 1.14;
0512         fit_conf.nBins = 50; // ~5 MeV bins
0513 
0514         fit_conf.sigmodel = "Gaussian";
0515         fit_conf.mean = 1.1160e+00;
0516         fit_conf.mean_low = 1.113;
0517         fit_conf.mean_high = 1.125;
0518         fit_conf.sigma = 2.7158e-03;
0519         fit_conf.sigma_low = 1e-4;
0520         fit_conf.sigma_high = 0.005;
0521 
0522         fit_conf.bkgmodel = "Polynomial3";
0523         fit_conf.p1 = -8.5720e+00;
0524         fit_conf.p1_low = -10.;
0525         fit_conf.p1_high = 10.;
0526 
0527         fit_conf.p2 = 1.4117e+00;
0528         fit_conf.p2_low = -10.;
0529         fit_conf.p2_high = 10.;
0530 
0531         fit_conf.p3 = 0;
0532         fit_conf.p3_low = -10.;
0533         fit_conf.p3_high = 10.;
0534 
0535         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0536         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0537         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0538         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0539     }
0540     else if (cutstring.find("Lambda0_pT>=1.20&&Lambda0_pT<1.30") != std::string::npos)
0541     {
0542         fit_conf.minMass = 1.09;
0543         fit_conf.maxMass = 1.14;
0544         fit_conf.nBins = 50; // ~5 MeV bins
0545 
0546         fit_conf.sigmodel = "Gaussian";
0547         fit_conf.mean = 1.1160e+00;
0548         fit_conf.mean_low = 1.113;
0549         fit_conf.mean_high = 1.125;
0550         fit_conf.sigma = 2.7158e-03;
0551         fit_conf.sigma_low = 1e-4;
0552         fit_conf.sigma_high = 0.005;
0553         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0554         {
0555             fit_conf.mean = 1.1130e+00;
0556             fit_conf.mean_low = 1.112;
0557             fit_conf.mean_high = 1.115;
0558 
0559             fit_conf.sigma = 2.87e-03;
0560             fit_conf.sigma_low = 0.0023;
0561             fit_conf.sigma_high = 5e-3;
0562         }
0563 
0564         fit_conf.bkgmodel = "Polynomial3";
0565         fit_conf.p1 = -8.5720e+00;
0566         fit_conf.p1_low = -10.;
0567         fit_conf.p1_high = 10.;
0568 
0569         fit_conf.p2 = 1.4117e+00;
0570         fit_conf.p2_low = -10.;
0571         fit_conf.p2_high = 10.;
0572 
0573         fit_conf.p3 = 4.9278e+00;
0574         fit_conf.p3_low = -10.;
0575         fit_conf.p3_high = 10.;
0576 
0577         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0578         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0579         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0580         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0581         if (cutstring.find("Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0582         {
0583             fit_conf.nSig = 3500.0;         // if > 0, will be used as fixed starting value
0584             fit_conf.nSig_low = 3000.0;     // if > 0, will be used as fixed starting value
0585             fit_conf.nBkg = 2e+03;          // if > 0, will be used as fixed starting value
0586             fit_conf.nBkg_low = 1.3967e+03; // if > 0,
0587         }
0588     }
0589     else if (cutstring.find("Lambda0_pT>=1.30&&Lambda0_pT<1.40&&Lambda0_phi>=-1.00&&Lambda0_phi<0.00") != std::string::npos)
0590     {
0591         fit_conf.minMass = 1.09;
0592         fit_conf.maxMass = 1.14;
0593         fit_conf.nBins = 50; // ~5 MeV bins
0594 
0595         fit_conf.sigmodel = "Gaussian";
0596         fit_conf.mean = 1.1160e+00;
0597         fit_conf.mean_low = 1.113;
0598         fit_conf.mean_high = 1.125;
0599         fit_conf.sigma = 2.7158e-03;
0600         fit_conf.sigma_low = 1e-4;
0601         fit_conf.sigma_high = 0.005;
0602 
0603         fit_conf.bkgmodel = "Polynomial3";
0604         fit_conf.p1 = -8.5720e+00;
0605         fit_conf.p1_low = -10.;
0606         fit_conf.p1_high = 10.;
0607 
0608         fit_conf.p2 = 1.4117e+00;
0609         fit_conf.p2_low = -10.;
0610         fit_conf.p2_high = 10.;
0611 
0612         fit_conf.p3 = 4.9278e+00;
0613         fit_conf.p3_low = -10.;
0614         fit_conf.p3_high = 10.;
0615 
0616         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0617         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0618         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0619         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0620     }
0621     else if (cutstring.find("Lambda0_pT>=1.50&&Lambda0_pT<1.80") != std::string::npos)
0622     {
0623         fit_conf.minMass = 1.09;
0624         fit_conf.maxMass = 1.14;
0625         fit_conf.nBins = 50;
0626 
0627         fit_conf.sigmodel = "Gaussian";
0628         fit_conf.mean = 1.1160e+00;
0629         fit_conf.mean_low = 1.113;
0630         fit_conf.mean_high = 1.125;
0631         fit_conf.sigma = 2.7158e-03;
0632         fit_conf.sigma_low = 1e-4;
0633         fit_conf.sigma_high = 0.005;
0634         if (cutstring.find("Lambda0_phi>=-3.15&&Lambda0_phi<-2.00") != std::string::npos)
0635         {
0636             fit_conf.mean = 1.1130e+00;
0637             fit_conf.mean_low = 1.11;
0638             fit_conf.mean_high = 1.115;
0639 
0640             fit_conf.sigma = 2.2e-03;
0641             fit_conf.sigma_low = 0.002;
0642             fit_conf.sigma_high = 0.0023;
0643         }
0644         else if (cutstring.find("Lambda0_phi>=2.00&&Lambda0_phi<3.15") != std::string::npos)
0645         {
0646             fit_conf.mean = 1.1130e+00;
0647             fit_conf.mean_low = 1.11;
0648             fit_conf.mean_high = 1.115;
0649 
0650             fit_conf.sigma = 2.87e-03;
0651             fit_conf.sigma_low = 0.0023;
0652             fit_conf.sigma_high = 5e-3;
0653         }
0654 
0655         fit_conf.bkgmodel = "Polynomial3";
0656         fit_conf.p1 = -8.5720e+00;
0657         fit_conf.p1_low = -10.;
0658         fit_conf.p1_high = 10.;
0659 
0660         fit_conf.p2 = 1.4117e+00;
0661         fit_conf.p2_low = -10.;
0662         fit_conf.p2_high = 10.;
0663 
0664         fit_conf.p3 = 4.9278e+00;
0665         fit_conf.p3_low = -10.;
0666         fit_conf.p3_high = 10.;
0667 
0668         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0669         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0670         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0671         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0672     }
0673     else
0674     {
0675         fit_conf.minMass = 1.09;
0676         fit_conf.maxMass = 1.14;
0677         fit_conf.nBins = 50;
0678 
0679         fit_conf.sigmodel = "Gaussian";
0680         fit_conf.mean = 1.1160e+00;
0681         fit_conf.mean_low = 1.113;
0682         fit_conf.mean_high = 1.125;
0683         fit_conf.sigma = 2.7158e-03;
0684         fit_conf.sigma_low = 1e-4;
0685         fit_conf.sigma_high = 0.08;
0686 
0687         fit_conf.bkgmodel = "Polynomial3";
0688         fit_conf.p1 = -8.5720e+00;
0689         fit_conf.p1_low = -10.;
0690         fit_conf.p1_high = 10.;
0691 
0692         fit_conf.p2 = 1.4117e+00;
0693         fit_conf.p2_low = -10.;
0694         fit_conf.p2_high = 10.;
0695 
0696         fit_conf.p3 = 4.9278e+00;
0697         fit_conf.p3_low = -10.;
0698         fit_conf.p3_high = 10.;
0699 
0700         fit_conf.nSig = 0.0;     // if > 0, will be used as fixed starting value
0701         fit_conf.nSig_low = 0.0; // if > 0, will be used as fixed starting value
0702         fit_conf.nBkg = 0.0;     // if > 0, will be used as fixed starting value
0703         fit_conf.nBkg_low = 0.0; // if > 0, will be used as fixed starting value
0704     }
0705 }
0706 
0707 // void Lambda0_ScaleWidthDifferential(                                                                                                                  //
0708 //     std::string additionalCuts = "Lambda0_pT>=0.50&&Lambda0_pT<0.60&&Lambda0_pseudorapidity>=0.00&&Lambda0_pseudorapidity<0.50&&Lambda0_phi>=1.00&&Lambda0_phi<2.00" //
0709 // )
0710 void Lambda0_ScaleWidthDifferential(                                                                      //
0711     std::string additionalCuts = "Lambda0_pT>=1.10&&Lambda0_pT<1.20&&Lambda0_phi>=0.00&&Lambda0_phi<1.00" //
0712 )
0713 {
0714     const std::string figure_dir = "./figure_lambda_crosscheck/";
0715     system(("mkdir -p " + figure_dir).c_str());
0716 
0717     const bool isMC = false;
0718 
0719     // TCut KS0_optimizeCut = "K_S0_DIRA >= 0.985000 && K_S0_decayLength > 0.125000 && min(abs(track_1_IP_xy), abs(track_2_IP_xy)) >= 0.020000";
0720     const TCut KS0_optimizeCut = "min(track_1_pT, track_2_pT) >= 0.2";
0721     const TCut KSO_additionalCuts(additionalCuts.c_str());
0722     const std::vector<std::string> cut_legend_entries = make_cut_legend_entries(additionalCuts + "&&" + KS0_optimizeCut.GetTitle());
0723 
0724     const TCut totalselection = KS0_optimizeCut && KSO_additionalCuts;
0725     std::cout << "Selection: " << totalselection.GetTitle() << std::endl;
0726 
0727     std::string plotdir_prefix = modify(additionalCuts);
0728     plotdir_prefix = shorten_tag_if_needed(plotdir_prefix);
0729     std::cout << "Plotdir prefix: " << plotdir_prefix << std::endl;
0730 
0731     const std::string plotdir = figure_dir + "/" + plotdir_prefix;
0732     system(("mkdir -p " + plotdir).c_str());
0733 
0734     // Fit configuration defaults
0735     fitparam_config fitconfig;
0736     fitconfig.branch = "Lambda0_mass";
0737     fitconfig.decaystring = "#Lambda^{0}#rightarrow p#pi^{-} + (c.c.)";
0738 
0739     // Signal model
0740     // fitconfig.sigmodel = "DoubleCrystalBall";
0741     fitconfig.sigmodel = "Gaussian";
0742 
0743     configure_fitparam(additionalCuts, fitconfig);
0744 
0745     if (!isMC)
0746     {
0747         const bool doSnapshot = true;
0748         const std::string snapshotName = std::format("./snapshot/filtered_tree_{}.root", plotdir_prefix);
0749         const std::string inputFile = "/sphenix/tg/tg01/hf/aopatton/SVLooseJun4/6RunsCombinedLambdaSVLoose.root";
0750 
0751         const double significance = RDataframeToRoofit(doSnapshot, snapshotName, inputFile, totalselection, fitconfig, plotdir, cut_legend_entries);
0752 
0753         std::cout << "Returned significance: " << significance << std::endl;
0754     }
0755     else
0756     {
0757         const bool doSnapshot = false;
0758         const std::string snapshotName = "./snapshot/filtered_tree.root";
0759         const std::string inputFile = "/sphenix/user/hjheng/sPHENIXRepo/TrackingAnalysis/Physics_Val_TF/misc/KFParticle_merged/merged_pipi_reco_00079516.root";
0760 
0761         RDataframeToRoofit_SOnly(doSnapshot, snapshotName, inputFile, totalselection, fitconfig, plotdir);
0762     }
0763 }
0764 
0765 #endif // KSHORT_SCALEWIDTHDIFFERENTIAL_C