#include #include #include #include #include #include #include #include using namespace std; TGraph *createGraph(const vector &x, const vector &y, const string &name) { static const vector colors = { kRed, kBlue, kMagenta, kGreen, kAzure, kYellow }; static auto colorIdx = 0; auto g = new TGraph(x.size(), x.data(), y.data()); g->SetTitle(name.c_str()); g->SetLineColor(colors[colorIdx]); g->SetMarkerColor(colors[colorIdx]); g->SetFillColor(kWhite); g->SetLineWidth(2); colorIdx = (1 + colorIdx) % colors.size(); return g; } vector file2graphlist(const string &filename) { ifstream is(filename); vector result; vector dataX; vector dataY; string line; string name("unnamed"); while (getline(is, line)) { if (boost::starts_with(line, "**")) { if (!dataX.empty()) { result.push_back(createGraph(dataX, dataY, name)); dataX.clear(); dataY.clear(); } continue; } if (boost::starts_with(line, "*")) { auto pos = line.find("NAME="); if (pos != string::npos) name = &line[pos + 5]; continue; } auto pos = line.find(", "); if (pos != string::npos) { line[pos] = 0; double x = atof(line.data()); double y = atof(&line[pos + 2]); dataX.push_back(x); dataY.push_back(y); } } if (!dataX.empty()) result.push_back(createGraph(dataX, dataY, name)); return result; } void koer() { auto graphs = file2graphlist("koer.dat"); auto c = new TCanvas; auto leg = new TLegend(0.7, 0.9, 0.9, 1.0); for (auto g:graphs) { g->Draw(); c->Update(); leg->AddEntry(g, g->GetTitle()); } leg->Draw(); for (auto g:graphs) { new TCanvas; g->Draw(); } }