# Using the Treeviewer 1

Right-click the `tree1`

icon again and select `StartViewer`

.

Note

You’re looking at the TreeViewer, a tool for making plots from n-tuples interactively. The TreeViewer is handy for quick studies of n-tuples, but it’s almost certainly not enough to get you through the work you’ll have to do this summer. Any serious analysis work will involve editing ROOT macros and writing C++ code or Python scripts.

Still, there are times when a simple tool can be useful. Let’s use the
TreeViewer to examine the `tree1`

n-tuple. Once you have an idea of
what’s inside `tree1`

, you’ll be ready to start writing programs to
analyze it.

You can figure out how to use the TreeViewer on your own; the `Help`

menu in the right-hand corner of the TreeViewer panel is genuinely
useful. Here’s a quick guide to get you started.

In the second column of the large pane in the window, you’ll see the variables in the n-tuple; they all have a “leaf” icon next to them. Double-click on one of them and look the resulting histogram. Double-click on a few more variables and see how the histogram changes.

## Correlating variables: scatterplots (10 minutes)

Left-click on a variable and hold the mouse down. Drag the variable next
to the blue curly `X`

in the first column, over the word `-empty-`

,
and let go of the button. Now select a different variable and drag it
over next to the curly `Y`

. Click on the scatterplot icon in the lower
left-hand corner of the TreeViewer (it’s next to a button labeled
`SPIDER`

2).

Note

This is a scatterplot, a handy way of observing the correlations between two variables. Be careful: it’s easy to fall into the trap of thinking that each (x,y) point on a scatterplot represents two values in your n-tuple. In fact, the scatterplot is a grid and each square in the grid is randomly populated with a density of dots that’s proportional to the number of values in that grid.

Drag different pairs of variables to the `X`

and `Y`

boxes and look
at the scatterplots. Do you see any correlations between the variables?

Note

If you just see a shapeless blob on the scatterplot, the variables are
likely to be uncorrelated; for example, plot `px`

versus `py`

. If
you see a pattern, there may be a correlation; for example, plot `pz`

versus `zv`

. It appears that the higher `pz`

is, the lower `zv`

is. Perhaps the particle loses energy before it is deflected in the
target.

## New variables: expressions (10 minutes)

Note

There are other quantities that we may be interested in apart from the ones already present in the n-tuple. One such quantity is \(p_{T}\) which is defined by:

This is the transverse momentum of the particle, that is, the component
of the particle’s momentum that’s perpendicular to the *z*-axis.

You can use TreeViewer to create expressions that are functions of the
variables in the tree. Double-click on one the **E()** icons that has
the word `-empty-`

next to it. In the dialog box, type
`sqrt(px*px+py*py)`

in the box under **Expression**, and type
`~pt`

3 in the box under **Alias**. Then click on **Done**. Now
double-click on the word `~pt`

in the TreeViewer.

Tip

When you’re typing in the expression, you don’t have to type the name of any variable in the tree. You can just click on the name in the TreeViewer.

The quantity theta, or the angle that the beam makes with the *z*-axis,
is calculated by:

The units are radians. Let’s create a new expression to calculate theta.
Double-click on a different **E()** icon with `-empty-`

next to it.
Type `atan2(~pt,pz)`

under **Expression**, and `~theta`

under
**Alias**. Click **Done**, then double-click on `~theta`

. 4

Note

After an expression is no longer empty, you can’t double-click on it to
edit it; that will just cause the expression to be plotted. To edit an
existing expression, right-click on it and select **EditExpression**.

You can have expressions within expressions (such as `~pt`

in the definition of `~theta`

). All expressions that you create must
have names that begin with a tilde (~), and the expression editor will
enforce this. A common error is to forget the tilde when you’re typing
an expression; that’s the reason why it can be a good idea to insert a
variable or an alias into an expression by clicking on it in the
TreeViewer.

## Restricting values: cuts (10 minutes)

Let’s create a “cut” (a limit on the range of a variable to be
plotted). Edit another empty expression and give it the formula `zv < 20`

and the alias `zcut`

.

Note

Note how the icon changes in the TreeViewer. ROOT recognizes that you’ve typed a logical expression instead of a calculation.

Drag `~zcut`

to the scissor icon. Double-click on `zv`

to plot it.
Double-click on some of the other variables and look at both the
histogram title and the `Nent`

in the statistics box of the
histograms; the z-cut affects all the plots, not just the plot of
`zv`

.

Double-click on the scissor icon to turn off the cut; note the change in the scissor icon. Double-click on the icon again to turn the cut back on.

Now edit `~zcut`

by right-clicking on it and selecting
`EditExpression`

. Edit the expression to read `zv<20 && zv>10`

and
click `Done`

. Plot `zv`

. Has the cut changed? Now drag `~zcut`

to
the scissors and plot `zv`

again.5

If you wanted to display this plot in a talk, you’d have to label both
axes (which you’ve already learned how to do)
and do something about
that title. It’s not clear how to fix the title of a plot from
TreeViewer; if you right-click on it you see that it’s a `TPaveText`

with a number of options that don’t seem to do what you want.

I figured this out by saving the plot as c1.C, examining that file, and
looking up `TPaveText`

on the ROOT web site. The simplest way to edit
the title is right-click on it, select `Clear`

, then select
`InsertText`

and type in your new title.

- 1
If you feel that this course has been too easy so far, you can skip the TreeViewer. It’s trivial to learn on your own if you want to. If you already know about cuts and scatterplots, skip ahead to The Notebook Server.

- 2
Go ahead and click on the SPIDER button if you want. A spider (or radar) chart is a way of displaying multivariant data in a two-dimensional graph.

I’ve never seen spider charts used in physics, except when I looked up the definition for this tutorial. By the way, if you clicked that link, you just looked up spider charts on the web. (OK, I’m no Randall Munroe.)

- 3
That first character is a tilde (~), not a dash.

- 4
The reason to use

`atan2(y,x)`

instead of just`atan(y/x)`

is that the`atan2`

function correctly handles the case when*x*=0.- 5
For those who know what a “weighted histogram” means: A “cut” is actually a weight ROOT applies when filling a histogram; a logical expression has the value 1 if true and the value 0 if false. If you want to fill a histogram with weighted values, use an expression for the cut that corresponds to the weight.

For example: a cut of

`1/e`

will fill a histogram with each event weighted by 1/e; a cut of`(1/e)*(sqrt(z)>3.2)`

will fill a histogram with events weighted by 1/e, for those events with sqrt(z) greater than 3.2.