Writing on files

This is a Python notebook in which you will practice the concepts learned during the lectures.

Startup ROOT

Import the ROOT module: this will activate the integration layer with the notebook automatically


In [ ]:
import ROOT

Writing histograms

Create a TFile containing three histograms filled with random numbers distributed according to a Gaus, an exponential and a uniform distribution. Close the file: you will reopen it later.


In [2]:
# Your code here

Now, you can invoke the ls command from within the notebook to list the files in this directory. Check that the file is there. You can invoke the rootls command to see what's inside the file.


In [3]:
# Your invocations here

Access the histograms and draw them in Python. Remember that you need to create a TCanvas before and draw it too in order to inline the plots in the notebooks. You can switch to the interactive JavaScript visualisation using the %jsroot on "magic" command.


In [4]:
# Your code here

You can now repeat the exercise above using C++. Transform the cell in a C++ cell using the %%cpp "magic".


In [ ]:
# Your code here

Inspect the content of the file: TXMLFile

ROOT provides a different kind of TFile, TXMLFile. It has the same interface and it's very useful to better understand how objects are written in files by ROOT. Repeat the exercise above, either on Python or C++ - your choice, using a TXMLFILE rather than a TFile and then display its content with the cat command. Can you see how the content of the individual bins of the histograms is stored? And the colour of its markers? Do you understand why the xml file is bigger than the root one even if they have the same content?


In [ ]:
# Your invocations here