#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 "TGaxis.h" #include void emitarnum() { gStyle->SetOptFit(0); //no print stat //gStyle->SetOptFit(); const char *dataBe = "Emittance_numb_target_Be.txt"; const char *dataBemm = "Emittance_numb_target_Bemm.txt"; const char *dataC = "Emittance_numb_target_C.txt"; const char *dataCmm = "Emittance_numb_target_Cmm.txt"; const char *dataout = "simulazione/Emittance_numb_target.png"; TCanvas *c01 = new TCanvas("c01","multigraph",1280,1024); //c01->SetLogy(); auto pad = new TPad("pad","",0,0,1,1); pad->cd(); 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(dataBe,"%lg %lg %lg %lg"); TGraphErrors *graph2 = new TGraphErrors(dataC,"%lg %lg %lg %lg"); printf("%d %d \n",graph1->GetN(),graph2->GetN()); graph1->SetMarkerColor(kBlue); graph1->SetLineColor(kBlue); graph1->SetMarkerStyle(5); graph1->SetMarkerSize(6); graph1->SetLineWidth(line); //graph1->SetLineStyle(8); mg->Add(graph1); graph2->SetMarkerColor(kGreen); graph2->SetLineColor(kGreen); graph2->SetMarkerStyle(5); graph2->SetMarkerSize(6); graph2->SetLineWidth(line); //graph2->SetLineStyle(8); mg->Add(graph2); mg->SetTitle(""); mg->GetXaxis()->SetTitle("Number of targets"); mg->GetYaxis()->SetTitle("#epsilon_{RMS} (nm*rad)"); 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->SetMinimum(1.e-10); //mg->SetMaximum(1.5e-5); mg->Draw("AP"); TLegend* leg = new TLegend(0.2, 0.78, .3, .88); leg->SetHeader("Legend"); leg->SetNColumns(1); leg->AddEntry(graph1, "Beryllium", "ap"); leg->AddEntry(graph2, "Carbon", "ap"); //leg->Draw(); c01->Update(); //create a transparent pad drawn on top of the main pad c1->cd(); auto overlay = new TPad("overlay","",0,0,1,1); overlay->SetFillStyle(4000); overlay->SetFillColor(0); overlay->SetFrameFillStyle(4000); overlay->Draw(); overlay->cd(); //Create the second graph TH1F *hframe = overlay->DrawFrame(0,0,30,10000000); TGraphErrors *graph3 = new TGraphErrors(dataBemm,"%lg %lg %lg %lg"); graph3->GetXaxis()->SetTitle("Be slices+vacuum (mm))"); graph3->GetYaxis()->SetTitleOffset(offy); graph3->GetXaxis()->SetTitleOffset(offx); graph3->GetYaxis()->SetTitleSize(40); graph3->GetYaxis()->SetTitleFont(43); graph3->GetYaxis()->SetLabelFont(43); graph3->GetYaxis()->SetLabelSize(40); graph3->GetXaxis()->SetTitleSize(40); graph3->GetXaxis()->SetTitleFont(43); graph3->GetXaxis()->SetLabelFont(43); graph3->GetXaxis()->SetLabelSize(40); graph3->GetXaxis()->SetNdivisions(6); // graph3->Draw("AP"); //Drawsecond axis TGaxis *axis = new TGaxis(30,0,30, 10000000,0.001,10000000,510,"G+"); axis->SetLineColor(kRed); axis->SetLabelColor(kRed); axis->SetLabelOffset(0.015); axis->Draw(); //create a transparent pad drawn on top of the main pad c1->cd(); auto overlay2 = new TPad("overlay2","",0,0,1,1); overlay2->SetFillStyle(4000); overlay2->SetFillColor(0); overlay2->SetFrameFillStyle(4000); overlay2->Draw(); overlay2->cd(); //Create the second graph TH1F *hframe2 = overlay->DrawFrame(0,0,30,10000000); TGraphErrors *graph4 = new TGraphErrors(dataCmm,"%lg %lg %lg %lg"); graph4->GetXaxis()->SetTitle("C slices+vacuum (mm))"); graph4->GetYaxis()->SetTitleOffset(offy); graph4->GetXaxis()->SetTitleOffset(offx); graph4->GetYaxis()->SetTitleSize(40); graph4->GetYaxis()->SetTitleFont(43); graph4->GetYaxis()->SetLabelFont(43); graph4->GetYaxis()->SetLabelSize(40); graph4->GetXaxis()->SetTitleSize(40); graph4->GetXaxis()->SetTitleFont(43); graph4->GetXaxis()->SetLabelFont(43); graph4->GetXaxis()->SetLabelSize(40); graph4->GetXaxis()->SetNdivisions(6); // graph4->Draw("AP"); //Drawsecond axis TGaxis *axis2 = new TGaxis(30,0,30, 10000000,0.001,10000000,510,"G+"); axis2->SetLineColor(kRed); axis2->SetLabelColor(kRed); axis2->SetLabelOffset(0.015); axis2->Draw(); c01->Print(dataout); }