void drawingExample() { TH1 *hist = new TH1F("hist", "Just a Histogram", 40, -2, 2); hist->FillRandom("gaus"); TBox box; box.SetFillColor(33); box.SetLineColor(38); TCanvas *canvas = new TCanvas("canvas", "Just a Canvas", 100, 100, 800, 800); canvas->Divide(2, 2); // Does not work since the hist, the axes and the bounding box of the graph are covered by the box canvas->cd(1); hist->Draw(); gPad->Modified(); gPad->Update(); box.DrawBox(-1, gPad->GetUymin(), 1, gPad->GetUymax()); // Works but still the axes and the bounding box of the graph are covered by the box. // This is also very inefficient since the hist is drawn twice and so all drawing commands // in ps-files will appear twice, too! canvas->cd(2); hist->DrawCopy(); gPad->Modified(); gPad->Update(); box.DrawBox(-1, gPad->GetUymin(), 1, gPad->GetUymax()); hist->DrawCopy("same"); // Now the axes are no longer coverd by the box. But still the bounding box of the graph is. // Also the hist is drawn twice and therefore this is very inefficient! canvas->cd(3); hist->DrawCopy(); gPad->Modified(); gPad->Update(); box.DrawBox(-1, gPad->GetUymin(), 1, gPad->GetUymax()); hist->DrawCopy("axissame"); hist->DrawCopy("same"); // The axes are drawn perfectly and the hist is only drawn once, so this is more efficient than // the methods before. Still the bounding box of the graph is covered by the box and even more // important no hist-title is drawn! canvas->cd(4); hist->DrawCopy("axis"); gPad->Modified(); gPad->Update(); box.DrawBox(-1, gPad->GetUymin(), 1, gPad->GetUymax()); hist->DrawCopy("axissame"); hist->DrawCopy("same"); // So, what would be the best way to draw a region that depends on the range of the axes that // is REALLY BEHIND the hist? }