{ TFile f("hsimple.root"); //Here are the distributions we want to compare hpy = new TH1F("hpy","This is the py distribution",100,-4,4); ntuple->Draw("py >> hpy"); hpx = new TH1F("hpx","This is the px distribution",100,-4,4); ntuple->Draw("px >> hpx"); hpx_line = (TH1F*)hpx->Clone(); hpy_line = (TH1F*)hpy->Clone(); //setup the drawing area c1 = new TCanvas("c1","Example"); c1->Divide(1,2); c1->SetFillColor(41); c1->GetPad(1)->SetFillColor(41); c1->GetPad(1)->SetFrameFillColor(0); c1->GetPad(1)->SetFrameFillColor(0); c1->GetPad(2)->SetFillColor(41); c1->cd(1); //draw the comparison plot Int_t cpy = TColor::GetColor("#8888FF"); hpy->SetFillColor(cpy); hpy->Draw(); Int_t cpx = TColor::GetColor("#FF8888"); hpx->SetFillColor(cpx); hpx->Draw("same"); Int_t cpyl = TColor::GetColor("#0000FF"); hpy_line->SetLineColor(cpyl); hpy_line->SetLineWidth(2); hpy_line->Draw("same"); Int_t cpxl = TColor::GetColor("#FF0000"); hpx_line->SetLineColor(cpxl); hpx_line->SetLineWidth(2); hpx_line->Draw("same"); c1->cd(2); //draw the ratio plot hpyDhpx = new TH1F("hpyDhpx","This is the py/px distribution",100,-4,4); hpyDhpx->Divide(hpy,hpx_line); hpyDhpx->SetLineColor(cpyl); hpyDhpx->SetFillColor(cpy); hpyDhpx->Draw(); //sets scale ghpyDhpx = new TH1F("ghpyDhpx","This is the greater than 1 py/px distribution",100,-4,4); for( int i =0; i != hpyDhpx->GetNbinsX(); ++i) { ghpyDhpx->Fill( hpyDhpx->GetBinCenter(i), (hpyDhpx->GetBinContent(i) > 1 ? hpyDhpx->GetBinContent(i) : 1)); } lhpyDhpx = new TH1F("lhpyDhpx","This is the less than 1 py/px distribution",100,-4,4); lhpyDhpx->Add(hpyDhpx,ghpyDhpx,1,-1); lhpyDhpx->SetFillColor(2); lhpyDhpx->Draw("same"); //This gives us a line at y=1 ghpyDhpx->SetLineColor(cpyl); ghpyDhpx->Draw("same"); //put color in the range of 0 to 1 lhpyDhpx = new TH1F("lhpyDhpx","This is the less than 1 py/px distribution",100,-4,4); for( int i =0; i != hpyDhpx->GetNbinsX(); ++i) { lhpyDhpx->Fill( hpyDhpx->GetBinCenter(i), (hpyDhpx->GetBinContent(i) !=0 ? 1 : 0)); } lhpyDhpx->SetFillColor(cpx); lhpyDhpx->Draw("same"); //create a histogram to draw the background color so it looks like one of the histograms is plotted upside-down // this one is actually the inverse of the histogram we want people to perceive. lhpyDhpx = new TH1F("lhpyDhpx","This is the less than 1 py/px distribution",100,-4,4); for( int i =0; i != hpyDhpx->GetNbinsX(); ++i) { lhpyDhpx->Fill( hpyDhpx->GetBinCenter(i), (hpyDhpx->GetBinContent(i) < 1 ? ( 0 !=hpyDhpx->GetBinContent(i) ?hpyDhpx->GetBinContent(i) :1 ): 1)); } lhpyDhpx->SetFillColor(c1->GetFillColor()); lhpyDhpx->SetLineColor(cpxl); lhpyDhpx->Draw("same"); }