#include #include #include #include #include void ratioplot1() { gStyle->SetOptStat(0); auto c1 = new TCanvas("c1", "A ratio example"); auto h1 = new TH1D("h1", "h1", 50, 0, 10); auto h2 = new TH1D("h2", "h2", 50, 0, 10); auto f1 = new TF1("f1", "exp(- x/[0] )"); f1->SetParameter(0, 3); h1->FillRandom("f1", 1000); h2->FillRandom("f1", 1000); h1->Sumw2(); h2->Scale(1.9 / 2.); h1->GetXaxis()->SetTitle("x"); h1->GetYaxis()->SetTitle("y"); TH1D *h3 = (TH1D*)h1->Clone("h3"); h3->Scale(0.5); h1->Scale(1.e-10); h2->Scale(1.e-10); h3->Scale(1.e-10); auto rp = new TRatioPlot(h1, h2); rp->GetUpperPad()->SetBottomMargin(0); rp->GetLowerPad()->SetTopMargin(0); c1->SetTicks(0, 1); rp->Draw(); rp->GetUpperPad()->cd(); h3->Draw("Same"); rp->GetLowerRefGraph()->SetMaximum(2.); rp->GetLowerRefGraph()->SetMinimum(0.); c1->Update(); c1->Print("ratioPlotTest.eps"); c1->Print("ratioPlotTest.pdf"); c1->Print("ratioPlotTest.png"); }