Skip to content

simonepigazzini/FuriousPlotter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FuriousPlotter

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).

Setup

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.

Configuration files

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) of OldBlock. This means that all the options defined in OldBlock are copied in NewBlock. The lines within the NewBlock modifies the content of the block, the first lines updates the value of the option src within the hist block with new_src (note that the value is changed for the hist block within NewBlock and not in OldBlock). new_src is appended so now hist.src holds three values first_src, second_src, new_src. In case new_src is an option defined in the cfg file its values are all appended to hist.src, if one particular value is specified (like new_src[2]) only that value is appended. If = is used instead of += the previous values of hist.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 search newvar within the existing options, CfgManager assumes that newvar 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 by oldopt in the zero position. Any position can be specified but it is mandatory to specify it (even position 0 as in the example).

The <draw> block

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 with gROOT::LoadMacro
    • A C++ shared library (.so). The library are loaded through ROOT.
    • A python module (.py). The module is loaded and any function defined in dictionary are loaded as a possible operation.
    • Any other type of string is processed with ROOT.ProcessLine(…)

The <plot> block

About

Everyday plots drawer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published