#include "TCanvas.h" #include "TMultiGraph.h" #include "TGraphErrors.h" #include "TArrow.h" #include "TLegend.h" #include "TStyle.h" #include #include #include #include const char *data01 = "archival_tab.txt"; const char *data02 = "flare_tab.txt"; const char *dataout = "SED.png"; std::vector arrows; void multul() { gStyle->SetOptFit(0); TString XTitleTString = "#nu [Hz]"; TString YTitleTString = "#nuF_{#nu} [erg cm^{-2} s^{-1}]"; TCanvas *c01 = new TCanvas("c01", "multigraph", 1600, 900); c01->SetLogy(); c01->SetLogx(); gStyle->SetOptStat(0); auto mg = new TMultiGraph(); std::vector x1, y1, ex1, ey1; std::vector x2, y2, ex2, ey2; std::vector isUpperLimit1, isUpperLimit2; std::ifstream infile1(data01); std::string line; while (std::getline(infile1, line)) { std::istringstream iss(line); double xv, yv, exv, eyv; std::string flag; if (!(iss >> xv >> yv >> exv >> eyv)) continue; if (iss >> flag && flag == "UPPER") { eyv = 0.0; isUpperLimit1.push_back(true); } else { isUpperLimit1.push_back(false); } x1.push_back(xv); y1.push_back(yv); ex1.push_back(exv); ey1.push_back(eyv); } infile1.close(); std::ifstream infile2(data02); while (std::getline(infile2, line)) { std::istringstream iss(line); double xv, yv, exv, eyv; std::string flag; if (!(iss >> xv >> yv >> exv >> eyv)) continue; if (iss >> flag && flag == "UPPER") { eyv = 0.0; isUpperLimit2.push_back(true); } else { isUpperLimit2.push_back(false); } x2.push_back(xv); y2.push_back(yv); ex2.push_back(exv); ey2.push_back(eyv); } infile2.close(); TGraphErrors *graph1 = new TGraphErrors(x1.size(), &x1[0], &y1[0], &ex1[0], &ey1[0]); graph1->SetMarkerColor(kGray); graph1->SetLineColor(kGray); graph1->SetMarkerStyle(22); graph1->SetMarkerSize(2); graph1->SetLineWidth(2); mg->Add(graph1); TGraphErrors *graph2 = new TGraphErrors(x2.size(), &x2[0], &y2[0], &ex2[0], &ey2[0]); graph2->SetMarkerColor(kGreen); graph2->SetLineColor(kGreen); graph2->SetMarkerStyle(29); graph2->SetMarkerSize(2); graph2->SetLineWidth(2); mg->Add(graph2); mg->GetXaxis()->SetTitle(XTitleTString); mg->GetYaxis()->SetTitle(YTitleTString); mg->GetXaxis()->SetLimits(1.e6, 1.e26); mg->Draw("AP"); for (size_t i = 0; i < x1.size(); i++) { if (isUpperLimit1[i]) { double yl = TMath::Power(10, TMath::Log10(y1[i]) - 0.5); TArrow *arrow = new TArrow(x1[i], y1[i], x1[i], yl, 0.01, "|>"); arrow->SetLineColor(kGray); arrow->SetFillColor(kGray); std::cout << "ARCHIVAL Upper limit at: x = " << x1[i] << ", y = " << y1[i] << std::endl; arrow->Draw(); arrows.push_back(arrow); } } for (size_t i = 0; i < x2.size(); i++) { if (isUpperLimit2[i]) { double yl = TMath::Power(10, TMath::Log10(y2[i]) - 0.5); TArrow *arrow = new TArrow(x2[i], y2[i], x2[i], yl, 0.01, "|>"); arrow->SetLineColor(kGreen); arrow->SetFillColor(kGreen); std::cout << "FLARE Upper limit at: x = " << x2[i] << ", y = " << y2[i] << std::endl; arrow->Draw(); arrows.push_back(arrow); } } TLegend *leg = new TLegend(0.15, 0.73, .35, .85); leg->AddEntry(graph1, "Archival", "ap"); leg->AddEntry(graph2, "Flare", "ap"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->Draw(); c01->Update(); c01->Modified(); c01->Print(dataout); }