582 Chapter 10. Software for Data Analysis
Interface Mode:This is perhaps the most common use of ROOT since in
this mode the classes of ROOT are used to develop a custom analysis package
according to the particular needs.
Since C++ is the programming language for ROOT therefore all the commands
must be C++ commands. For some, this is a disadvantage since it requires getting
familiar with C++. But for those, who already know C++, using ROOT is a simple
matter. One thing that should be pointed out here is that for small to moderate
analysis tasks, one only needs to know the basic C++ methods and therefore one
can essentially start working with ROOT while learning C++.
A.6 Examples
Now that we have some idea of what ROOT is and how it can be used, let us have
a look at some practical examples of its usage.
Figure 10.1.7: Screen dump of ROOT output to three text display commands.
We will start with the most basic of C and C++ commands in the interactive
mode of ROOT. We want to see if CINT accepts standard output commands of C
and C++. Fig.10.1.7 shows the screen dump of this exercise. It is apparent that
the CINT syntax is exactly the same as that of C and C++. The first command is
a C++ output stream command, which by default sends the output to the screen
display. The second is a C command to display a text. In the third, a loop has been
introduced that prints out a sentence five times on the screen.
As mentioned earlier, it is also possible to write all the commands in a file and
then run it as a macro. To show how this is done, we will write all the above
commands in a file namedexample1.C(see Fig.10.1.8) and then run it from ROOT.
The macro can be executed with the command .x example1.C as shown in Fig.10.1.9.
Let us now go to a a little more involved example. Suppose we have some ex-
perimental data and we want not only to plot it but also to perform a regression
fit. We will first write a macro to plot the data. For simplicity we will hardwire the
data into the macro, which in fact is not a good practice. Usually one would read
the data from a file using standard C or C++ commands. The macro together with
comments explaining different commands is shown in Fig.10.1.10.