// a macro to draw a set of Beta distributions { gROOT->Reset(); // first make a canvas and a 2D histogram for the axes TCanvas* c1 = new TCanvas("c1", "c1", 10, 10, 500, 500); c1->SetBottomMargin(0.15); c1->SetLeftMargin(0.15); // create functions to be plotted TF1* f1 = new TF1("f1","TMath::BetaDist(x,[0],[1])", 0, 1); f1->SetParameter(0, 2.); f1->SetParameter(1, 3.); TF1* f2 = new TF1("f2","TMath::BetaDist(x,[0],[1])", 0, 1); f2->SetParameter(0, 5.); f2->SetParameter(1, 2); TF1* f3 = new TF1("f3","TMath::BetaDist(x,[0],[1])", 0, 1); f3->SetParameter(0, 2.); f3->SetParameter(1, 2.); // use f1 to set axis properties f1->SetMinimum(0); // y axis min and max f1->SetMaximum(3.0); f1->SetRange(0., 1.0); // x axis gStyle->SetOptStat(0); // turn off statistics box f1->SetTitle(""); // turn off global title f1->GetHistogram()->GetYaxis()->SetTitle("f(x;#alpha,#beta)"); f1->GetHistogram()->GetXaxis()->SetTitle("x"); gStyle->SetOptLogy(0); // 1 for log scale // See TStyle for how to change attributes f1->GetXaxis()->SetTitleOffset(1.2); // factor multiplies default offset f1->GetYaxis()->SetTitleOffset(1.5); f1->GetXaxis()->SetTitleSize(0.04); // default = 0.04 (??? in manual, 0.02) f1->GetYaxis()->SetTitleSize(0.04); f1->GetXaxis()->SetNdivisions(8); // N2*100+N1 (N2=secondary, N1=primary) f1->GetYaxis()->SetNdivisions(8); // N2*100+N1 (N2=secondary, N1=primary) f1->GetXaxis()->SetLabelSize(.04); f1->GetYaxis()->SetLabelSize(.04); f1->GetXaxis()->SetLabelOffset(0.01); f1->GetYaxis()->SetLabelOffset(0.015); f1->GetXaxis()->SetTickLength(0.015); // default = 0.03 f1->GetYaxis()->SetTickLength(0.015); // default = 0.03 f1->GetXaxis()->SetLabelFont(42); // default = 62 f1->GetYaxis()->SetLabelFont(42); f1->GetXaxis()->SetTitleFont(42); f1->GetYaxis()->SetTitleFont(42); // gStyle->SetHistLineWidth(1); // Default:1 --- Line width of histogram // gStyle->SetLineWidth(.5); // Default:1 --- Line width of axis. // gROOT->ForceStyle(); // c1->GetFrame()->SetBorderSize(6); // from root cheat sheet (???) // c1->GetFrame()->SetBorderMode(-1); // now add some stuff to the graph f1->SetLineStyle(1); f1->SetLineWidth(1.5); f1->Draw(); f2->SetLineStyle(2); f2->SetLineWidth(1.5); f2->Draw("same"); f3->SetLineStyle(3); f3->SetLineWidth(1.5); f3->Draw("same"); TLegend* leg = new TLegend(0.2, 0.7, 0.5, 0.85); // x1, y1, x2, y2 leg->SetTextSize(0.04); leg->SetBorderSize(0); leg->SetFillColor(0); leg->AddEntry(f1, "#alpha=2, #beta=3", "l"); // l for line, f for box leg->AddEntry(f2, "#alpha=5, #beta=2", "l"); leg->AddEntry(f3, "#alpha=2, #beta=2", "l"); leg->Draw(); }