PyROOT Exercise 3: Canvas and Legends

Exercise

Write a python macro ExerciseCanvas.py.

  1. Create two histograms with 50 bins ranging from -3 to 3 with two different names.
  2. Fill first histogram with Gaussian distribution with 10000 entries.
  3. Fill second histogram with a second order polynomial and 5000 entries (hint: hist2.FillRandom("pol2", 500)).
  4. Set the line color of the first histogram to kRed and second to kBlue.
  5. Draw both histograms on a canvas.
  6. Clone both histograms and normalise them (scale with inverse of the integral).
  7. Draw both histograms on a different canvas.
  8. Draw a legend on both canvases at position (0.16, 0.63, 0.45, 0.91); bonus: do it after you created both canvases.
  9. Save both canvases in a PDF; bonus: save them in the same file.

Solution