#include "TCanvas.h" #include "TPad.h" #include "TMultiGraph.h" #include "TGraph.h" #include "TGraphAsymmErrors.h" #include "TGraphErrors.h" #include "TAxis.h" #include "TLegend.h" #include "TLatex.h" #include "TROOT.h" #include "TPaveStats.h" #include "TStyle.h" #include void dedxmat() { gStyle->SetOptFit(0); //no print stat //gStyle->SetOptFit(); const char *data01 = "Edep_dx_materials_tar01.txt"; const char *data02 = "Edep_dx_materials_tar01.txt"; const char *dataout = "Edep_dx_materials.png"; TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); //c01->SetLogy(); gStyle->SetOptStat(111110); auto mg = new TMultiGraph(); float offx=1.3; float offy=1.3; float margr=0.08; float w=3; float margl=0.12; float line=2; gPad->SetLeftMargin(margl); gPad->SetRightMargin(margr); TGraphErrors *graph1 = new TGraphErrors(data01,"%lg %lg %lg %lg"); TGraphErrors *graph2 = new TGraphErrors(data02,"%lg %lg %lg %lg"); printf("%d %d \n",graph1->GetN(),graph2->GetN()); graph1->SetMarkerColor(kBlue); graph1->SetLineColor(kBlue); graph1->SetMarkerStyle(22); graph1->SetMarkerSize(3); graph1->SetLineWidth(line); graph1->SetLineStyle(8); mg->Add(graph1); graph2->SetMarkerColor(kGreen); graph2->SetLineColor(kGreen); graph2->SetMarkerStyle(29); graph2->SetMarkerSize(3); graph2->SetLineWidth(line); graph2->SetLineStyle(8); mg->Add(graph2); mg->SetTitle(""); mg->GetXaxis()->SetTitle("Material"); mg->GetYaxis()->SetTitle("#frac{d}{dx} (MeV/mm)"); mg->GetYaxis()->SetTitleOffset(offy); mg->GetXaxis()->SetTitleOffset(offx); mg->GetYaxis()->SetTitleSize(40); mg->GetYaxis()->SetTitleFont(43); mg->GetYaxis()->SetLabelFont(43); mg->GetYaxis()->SetLabelSize(40); mg->GetXaxis()->SetTitleSize(40); mg->GetXaxis()->SetTitleFont(43); mg->GetXaxis()->SetLabelFont(43); mg->GetXaxis()->SetLabelSize(40); //mg->GetXaxis()->SetNdivisions(6); // mg->Draw("ALP"); TLegend* leg = new TLegend(0.2, 0.78, .3, .88); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(graph1, "Target 1", "ap"); leg->AddEntry(graph2, "Target 2", "ap"); leg->Draw(); gPad->Update(); Int_t bin1= mg->GetXaxis()->FindBin(1); Int_t bin2= mg->GetXaxis()->FindBin(2); Int_t bin3= mg->GetXaxis()->FindBin(3); Int_t bin4= mg->GetXaxis()->FindBin(4); Int_t bin5= mg->GetXaxis()->FindBin(5); mg->GetHistogram()->GetXaxis()->SetBinLabel(bin1,"H_{2}"); gPad->Update(); mg->GetXaxis()->ChangeLabel(bin1, 45, 0.02, 31, -1, -1,Form("H_{2}")); gPad->Update(); mg->GetXaxis()->ChangeLabel(bin2, 45, 0.02, 31, -1, -1,Form("He")); gPad->Update(); mg->GetXaxis()->ChangeLabel(bin3, 45, 0.02, 31, -1, -1,Form("Li")); gPad->Update(); mg->GetXaxis()->ChangeLabel(bin4, 45, 0.02, 31, -1, -1,Form("Be")); gPad->Update(); mg->GetXaxis()->ChangeLabel(bin5, 45, 0.02, 31, -1, -1,Form("C")); gPad->Update(); gPad->Update(); c01->Update(); c01->Print(dataout); }