File indexing completed on 2026-07-16 08:11:28
0001 struct plotData
0002 {
0003 std::string x_vals;
0004 std::string x_err_low;
0005 std::string x_err_high;
0006
0007 std::string y_vals;
0008 std::vector<std::string> y_err_names;
0009 std::vector<std::string> y_errs_low;
0010 std::vector<std::string> y_errs_high;
0011
0012 void append_all(const std::string& s)
0013 {
0014 x_vals += s;
0015 x_err_low += s;
0016 x_err_high += s;
0017 y_vals += s;
0018 for(int i=0;i<y_err_names.size();i++)
0019 {
0020 y_errs_low[i] += s;
0021 y_errs_high[i] += s;
0022 }
0023 }
0024
0025 plotData(const std::vector<std::string> errnames)
0026 {
0027 for(const std::string& name : errnames)
0028 {
0029 y_err_names.push_back(name);
0030 y_errs_low.push_back("");
0031 y_errs_high.push_back("");
0032 }
0033
0034 append_all("{");
0035 }
0036 };
0037
0038 plotData TH1_getText(const std::string& filename, const std::string& hname)
0039 {
0040 TFile* f = TFile::Open(filename.c_str());
0041 TH1* h = (TH1*)f->Get(hname.c_str());
0042
0043 plotData pd({"y_err"});
0044
0045 const int nbins = h->GetNbinsX();
0046
0047 for(int i=1;i<=nbins;i++)
0048 {
0049 pd.x_vals += std::to_string(h->GetBinCenter(i));
0050 pd.x_err_low += std::to_string(h->GetBinCenter(i)-h->GetBinLowEdge(i));
0051 pd.x_err_high += std::to_string((h->GetBinLowEdge(i)+h->GetBinWidth(i))-h->GetBinCenter(i));
0052
0053 pd.y_vals += std::to_string(h->GetBinContent(i));
0054 pd.y_errs_low[0] += std::to_string(h->GetBinError(i));
0055 pd.y_errs_high[0] += std::to_string(h->GetBinError(i));
0056
0057 std::string separator = ", ";
0058 if(i==nbins) separator = "}";
0059
0060 pd.append_all(separator);
0061 }
0062
0063 return pd;
0064 }
0065
0066 plotData TGraphMultiErrors_StatSys_getText(const std::string& filename, const std::string& gname)
0067 {
0068 TFile* f = TFile::Open(filename.c_str());
0069 TGraphMultiErrors* g = (TGraphMultiErrors*)f->Get(gname.c_str());
0070
0071 plotData pd({"y_err_stat","y_err_sys"});
0072
0073 for(int i=0;i<g->GetN();i++)
0074 {
0075 pd.x_vals += std::to_string(g->GetPointX(i));
0076 pd.y_vals += std::to_string(g->GetPointY(i));
0077 pd.x_err_low += std::to_string(g->GetErrorXlow(i));
0078 pd.x_err_high += std::to_string(g->GetErrorXhigh(i));
0079 pd.y_errs_low[0] += std::to_string(g->GetErrorYlow(i,0));
0080 pd.y_errs_high[0] += std::to_string(g->GetErrorYhigh(i,0));
0081 pd.y_errs_low[1] += std::to_string(g->GetErrorYlow(i,1));
0082 pd.y_errs_high[1] += std::to_string(g->GetErrorYhigh(i,1));
0083
0084 std::string separator = ", ";
0085 if(i==g->GetN()-1) separator = "}";
0086
0087 pd.append_all(separator);
0088 }
0089
0090 return pd;
0091 }
0092
0093 void result_toText(const std::string& filename = "../yield_and_ratios/fits.root",
0094 const std::string& hname = "K_S0_yield_vspT")
0095 {
0096 plotData pd = TH1_getText(filename,hname);
0097 std::cout << "x_vals = " << pd.x_vals << ";" << std::endl;
0098 std::cout << "y_vals = " << pd.y_vals << ";" << std::endl;
0099 }
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115