#include "TCanvas.h" #include "TPad.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TAxis.h" #include "TLegend.h" #include "TLatex.h" #include "TROOT.h" #include // for "exit" //const char *labelsgamma[] = {"30.53 GeV", "69.34 GeV", "138.70 GeV", "260.98 GeV", "453.25 GeV", "765.59 GeV"}; void drawlabels(TGraph *g = 0, const char *labels[] = 0) { if ((!g) || (!labels) || (!gPad)) return; // just a precaution for (Int_t i = 0; i < g->GetN(); i++) { Double_t x, y; g->GetPoint(i, x, y); if (gPad->GetLogx()) x *= 1.25; else x+= 0.0; if (gPad->GetLogy()) y *= 1.25; else y+= 0.0; TLatex *l = new TLatex(x, y, labels[i]); l->SetTextSize(0.025); l->SetTextFont(42); l->SetTextAlign(21); l->SetTextColor(g->GetMarkerColor()); l->Draw(); } } void corona() { #if 1 /* 0 or 1 */ const char *datagamma = "C:/corona.txt"; const char *dataout = "C:/root_v6.18.04/corona.pdf"; #else /* 0 or 1 */ const char *datagamma = "corona.txt"; const char *dataout = "corona.pdf"; #endif /* 0 or 1 */ TCanvas *c36 = new TCanvas("c36","multigraph",1280,1024); //c36->SetLogx(); //c36->SetLogy(); float offx=1.3; float offy=1.7; float margr=0.08; float w=3; float margl=0.12; gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); TMultiGraph *mg = new TMultiGraph(); TGraphErrors *gamma = new TGraphErrors(datagamma,"%lg %lg"); gamma->SetMarkerColor(kBlue); gamma->SetLineColor(kBlue); gamma->SetMarkerStyle(23); TF1 *fitspettro = new TF1("fitspettro", "[0] * (1+[1]*TMath::Exp(-x/[2]))/(1+[3]*TMath::Exp(-x/[2]))", 0,15); fitspettro->SetParName(0,"a"); fitspettro->SetParName(1,"m"); fitspettro->SetParName(2,"\tau"); fitspettro->SetParName(3,"n"); fitspettro->SetParameter(0,1); fitspettro->SetParameter(1,1); fitspettro->SetParameter(2,1); fitspettro->SetParameter(3,1); //TF1 *fitspettro = new TF1("fitspettro", "gaus"); gamma->Fit("fitspettro"); mg->Add(gamma); mg->Draw("AP"); mg->SetTitle("Covid-19 cases"); mg->GetXaxis()->SetTitle("Day"); mg->GetYaxis()->SetTitle("Cases"); mg->GetYaxis()->SetTitleOffset(offy); mg->GetXaxis()->SetTitleOffset(offx); mg->GetXaxis()->SetRange(0,200); c36->Modified(); //force drawing of canvas to generate the fit TPaveStats c36->Update(); c36->Modified(); //drawlabels(gamma, labelsgamma); c36->Print(dataout); delete c36; exit(0); }