(python-analysis-draw)= # Walkthrough: Simple analysis using the Draw command **(10 minutes)** :::{admonition} Moving to the next level :class: note It may be that all the analysis tasks that your supervisor will ask you to do can be performed using the `Draw` command, the `Treeviewer`, the `FitPanel`, and other simple techniques discussed in the early chapters of the [ROOT Users Guide](https://root.cern/root/htmldoc/guides/users-guide/ROOTUsersGuide.html). However, it's more likely that these simple commands will only be useful when you get started; for example, you can draw a histogram of just one variable to see what the histogram limits might be. Let's start with the same tasks you did with Treeviewer.[^f89]$^,$[^f90] ::: If you didn't copy the example n-tuple file in {ref}`the basics`, do so now: > cp ~seligman/root-class/experiment.root $PWD Open the sample ROOT TTree in the notebook with the following: :::{code-block} python from ROOT import TFile, gROOT myFile = TFile("experiment.root") tree1 = gROOT.FindObject("tree1") ::: :::{admonition} Let's understand what this does :class: note The first command imports specific ROOT classes into Python (see the previous page). That third command means: Look through everything we've read in (the "everything" is `gROOT`) and find the object whose name is `tree1`. If you've done {ref}`cpath`, note that in Python we have to read in the n-tuple explicitly. ::: In a notebook, you can't use {ref}`the Scan method ` to look at the contents of the tree, but you can display the names of the variables and the size of the `TTree`: tree1.Print() You can see that the variables stored in the TTree are **`event`**, **`ebeam`**, **`px`**, **`py`**, **`pz`**, **`zv`**, and **`chi2`**. Create a histogram of one of the variables. For example: :::{code-block} python from ROOT import TCanvas my_canvas = TCanvas() tree1.Draw("ebeam") my_canvas.Draw() ::: While we have to explicitly Draw a canvas, we can re-use a previously-defined canvas (the same way command-line ROOT keeps re-using c1). Using the Draw commands, make histograms of the other variables. [^f89]: I duplicate some of the descriptions from the Treeviewer discussion, in case you decided to rush into programming and skip the simple tools. [^f90]: If you're experienced with Python, you may ask why I'm not including [NumPy](https://numpy.org/), [SciPy](https://scipy.org/), and [Matplotlib](https://matplotlib.org/) in this tutorial. I want to focus on the ROOT toolkit, even though many tasks (especially in the {ref}`advanced exercises` and {ref}`expert exercises`) can be more easily accomplished using those additional packages. I wrestled with this issue for a while, before deciding that there are hundreds of web pages on these standard Python tools but few sites on ROOT. But I may change my mind next year!