{ gROOT->Reset(); // -- Nothing fancy gROOT->SetStyle("Plain"); gROOT->ForceStyle(); // -- Don't show histogram titles gStyle->SetOptTitle(0); // -- Open the File TFile f("Exercise3.root"); // -- Remove stats box gStyle->SetOptStat(0); // -- Define and fill histograms containing the sum and ratio TH1F *hsum1 = new TH1F(*h1d1); TH1F *hsum2 = new TH1F(*h1d1); TH1F *hratio = new TH1F(*h1d1); hsum1->Add(h1d1, h1d2); hsum2->Add(hsum1, h1d2); hratio->Divide(h1d1, h1d2); // -- Change the appearance hsum2->SetFillColor(kBlue); hsum1->SetFillColor(kGreen); h1d1->SetFillColor(kRed); // -- Provide some labelling hsum2->SetAxisRange(0., 8.); hsum2->SetTitleOffset(1.2, "y"); hsum2->SetXTitle("Charged Track Mulitiplicity"); hsum2->SetTitleOffset(1.2, "x"); hsum2->SetYTitle("Entries/bin"); // -- Draw them. Redraw the axes at the end hsum2->Draw(); hsum1->Draw("Same"); h1d1->Draw("Same"); hsum2->Draw("sameaxis"); // -- Make an inset and show the ratio TPad *npad = new TPad("npad", "", 0.6, 0.6, 0.9, 0.88); npad->Draw(); npad->cd(); gPad->SetGridx(1); gPad->SetGridy(1); // -- make enough space so that axis titles are not cut off gPad->SetBottomMargin(0.25); gPad->SetLeftMargin(0.25); // -- labelling hratio->SetLabelSize(0.1, "x"); hratio->SetLabelSize(0.1, "y"); hratio->SetNdivisions(305); hratio->SetTitleSize(0.105, "y"); hratio->SetTitleOffset(.8, "y"); hratio->SetYTitle("Positive/Negative"); hratio->SetTitleSize(0.1, "x"); hratio->SetTitleOffset(1.2, "x"); hratio->SetXTitle("Multiplitcity"); // -- show a subrange hratio->SetMaximum(3.); hratio->SetAxisRange(0., 8.); hratio->Draw(); // -- go back to the big canvas and put a legend there c1->cd(); TLegend *pl = new TLegend(0.6,0.25,0.88,0.5); pl->SetTextSize(0.03); pl->SetFillColor(0); TLegendEntry *ple = pl->AddEntry(h1d1, "Positive GoodTracks", "F"); ple = pl->AddEntry(hsum1, "Negative GoodTracks", "F"); ple = pl->AddEntry(hsum2, "Charged tracks", "F"); pl->Draw(); // -- Save it to files c1->SaveAs("inset.eps"); c1->SaveAs("inset.gif"); }