From Łukasz Graczykowski
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
Uwagi
- Uwaga! Aby środowisko ROOT można było uruchomić na własnym koncie użytkownika w laboratorium, należy w pliku
$HOME/.bashrc
dopisać następujące linijki (jeśli nie były dodane na zajęciach z PTI):
export ROOTSYS=/opt/root
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
- środowisko ROOT jest zainstalowane lokalnie na każdym komputerze - nie jest dostępne na serwerze
- w środowisku ROOT piszemy makra, które mają rozszerzenie .c, .C, .cpp, lub .cxx
- makro zawiera w sobie kod w języku C++ interpretowany linijka po linijce
- w zasadzie nie musimy załączać żadnych bibliotek
- przykład 1:
{
double x = 5;
cout<<x<<endl;
}
- wywołanie makra: uruchamiamy środowisko (komenda
root
), wpisujemy .x macro.C
- makro może zawierać również funkcje, przykład 2:
int macro()
{
double x = 5;
cout<<x<<endl;
return 1;
}
- nazwa makra musi być taka sama jak nazwa funkcji w makrze (by można było je uruchomić komendą
.x macro.C
)
- w makrach może być więcej funkcji - przy standardowym uruchomieniu wywołana zawsze będzie ta funkcja, której nazwa zgadza się z nazwą makra (odpowiednik funkcji
main
w standardowym C++)
Wynik
Wykresy: