May 1, 2025, Thursday, 120

KADD 2022 Laboratorium 1 EN

From Łukasz Graczykowski

(Difference between revisions)
Jump to: navigation, search
(Zadanie)
(Wynik)
 
(One intermediate revision not shown)
Line 43: Line 43:
* draw the graph in a separate window
* draw the graph in a separate window
-
== Uwagi ==
+
== Attention ==
-
* <b>Uwaga!</b> Aby środowisko ROOT można było uruchomić na własnym koncie użytkownika w laboratorium, należy w pliku <code>$HOME/.bashrc</code> dopisać następujące linijki (jeśli nie były dodane na zajęciach z PTI):
+
* <b>Attention!</b> 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 <code>$HOME/.bashrc</code> (they could had been added during the PTI class):
   export ROOTSYS=/opt/root
   export ROOTSYS=/opt/root
   export PATH=$PATH:$ROOTSYS/bin
   export PATH=$PATH:$ROOTSYS/bin
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib  
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib  
-
* środowisko ROOT jest zainstalowane lokalnie na każdym komputerze - nie jest dostępne na serwerze
+
* the ROOT environment is installed separately on each computer - it is not available on the server
-
* w środowisku ROOT piszemy <b>makra</b>, które mają rozszerzenie .c, .C, .cpp, lub .cxx
+
* in the ROOT environment  we write <b>macros</b>, which have extensions .c, .C, .cpp, or .cxx
-
* makro zawiera w sobie kod w języku C++ interpretowany linijka po linijce
+
* a macro contains a C++ code interpreted line-by-line
-
* w zasadzie nie musimy załączać żadnych bibliotek
+
* in principle, we do not need to include any libraries
-
* przykład 1:
+
* example 1:
  {
  {
     double x = 5;
     double x = 5;
     cout<<x<<endl;
     cout<<x<<endl;
  }
  }
-
* wywołanie makra: uruchamiamy środowisko (komenda <code>root</code>), wpisujemy <code>.x macro.C</code>
+
* execution of a macro: start the environment (command <code>root</code>), type <code>.x macro.C</code>
-
* makro może zawierać również <b>funkcje</b>, przykład 2:
+
* macro can also contain  <b>funkcje</b>, example 2:
  int macro()
  int macro()
  {
  {
Line 65: Line 65:
     return 1;
     return 1;
  }
  }
-
* nazwa makra musi być taka sama jak nazwa funkcji w makrze (by można było je uruchomić komendą <code>.x macro.C</code>)
+
* 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 <code>.x macro.C</code>)
-
* 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 <code>main</code> w standardowym 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

Contents

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:

  • window 1

Lab1 1.png

  • window 2

1 2.png