void sames_tratio_plot() { TFile *f=new TFile("kk.root"); TH1F *h1; TH1F *h2; //h1 = (TH1F*)f->Get("mkk_d0"); //h2 = (TH1F*)f->Get("mkk_d0bar"); h1 = (TH1F*)f->Get("md0pi_d0"); h2 = (TH1F*)f->Get("md0pi_d0bar"); cout<< "Entries D0 (h1):"<GetEntries()<<"\n"; cout<< "Integral D0 (h1):"<Integral()<<"\n"; cout<< "Entries D0bar (h2):"<GetEntries()<<"\n"; cout<< "Integral D0bar (h2):"<GetEntries()<<"\n"; // Define the Canvas TCanvas *c = new TCanvas("c", "canvas", 700, 650); // Upper plot will be in pad1 TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0); // Upper and lower plot are joined pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); // pad1 becomes the current pad //h1->SetStats(0); // No statistics on upper plot TH1F *h1n = (TH1F*)h1->DrawNormalized(); h1n->Draw(); // Draw h1 //h1n->SetStats(0); TH1F *h2n = (TH1F*)h2->DrawNormalized(); h2n->DrawNormalized("sames"); h2n->SetStats(0); //h2->Draw("sames"); // Draw h2 on top of h1 //h2->SetStats(0); // No statistics on upper plot c->Update(); /*TPaveStats *stat1 = (TPaveStats*)(h1->FindObject("stats")); TPaveStats *stat2 = (TPaveStats*)(h2->FindObject("stats")); stat1->SetTextColor(kRed); stat1->SetLineColor(kRed); stat2->SetTextColor(kBlue); stat2->SetLineColor(kBlue); stat1->Draw(); stat2->Draw();*/ TLegend *legend = new TLegend(.75,.80,.95,.95); legend->AddEntry(h1n,"D^{0}"); legend->AddEntry(h2n,"#barD^{0}"); legend->SetLineColor(0); legend->Draw(); //if ROOT_VERSION_CODE >= ROOT_VERSION(6,8,0) // Avoid the first label (0) to be clipped. TAxis *axis = h1n->GetYaxis(); axis->ChangeLabel(1, -1, -1, -1, -1, -1, " "); axis->SetLabelFont(43); // Absolute font size in pixel (precision 3) axis->SetLabelSize(15); // lower plot will be in pad c->cd(); TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.2); pad2->Draw(); pad2->cd(); // Define the ratio plot TH1F *h3 = (TH1F*)h1n->Clone("h3"); h3->SetLineColor(kBlack); h3->SetMinimum(-0.5); //h3->SetMaximum(7); h3->SetMaximum(0.5); h3->Sumw2(); h3->SetStats(0); // No statistics on lower plot h3->Divide(h2); h3->SetMarkerStyle(20); h3->Draw("ep"); // Draw the ratio plot //TLine *line = new TLine(1.75,1,2.05,1); TLine *line = new TLine(2.005,1,2.025,1); line->SetLineColor(kBlack); line->Draw("same"); // h1 settings //h1->Scale(0.963); //(D0bar/D0) h1n->SetLineWidth(2); //h1->SetStats(0); h1n->SetFillStyle(3004); h1n->SetFillColor(kBlue); // Y axis h1 plot settings h1n->GetYaxis()->SetTitleSize(20); h1n->GetYaxis()->SetTitleFont(43); h1n->GetYaxis()->SetTitleOffset(1.55); // h2 settings h2n->SetLineWidth(2); //h2->Draw("sames"); //h2->SetStats(0); h2n->SetLineColor(kRed); h2n->SetFillColor(kRed); h2n->SetFillStyle(3005); // Ratio plot (h3) settings h3->SetTitle(""); // Remove the ratio title // Y axis ratio plot settings h3->GetYaxis()->SetTitle("D^{0}/#barD^{0}"); h3->GetYaxis()->SetNdivisions(505); h3->GetYaxis()->SetTitleSize(17); h3->GetYaxis()->SetTitleFont(43); h3->GetYaxis()->SetTitleOffset(1.55); h3->GetYaxis()->CenterTitle(); h3->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetYaxis()->SetLabelSize(15); // X axis ratio plot settings h3->GetXaxis()->SetTitleSize(20); h3->GetXaxis()->SetTitleOffset(2); h3->GetXaxis()->SetTitleFont(43); h3->GetXaxis()->SetTitleOffset(3.0); h3->GetXaxis()->CenterTitle(); h3->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetXaxis()->SetLabelSize(15); }