From Łukasz Graczykowski
(Difference between revisions)
|
|
| Line 68: |
Line 68: |
| | * macros can contain more functions - during the macro execution the one which will be run is that which name corresponds to the macro name (the equivalent of the <code>main</code> function in standard C++) | | * macros can contain more functions - during the macro execution the one which will be run is that which name corresponds to the macro name (the equivalent of the <code>main</code> function in standard C++) |
| | | | |
| - | == Wynik == | + | == Results == |
| - | Wykresy:
| + | Plots: |
| - | * okno 1 | + | * window 1 |
| | [[File:lab1_1.png]] | | [[File:lab1_1.png]] |
| - | * okno 2 | + | * window 2 |
| | [[File:1_2.png]] | | [[File:1_2.png]] |
Latest revision as of 12:47, 28 February 2022
Documentation
Documentation of the ROOT environment:
Exercise
1. Write a macro, which:
- creates an object
fun1 of type TF1 representing a sin(x) function (see class TMath)
- creates an object
fun2 of type TF1 representing a cos(x) function
- creates a window with 4 panels (panel distribution 2x2) - see class
TCanvas and method Divide
- draws the
fun1 object on panel 1, fun2 on panel 2, and two functions simultaneously on panel 3
- changes the color of the line of function
fun2 to blue - see method SetLineColor and class TColor
2. Let's imagine we throw a dice that is asymmetric. The table below summarizes the results:
| Number of pips
| 1
| 2
| 3
| 4
| 5
| 6
|
| Number of throws
| 2
| 1
| 5
| 4
| 10
| 12
|
We modify further the macro:
- let's create a histogram (see class
TH1D) by filling each bin (which corresponds to each dice facet) with values from the table (number of throws) - the histogram should be plotted on panel 4
- create a plot, called graph (see class
TGraph) according to values from the table.
- change the style of graph points (see method
SetMarkerStyle and class TAttMarker)
- draw the graph in a separate window
Attention
- Attention! In order to run ROOT environment on your student account in the laboratory, you have to add the following lines (if they were not added already) to the file
$HOME/.bashrc (they could had been added during the PTI class):
export ROOTSYS=/opt/root
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
- the ROOT environment is installed separately on each computer - it is not available on the server
- in the ROOT environment we write macros, which have extensions .c, .C, .cpp, or .cxx
- a macro contains a C++ code interpreted line-by-line
- in principle, we do not need to include any libraries
- example 1:
{
double x = 5;
cout<<x<<endl;
}
- execution of a macro: start the environment (command
root), type .x macro.C
- macro can also contain funkcje, example 2:
int macro()
{
double x = 5;
cout<<x<<endl;
return 1;
}
- name of the macro must be the same as the name of the main function in the macro (in order to run it with the command
.x macro.C)
- macros can contain more functions - during the macro execution the one which will be run is that which name corresponds to the macro name (the equivalent of the
main function in standard C++)
Results
Plots: