Skip to content

HarryPlotter

Olena Hlushchenko edited this page Mar 12, 2020 · 26 revisions

This tutorial/documentation is superseded by Artus/wiki/HarryPlotter-Overview.

This tutorial uses the outputs of the synchonisation analysis as described in Running Artus. The ROOT output file is denoted by output.root. It can be the output of an individual run, the one of an individual job or the merged output file.

Individual checkout recipe

HarryPlotter is part of the Artus repository. To only check out HarryPlotter, do the following:

git clone --branch dictchanges_CMSSW102 [email protected]:artus-analysis/Artus.git -n
cd Artus
git remote add -f Artus [email protected]:artus-analysis/Artus.git
git config core.sparsecheckout true
echo "/HarryPlotter/" >> .git/info/sparse-checkout
echo "/Utility/python/" >> .git/info/sparse-checkout
echo "/Utility/scripts/" >> .git/info/sparse-checkout
git pull

git read-tree --empty
git read-tree -mu HEAD

General Basics

The Artus run consisted of several pipelines. Each pipeline creates a separated TDirectory in the ROOT file and can be identified by looking into the file or the configuration.

artusPipelines.py output.root

This should produce an output similar to

em
et
mt
tt

Each pipeline writes several objects into this directory:

get_root_file_content.py output.root

gives something similar to

config (TObjString)
em/ntuple (TTree)
em/cutFlowUnweighted (TH1F)
em/cutFlowWeighted (TH1F)
et/ntuple (TTree)
et/cutFlowUnweighted (TH1F)
et/cutFlowWeighted (TH1F)
mt/ntuple (TTree)
mt/cutFlowUnweighted (TH1F)
mt/cutFlowWeighted (TH1F)
tt/ntuple (TTree)
tt/cutFlowUnweighted (TH1F)
tt/cutFlowWeighted (TH1F)
...

HarryPlotter provides the executable harry.py. This script is extended with analysis-specific needs and then called higgsplot.py. Basic functionallity is possible with harry.py [-h], but here it is always referred to higgsplot.py [-h].

HarryPlotter can read in ROOT histograms, graphs and similar objects as well as create histograms or graphs from trees. Possible quantities to plot can be obtained with the following command:

higgsplot.py -i <input> -f <folder> --quantities

Based on the example, one could do

higgsplot.py -i output.root -f mt/ntuple --quantities
higgsplot.py -i output.root -f mt --quantities

which then gives

List of all tree quantities (in the first file):
	eta_1 (Float_t)
	eta_2 (Float_t)
	m_vis (Float_t)
	pt_1 (Float_t)
	pt_2 (Float_t)
	weight (Float_t)
...

and

List of all histogram/graph/function quantities (in the first file):
	cutFlowUnweighted (TH1F)
	cutFlowWeighted (TH1F)

This works for every ROOT file and is not limited to Artus outputs. HarryPlotter can plot contents of arbitrary ROOT files.

Plotting Examples

Basic Plots from Trees

1D histogram

higgsplot.py -i output.root -f mt/ntuple -x m_vis

plots/histogram_from_tree.png

1D histogram with weights and selection

higgsplot.py -i output.root -f mt/ntuple -x m_vis -w weight
higgsplot.py -i output.root -f mt/ntuple -x m_vis -w "weight*(eta_1>0)"

plots/histogram_weight.png plots/histogram_weight_selection.png

1D histogram with binning

higgsplot.py -i output.root -f mt/ntuple -x m_vis --x-bins "15,20,170"
higgsplot.py -i output.root -f mt/ntuple -x m_vis --x-bins "15 30 45 60 75 90 105 120 170 220 270"

plots/histogram_binning_1.png plots/histogram_binning_2.png

More 1D histograms

higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis [--labels MT ET --legend 0.5 0.6 0.8 0.8]
higgsplot.py -i output.root -f mt/ntuple -x m_vis "m_vis+10" [--labels m "m+10" --legend 0.5 0.6 0.8 0.8]

plots/two_histograms_1.png plots/two_histograms_2.png

2D histogram

higgsplot.py -i output.root -f mt/ntuple -x eta_1 -y pt_1 -m COLZ

plots/2d_histogram.png

1D profile histogram

higgsplot.py -i output.root -f mt/ntuple -x eta_1 -y pt_1 --tree-draw-options prof -m E

plots/profile_histogram.png

Basic Plots from (Drawable) ROOT Objects

Histogram

higgsplot.py -i output.root -f mt -x cutFlowWeighted

plots/histogram_from_root.png

Using Analysis Modules

Modules and their Options

higgsplot.py --list-available-modules
higgsplot.py --analysis-modules <modules> -h

Histogram normalised to unity

higgsplot.py -i output.root -f mt/ntuple -x m_vis --analysis-modules NormalizeToUnity

plots/histogram_normalised.png

Ratio of two histograms

higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --analysis-modules Ratio
higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --analysis-modules Ratio --nicks mt et --ratio-numerator-nicks mt --ratio-denominator-nicks et --ratio-result-nicks ratio

These two commands are equivalent. plots/ratio_subplot_1.png plots/ratio_subplot_2.png

More Sophisticated Plots

Stacked histograms

higgsplot.py -i output.root -f mt/ntuple et/ntuple mt/ntuple -x m_vis -w weight weight "1.5*weight" --stacks mc mc data -m HIST HIST E --colors kGreen kRed kBlack
higgsplot.py -i output.root -f mt/ntuple et/ntuple mt/ntuple -x m_vis -w weight weight "1.5*weight" --stacks mc mc data -m HIST HIST E E --colors kGreen kRed kBlack kBlack --nicks mc1 mc2 data --analysis-modules Ratio --ratio-numerator-nicks data --ratio-denominator-nicks "mc1 mc2"

plots/histogram_stack_1.png plots/histogram_stack_2.png

Sum of inputs

higgsplot.py -i output.root -f "mt/ntuple et/ntuple" -x m_vis
higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --nicks mc mc
higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --nicks mt_noplot et_noplot --analysis-modules AddHistograms --add-nicks "mt_noplot et_noplot" --add-result-nicks sum

These three commands are equivalent, although the automatically chosen binning can make them look different. This can be changed specifying --x-bins. plots/sum_inputs_1.png plots/sum_inputs_2.png plots/sum_inputs_3.png

Formatting

Labels and titles

higgsplot.py -i output.root -f mt/ntuple -x eta_1 -y pt_1 --tree-draw-options prof -m E --x-label "#eta(#mu)" --y-label "p_{T}(#mu) / GeV" --title Title
higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --analysis-modules Ratio --x-label "m_{vis} / GeV" --y-subplot-label "Data/MC"

plots/labels_1.png plots/labels_2.png

Markers and legends

higgsplot.py -i output.root -f mt/ntuple et/ntuple mt/ntuple -x m_vis -w weight weight "1.5*weight" --stacks mc mc data -m HIST HIST E E --colors kGreen kRed kBlack kBlack --nicks mc1 mc2 data --analysis-modules Ratio --ratio-numerator-nicks data --ratio-denominator-nicks "mc1 mc2" --labels "Bkg. 1" "Bkg. 2" "Data" "" --legend 0.7 0.65 0.9 0.85 --legend-markers F F ELP ""
higgsplot.py -i output.root -f mt/ntuple -x m_vis -w 4 3 2 1 -m E LINE LINE HIST --line-styles 1 2 1 1 --line-widths 1 2 3 1 --legend 0.6 0.65 0.9 0.85 --legend-markers ELP L L F --labels points "dashed line" line filled

plots/labels_1.png plots/labels_2.png

Colors

higgsplot.py -i output.root -f mt/ntuple et/ntuple mt/ntuple -x m_vis -w weight weight "1.5*weight" --stacks mc mc data -m HIST HIST E --colors "#220088" kYellow 1

plots/colors.png

Axis ranges

higgsplot.py -i output.root -f mt/ntuple -x eta_1 -y pt_1 --tree-draw-options prof -m E --y-lims 40 50
higgsplot.py -i output.root -f mt/ntuple et/ntuple -x m_vis --analysis-modules Ratio --y-subplot-lims 0 2 --x-lims 0 750

plots/axis_ranges_1.png plots/axis_ranges_2.png

Clone this wiki locally