First Steps: Canvases and Pads


Creating TCanvas and TPad objects. Making a TPad the current pad. Adding objects to the current pad. Updating pads.

The Lesson

Start by reading about TCanvas in the ROOT Crib. Now we will put it into practice. You may find it helpful to open a second browser window looking at the TCanvas documentation as we proceed.

Run ROOT and create a TCanvas:-

root TCanvas *my_canvas = new TCanvas("my_canvas","Plotting Canvas",150,10,990,660); A window with the title "Plotting Canvas" should appear. Now divide the canvas into 6 pads:- my_canvas->Divide(3,2,0.01,0.01,0); To show that we now have 6 pads get CINT to find one with:- .print my_canvas_1 Make pad my_canvas_3 the current pad and create a 2D histogram in it (we will look at histogram in the Histograms lesson) and add it to the current pad:- my_canvas_3->cd(); TH1F *hist = new TH1F("hist","My histogram",100,0.,100.); hist->Draw(); This produces an empty histogram in the current pad. If running compiled code we would now have to:- my_canvas_3->Update(); but thanks to a CINT shortcut this has been done automatically. Now we update the histogram:- hist->Fill(1.); Although this updates the histogram, the pad does not change as it is unaware that the histogram has changed. To tell it we have to:- my_canvas_3->Modified(); For another simple example of TCanvas use see the ROOT tutorial An Example of Object Oriented User Interface


Go Back to the The First Steps Top Page

If you have any comments about this page please send them to Nick West