This python script is meant to provide an interface to ROOT when dealing with TTrees and plots. With FP you can:
- Draw plots from trees
- Draw plots from objects stored in ROOT files (TH1, TH2, TGraph, …)
- Combine histograms from different trees and different files into the same canvas.
- Manipulate the input histogram(s) with predefined operations (Sum, difference, multiplication, …) or custom function provided as python plugins.
- Read and create TTrees without writing all the Branch/SetBranchAddress (done through DynamicTTree).
FuriousPlotter relies on two other piece of code: CfgManager and DynamicTTree. The first one is essential,
the second one is needed only to use the --make-trees
funtionality.
Installation instructions:
git clone https://github.com/simonepigazzini/FuriousPlotter.git
cd FutiousPlotter/
git clone https://github.com/simonepigazzini/CfgManager.git
git clone https://github.com/simonepigazzini/DynamicTTree.git
(optional)cd CfgManager/; make
(optional:cd make install
).cd -
cd DynamicTTree/; make
(optional:cd make install
).cd -
Now FP should work fine, if you want to install it on the system just run:
sudo make install
. This will install the main scripts together with the basic operations and style macros.
FuriousPlotter options are controlled by the configuration file provided through the -c
command line option.
The configuration file is parsed with CfgManager which handles the options. CfgManager sintax allows to define
blocks (<NewBlock>
) and single options (src test.root testTree
), both single options and blocks can be copied
or updated. A dot (.
) is used to access options within blocks. Blocks can be nested, so the expression
blockA.blockB.myopt
will access option myopt
in blockB
which in turn is defined inside blockA
.
By default the first option value from myopt
is read, in order to specify a particular value within
the option use the []
operator: blockA.blockB.myopt[3]
, this will read the third value in myopt
Each configuration files can import options from other files (import is specified with the importCfg
keyword).
CfgManager parses options using whitespaces and linebreaks as delimeters: to prevent it from splitting an option
containing whitespaces one has to surround it with single quotes ( src 'My file.root'
).
CfgManager allows to define simple for loops:
- Range based loops (in the example
i
runs from 0 to 100 excluded):for i 0 100 loop lines... end
- For each loops (where
items
is an option already defined in the cfg file):items 0 10 11 17 for i items loop lines... end
Each occurence of $i
where i
is the counter variable is replaced with its current value
(assuming i=5 in the current loop cycle: plot_number_$i
—> plot_number_5
).
- Example on how to use copy and append:
<OldBlock> histos hist <hist> src first_src second_src var 'myvar' cut 'selection > 20' bins 100 0 1 </hist> </OldBlock> <NewBlock= OldBlock> hist.src+= new_src hist.var newvar </NewBlock>
In this example
OldBlock
is a typical plot definition within FP.NewBlock
is defined as a copy (note the space between the ‘=’ character and the following block name) ofOldBlock
. This means that all the options defined inOldBlock
are copied inNewBlock
. The lines within theNewBlock
modifies the content of the block, the first lines updates the value of the optionsrc
within thehist
block withnew_src
(note that the value is changed for thehist
block withinNewBlock
and not inOldBlock
).new_src
is appended so nowhist.src
holds three valuesfirst_src
,second_src
,new_src
. In casenew_src
is an option defined in the cfg file its values are all appended tohist.src
, if one particular value is specified (likenew_src[2]
) only that value is appended. If = is used instead of += the previous values ofhist.src
are overwritten by the values of the specified options. A similar behaviour occours in the next line (hist.var newvar
) with the difference that in this case no attempt is made to searchnewvar
within the existing options, CfgManager assumes thatnewvar
is a value not an option.- Option evaluation:
options can be evaluated using the following syntax:
newopt $oldopt[0]
, this lines defines a new option (newopt
) and assign to it the value holded byoldopt
in the zero position. Any position can be specified but it is mandatory to specify it (even position 0 as in the example).
- Option evaluation:
options can be evaluated using the following syntax:
The <draw>
block is the main block and is used to configure global options within FP.
List of options within the <draw>
block:
plots
: the names of the plots to be drawn. A block named after the plot is mandatory to define the plot configuration.outDir
: the location of the output direcotry (if left black plots will be saved in./plots
).saveAs
: mandatory. Specify the type of output files as accepted by ROOT::TCanvas::SaveAs.postProcCommands
: a list of bash commands executed after drawing all the plots.plugins
: list of plugins loaded before the execution of the program. A plugin can be:- A ROOT macro with file extension
.C
. This file are compiled and loaded withgROOT::LoadMacro
- A C++ shared library (
.so
). The library are loaded through ROOT. - A python module (
.py
). The module is loaded and any function defined indictionary
are loaded as a possible operation. - Any other type of string is processed with ROOT.ProcessLine(…)
- A ROOT macro with file extension