TF ErrAna InClassLab

From New IAC Wiki
Revision as of 15:36, 21 January 2010 by Oborn (talk | contribs) (→‎Day 3)
Jump to navigation Jump to search

Start ROOT and Draw Histogram

Step 1

In this first lab your goal will be to start root and draw a histogram.

If you are on a Windows machine start the ROOT interpreter by double clicking on the Desctop icon which looks like a tree and says ROOT underneath it If you are on a Unix machine set the environmental variable ROOTSYS to point to the base subdirectory containing the ROOT files and start root with the command $ROOTSYS/bin/root. You can set the ROOTSYS environmental variable under the bash chell with the command

export ROOTSYS=path

where path identifies the location of the root base subdirectory. My ROOT base subdirectory is located at ~/src/ROOT/root so I would execture the following shell command

export ROOTSYS=~/src/ROOT/root

Step 2

Define a variable to contain the desired histogram

TH1F *Hist1=new TH1F("Hist1","Hist1",50,-0.5,49.5);


The above function "TH1F" has 5 parameters and is a member of the class TH1.

The first parameter "Hist1" create a name for the histogram. The second parameter gives the histogram a title. I usually set the name and title to the same variable name I use to store the histogram. This allows me to look up the variable name of the histogram when I double click on the histogram from the browser listing. The third parameter (50) is an integer which identifies the number of "bins" the histogram will use to store information. The Fourth parameter (-0.5) is a real number identifying the numerical value to be used for the lowest bin and the fifth parameter is the value for the highest bin.

Step 3

The class TH1 contains a function "Fill" which you can you to insert data into the histogram. In the above example the variable "Hist1" was defined in terms of the class TH1. To use the Fill function which is defined within the class TH1 and associated with the histogram named Hist1 you use the command

 Hist1->Fill(10);

The above Fill function will increment the counter for the bin in Hist1 which is associated with the numerical value "10"

Step 4

The TH1 class also has a function to graphically display the created histogram. The function is executed with the command

 Hist1->Draw();


You should now see a histogram on your computer screen if ROOT is able to create a graphics window.

Lab 2

Histogram by Hand

Our goal is to construct a Histogram by hand (without using a computer).

Step 1: Range

The first step to creating a histogram is to determine what are the min and max values

Step 2: Binning

What is binning?

The term binning is used to basically describe how must you have rounded off your data. A bin represent the distance between two interval in a histogram over which you are counting all measurements as the same value.

For example: If I have the following data

1.2, 1.6, 1.4, 1.8, 1.3

and I create a histogram from 1-2 using only one bin, then I will have 4 counts showing in my histogram between 1 and 2 units. If however, I create 2 bins between 1 and 2 then I will have 3 counts in the bin corresponding to 1-1.5 and 2 counts in the 1.5-2.0 bin.

You need to decide how to quantize the information to be presented in the histogram. One thing to consider is the systematic uncertainty of your device. If your device measures the temperature and has scale increments of 1/10 of a degree, you don't want to bin your temperature measurement using bin widths that are 1/10 or smaller.

Step 3: Filling the Histogram

The bins in a histogram are filled by rounding off the data according to the bin width. What happens if you are on the edge of a bin? Just follow the roundoff procedure in the notes.

Step 4: Labels

Properly label the abscissca and ordinate axis with names and UNITs.

Data for histogram

Create a histogram by hand using the following data.

Two dice are rolled 20 times. Create a histogram to represent the 20 trials below

Trial Value
1 8
2 10
3 9
4 5
5 9
6 6
7 5
8 6
9 3
10 9
11 8
12 5
13 8
14 10
15 8
16 11
17 12
18 6
19 7
20 8


Create ROOT script to make Histogram

We are going to repeat Lab 1 but this time we will make a script to do the typing for us.

Step 1: Create Text file

Use an editor to create a text file.

In windows this could be the program "notepad" under the utilities menu (ie : Start->All Programs->Accessories->Notepad)

The important point is that you want to create and ASCII text file.

As a test, write the following in the text file

MyProgram()
{
new TBrowser();
}

Now save the file as "test.C" in the root sub directory.

In Windows the root program launches such that it is within the subdirectory "C:\root". You should save your text file under the subdirectory "Local Disk (C:) root" using the "save as" menu.


If you did things correctly you can use the command completion function on the ROOT command line to load in your program

If you type the partial name

.L te

then hit the tab key, ROOT will complete the command or offer a list of commands you can use.

root[1] .L test
test/
test.C


If you are having trouble then just type the following within root

.L test.C
MyProgram();

You should see the ROOT browser open in a new window.

Step 2: Create a Program to fill histogram

Now let's create a program to create and fill a histogram like we did in Lab 1.

Using Notepad, or another editor, create and ASCII file with the following contents

MyProgram()
{
  TH1F *Hist1=new TH1F("Hist1","Hist1",50,-0.5,49.5);
  Hist1->Fill(10);
  Hist1->Draw();
}

Save the file under the name "MyProgram.C"

Now launch root and type into the interpreter window

.x MyProgram.C

alternatively you can type

.L MyProgram.C

and then

MyProgram();


The above represents two different ways to do the same thing. One advantage of the

.L MyProgram.C


sequence is that when you are creating or editing a program you can reload the program into the interpreter after saving changes to a file. So if you create a program that doesn't work as expected you debug it, save the changes, reload it into the interpreter, and then execute it again.


Day 3

ROOT GUI practice

Histogram Font labels

Hisogram module

Rebinning

compare with ROOT's output.


[1] Forest_Error_Analysis_for_the_Physical_Sciences