Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options for Compare Graphs and implemented script for nice plots with systematics #33

Merged
merged 17 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions CompareGraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import yaml
from rich import print

from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D
from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle, TLatex

import fempy
from fempy import logger as log
Expand Down Expand Up @@ -50,12 +50,16 @@
inObj.Scale(1./inObj.Integral())
if inputCfg['normalizecf']:
inObj.Scale(inputCfg['normalizecf'])
if 'shift' in inputCfg:
for iBin in range(inObj.GetNbinsX()):
inObj.SetBinContent(iBin+1, inObj.GetBinContent(iBin+1) + inputCfg['shift'])

inObj.SetLineColor(style.GetColor(inputCfg['color']))
inObj.SetMarkerColor(style.GetColor(inputCfg['color']))
inObj.SetLineWidth(inputCfg.get('thickness', 1))
drawOpts.append(inputCfg.get('drawopt', 'p' if isinstance(inObj, TH1) else 'pe'))
inObj.SetMarkerStyle(inputCfg['markerstyle'])
inObj.SetMarkerSize(inputCfg['markersize'])
inObjs.append(inObj)
legends.append(inputCfg['legend'])

Expand All @@ -66,6 +70,16 @@
pad = cPlot.cd(1)
pad.SetLogx(plot["opt"]["logx"])
pad.SetLogy(plot["opt"]["logy"])
if("padtopmargin" in plot["opt"]):
pad.SetTopMargin(plot["opt"]["padtopmargin"])
if("padbottommargin" in plot["opt"]):
pad.SetBottomMargin(plot["opt"]["padbottommargin"])
if("padrightmargin" in plot["opt"]):
pad.SetRightMargin(plot["opt"]["padrightmargin"])
if("padleftmargin" in plot["opt"]):
pad.SetLeftMargin(plot["opt"]["padleftmargin"])
if("ytitleoffset" in plot['opt']):
gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y")

fx1 = plot['opt']['rangex'][0]
fy1 = plot['opt']['rangey'][0]
Expand Down Expand Up @@ -96,6 +110,8 @@
if plot['opt']['leg']['sigma']:
legend += f'; #sigma={inObj.GetStdDev():.3f}'
leg.AddEntry(inObj, legend, 'lp')

inputlines = []
for line in plot['opt']['lines']:
x1 = plot['opt']['rangex'][0] if(line['coordinates'][0] == 'min') else line['coordinates'][0]
y1 = plot['opt']['rangey'][0] if(line['coordinates'][1] == 'min') else line['coordinates'][1]
Expand All @@ -105,11 +121,32 @@
inputline.SetLineColor(style.GetColor(line['color']))
inputline.SetLineWidth(line['thickness'])
inputline.Draw("same")
leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l")
inputlines.append(inputline)
if('legendtag' in line):
leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l")

leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C')
if('center' in plot['opt']['leg']):
leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C')
else:
leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']))
leg.Draw()

for text in plot['opt']['description']:
if('#' in text['text']):
tl = TLatex()
tl.SetTextSize(text['textsize'])
tl.SetTextFont(text['textfont'])
tl.DrawLatexNDC(text['position'][0], text['position'][1], text['text'])
cPlot.Modified()
cPlot.Update()
else:
tl = TLatex()
tl.SetTextSize(text['textsize'])
tl.SetTextFont(text['textfont'])
tl.DrawTextNDC(text['position'][0], text['position'][1], text['text'])
cPlot.Modified()
cPlot.Update()

# Compute ratio wrt the first obj
if plot['ratio']['enable']:
pad = cPlot.cd(panels['ratio'])
Expand Down
20 changes: 13 additions & 7 deletions cfg_compare_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,32 @@
rangex: [0, 10]
rangey: [800, 1600]
rebin: 1
ytitleoffset: some_value # Optional
padtopmargin: some_value # Optional
padbottommargin: some_value # Optional
padleftmargin: some_value # Optional
padrightmargin: some_value # Optional
logx: false
logy: false
title: ';variable (units);variable (units)'

lines: # Use lines: [] if you don't want to draw lines
- coordinates: [3,'min',3,'max'] # min, max for all range, otherwise coordinates
color: kRed
thickness: 2
legendtag: 'Example line'
description: # Use description: [] if you don't want text lines
- text: '#Lambda purity'
textfont: 43
textsize: 30
position: [0.5, 0.27]

lines: # Use lines: [] if you don't want to draw lines
- coordinates: ['min','min','max','max'] # min, max for all range, otherwise coordinates
- coordinates: [3,'min',3,'max'] # min, max for all range, otherwise coordinates
color: kRed
thickness: 2
legendtag: 'Example line'
legendtag: 'Example line' # Optional

ext: [pdf]

leg:
header: 'Legend header'
center: null # Optional, true to center
posx: [0.5, 0.9]
posy: [0.7, 0.9]
sigma: false
Expand Down
5 changes: 4 additions & 1 deletion fempy/sim/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from . import alice3
import os
# If you want to import alice3 sw add `export FEMPY_ALICE3=true` to your .bashrc
if os.getenv("FEMPY_ALICE3", 'false').lower() in ('true', '1'):
from . import alice3
5 changes: 4 additions & 1 deletion fempy/sim/alice3/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from . import alice3
import os
# If you want to import alice3 sw add `export FEMPY_ALICE3=true` to your .bashrc
if os.getenv("FEMPY_ALICE3", 'false').lower() in ('true', '1'):
from . import alice3
Loading