Skip to content

Refactoring plotting code

Davide Valsecchi requested to merge github/fork/mmarchegiani/plotting into main

Created by: mmarchegiani

The present PR consists in the refactoring of the plotting code. A system of composite classes is introduced to manage the plotting of Data and MC histograms together with their systematic uncertainties. The following classes are implemented:

  • PlotManager: class that manages multiple Shape objects and their plotting, taking the histogram configuration dictionary as input. The method plot_datamc_all() allows to plot all the histograms contained in the dictionary, for all years and categories.
  • Shape: class that stores the shapes of a 1D variable for multiple systematic variations in different categories and handles the plotting of the corresponding 1D data/MC histograms. Several methods for plotting are implemented to plot data and MC histograms and their ratio: plot_data(), plot_mc(), plot_datamc(), plot_datamc_ratio() and plot_datamc_all().
  • SystManager: class that handles the systematic uncertainties of 1D MC histograms, storing all the systematic uncertainties in a dictionary of SystUnc objects.
  • SystUnc: class that stores the information of a single systematic uncertainty of a 1D MC histogram. The built-in __add__() method implements the sum in quadrature of two systematic uncertainties, returning a SystUnc instance corresponding to their sum in quadrature. The plot() method plots the nominal, up and down variations of the corresponding systematic uncertainty.
  • Style: class that reads and stores the dictionary containing all the style parameters relevant to the plotting. One can define a custom style dictionary and pass it as an argument to the PlotManager constructor.

The plotting script is updated accordingly, and is now making use of the PlotManager class to produce all the plots. The parallelization of the plotting is currently done at the level of the plotting script by creating multiple PlotManager instances, but will be moved as a feature of the PlotManager class, so that a single instance has to be defined and the parallelization is done internally in PlotManager.

Merge request reports