My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

ROOT 7 Boxes

Omar Ahmed's photo
Omar Ahmed
·Jun 6, 2020

WHAT IS ROOT?

ROOT is a scientific software toolkit. It is used to deal with big data processing, statistical analysis, visualization, and storage. The software is developed mainly in C++. Also, it contains python and R bindings.

PREREQUISITES

Readers of this post should know the basics of programming and Intermediate knowledge of c++.

Note

This tutorial is done on UBUNTU 16.04. It should also work on other UBUNTU releases. If you have a different operating system, you could see the equivalent command on your operating system. All these commands are simple, and you can find their equivalent commands relevant to your operating system easily.

How To Use ROOT 7?

1. Make sure CMake is the latest version

You should make sure that CMake version is >= 3.9. To check your current CMake version, run this command in a Linux terminal.

CMake --version

If you found that CMake version is outdated, download the latest version relevant to your operating system from here.

2. Build ROOT from source

To build ROOT source code, you could simply follow the steps described in the building root 7 section in this page.

3. Execute ROOT 7 examples

After the building is successful, follow these steps:

  1. Navigate to your root 7 build folder, and open a terminal in this path
    cd your_root_clone_path/root/root7_build
    
  2. Execute this command in the opened terminal
    source bin/thisroot.sh
    
  3. In this opened terminal, you could run any .cxx file with ROOT code with this command
    root your_root_code_file.cxx
    

Now, after all, is successfully setup we could begin in ROOT 7 boxes. You could find some ROOT 7 examples in this path your_root_clone_path/root/tutorials/v7/

ROOT 7 Boxes

Boxes are rectangles drawn on the screen and generated using the normal coordinate system. We will illustrate, how to draw boxes using this example. You can also find this example in your_root_clone_path/root/tutorials/v7/box.cxx.
Note, This example could change, as this documentation is under development.

#include "ROOT/RCanvas.hxx"
#include "ROOT/RColor.hxx"
#include "ROOT/RBox.hxx"
#include <ROOT/RPadPos.hxx>
void box()
{
   using namespace ROOT::Experimental;
   // Create a canvas to be displayed.
   auto canvas = RCanvas::Create("Canvas Title");
   auto Box1 = canvas->Draw<RBox>(RPadPos(0.1_normal, 0.3_normal),                                                                  
                                      RPadPos(0.3_normal,0.6_normal));
   RColor Color1(255, 0, 0, 0.5); // 50% opaque
   RColor Color2(0, 0, 255, 0.3); // 30% opaque
   Box1->AttrBox().AttrBorder().SetColor(Color1).SetWidth(5);
   Box1->AttrBox().AttrFill().SetColor(RColor::kRed);
   auto Box2 = canvas->Draw<RBox>(RPadPos(0.4_normal, 0.2_normal), 
                                      RPadPos(0.6_normal,0.7_normal));
   Box2->AttrBox().AttrBorder().SetColor(Color2).SetStyle(2).SetWidth(3);
   Box2->AttrBox().AttrFill().SetColor(RColor::kGreen);
   auto Box3 = canvas->Draw<RBox>(RPadPos(0.7_normal, 0.4_normal), 
                                      RPadPos(0.9_normal,0.6_normal));
   Box3->AttrBox().AttrBorder().SetWidth(3);
   Box3->AttrBox().AttrFill().SetColor(RColor::kBlue);
   auto Box4 = canvas->Draw<RBox>(RPadPos(0.7_normal, 0.7_normal), 
                                      RPadPos(0.9_normal,0.9_normal));
   //OptsBox4->SetFillStyle(0);
   //OptsBox4->SetRoundWidth(50);
   //OptsBox4->SetRoundHeight(25);
   Box4->AttrBox().AttrBorder().SetWidth(3);
   auto Box5 = canvas->Draw<RBox>(RPadPos(0.7_normal, 0.1_normal), 
                                      RPadPos(0.9_normal,0.3_normal));
   //OptsBox5->SetFillStyle(0);
   //OptsBox5->SetRoundWidth(25);
   //OptsBox5->SetRoundHeight(50);
   Box5->AttrBox().AttrBorder().SetWidth(3);
   canvas->Show();
}

Try to run this example before we go further to see the output. You will find this code open localhost on your browser with 5 drawn boxes on the screen.

First, we included the header files that we will use in our program. To use ROOT 7 functionalities, we should use the ROOT::Experimental namespace.

RCanvas::Create
The canvas is like a screen to draw on. We need to create a canvas at the beginning of our program. Create is used to create a canvas. It takes a string as a parameter to specify the name of our canvas.

Draw<RBox>()
Draw is a method of canvas class. It is used to draw shapes on the canvas. We specify the shape drawn by the Draw function by passing RBox as a type to specify that we will draw a ROOT Box. Draw takes 2 parameters to specify the coordinates of drawing the box on the canvas. The 2 parameters specify the top left corner of the box, and the bottom right corner respectively.

RColor
This class is used to specify a color in RGBA format.

AttrBox().AttrBorder().SetColor().SetWidth(5)
We use Box class methods to select the border attributes then set the color and the width of the border.

canvas->Show()
Show is a canvas class method for starting the canvas. If we didn't show the canvas, nothing will happen when we run the code.

This is the main classes and methods in this code for further knowledge, refer to the useful resources section.

Useful Resources

This resources are used to write this small tutorial:
ROOT WEBSITE
ROOT REPOSITORY
ROOT 7 REFERENCE GUIDE
ROOT 7 GETTING STARTED