From 18db05974f6541f0097e36d6db61b5049ba92eea Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 10:30:15 +0100 Subject: [PATCH 01/17] added option for marker size --- CompareGraphs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/CompareGraphs.py b/CompareGraphs.py index 2c6a0ae..1a34a22 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -56,6 +56,7 @@ 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']) From 1af771eadd86b0a3a53e8670dd3b138350bf9474 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 10:39:43 +0100 Subject: [PATCH 02/17] added options for pad margins --- CompareGraphs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CompareGraphs.py b/CompareGraphs.py index 1a34a22..46a8b63 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -67,6 +67,15 @@ pad = cPlot.cd(1) pad.SetLogx(plot["opt"]["logx"]) pad.SetLogy(plot["opt"]["logy"]) + if(plot["opt"]["padtopmargin"]): + pad.SetTopMargin(plot["opt"]["padtopmargin"]) + if(plot["opt"]["padbottommargin"]): + pad.SetBottomMargin(plot["opt"]["padbottommargin"]) + if(plot["opt"]["padrightmargin"]): + pad.SetRightMargin(plot["opt"]["padrightmargin"]) + if(plot["opt"]["padleftmargin"]): + pad.SetLeftMargin(plot["opt"]["padleftmargin"]) + fx1 = plot['opt']['rangex'][0] fy1 = plot['opt']['rangey'][0] From d83db6b188659a71222b7eb45af9e38acbf56a5a Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 10:45:57 +0100 Subject: [PATCH 03/17] added option for y axis title shift --- CompareGraphs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index 46a8b63..1c7676d 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -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 import fempy from fempy import logger as log @@ -75,7 +75,9 @@ pad.SetRightMargin(plot["opt"]["padrightmargin"]) if(plot["opt"]["padleftmargin"]): pad.SetLeftMargin(plot["opt"]["padleftmargin"]) - + if(plot['opt']['ytitleoffset'] is not None): + print(plot['opt']['ytitleoffset']) + gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y") fx1 = plot['opt']['rangex'][0] fy1 = plot['opt']['rangey'][0] From ec3728396ed1d7e54cc6ea0dc3d9f1aff451cd70 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 12:07:15 +0100 Subject: [PATCH 04/17] added macro to compare graphs with syst unc --- CompareWithSystematics.py | 367 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 CompareWithSystematics.py diff --git a/CompareWithSystematics.py b/CompareWithSystematics.py new file mode 100644 index 0000000..0d563af --- /dev/null +++ b/CompareWithSystematics.py @@ -0,0 +1,367 @@ +import argparse +import os +import yaml +from rich import print + +from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle + +import fempy +from fempy import logger as log +from fempy.utils.format import TranslateToLatex +from fempy.utils.io import Load +from fempy.utils import style + +parser = argparse.ArgumentParser(description='Arguments') +parser.add_argument('cfg') +args = parser.parse_args() + +# Load configuration file +with open(args.cfg, "r") as stream: + try: + cfg = yaml.safe_load(stream) + except yaml.YAMLError: + log.critical('Yaml file not loaded') + +style.SetStyle() + +for plot in cfg: + plot = plot["plot"] + + panels = {'default': 1} + if plot['ratio']['enable']: + panels['ratio'] = len(panels)+1 + if plot['relunc']['enable']: + panels['relunc'] = len(panels)+1 + + # Load the objects to draw + graphsStat = [] + graphsSyst = [] + legends = [] + drawOpts = [] + for inputCfg in plot["input"]: + inFile = TFile(inputCfg['file']) + + inObjStat = Load(inFile, inputCfg['histostat']) + inObjSyst = Load(inFile, inputCfg['histosyst']) + + if isinstance(inObjStat, TH1): + inObjStat.SetDirectory(0) + inObjStat.Rebin(inputCfg['rebin']) + + if inputCfg['normalize']: + inObjStat.Scale(1./inObjStat.Integral()) + if inputCfg['normalizecf']: + inObjStat.Scale(inputCfg['normalizecf']) + + statErr = TGraphAsymmErrors(inObjStat) + systErr = TGraphAsymmErrors(inObjSyst) + + statErr.SetLineColor(style.GetColor(inputCfg['color'])) + statErr.SetMarkerColor(style.GetColor(inputCfg['color'])) + statErr.SetLineWidth(inputCfg.get('thickness', 1)) + statErr.SetMarkerStyle(inputCfg['markerstyle']) + statErr.SetMarkerSize(inputCfg['markersize']) + systErr.SetLineColor(style.GetColor(inputCfg['color'])) + systErr.SetMarkerColor(style.GetColor(inputCfg['color'])) + systErr.SetLineWidth(inputCfg.get('thickness', 1)) + systErr.SetMarkerStyle(inputCfg['markerstyle']) + systErr.SetMarkerSize(inputCfg['markersize']) + systErr.SetFillColor(style.GetColor(inputCfg['color'])) + if(inputCfg['fillstylesyst'] is not None): + systErr.SetFillStyle(inputCfg['fillstylesyst']) + systErr.SetFillColorAlpha(style.GetColor(inputCfg['color']), inputCfg['fillalphasyst']) + + for iPoint in range(inObjStat.GetNbinsX()): + errX = inObjStat.GetBinWidth(iPoint)/4 + statErr.SetPointEXlow(iPoint, errX*2) + statErr.SetPointEXhigh(iPoint, errX*2) + systErr.SetPointEXlow(iPoint, errX) + systErr.SetPointEXhigh(iPoint, errX) + + graphsStat.append(statErr) + graphsSyst.append(systErr) + + legends.append(inputCfg['legend']) + + drawOpts.append(inputCfg.get('drawopt', 'p' if isinstance(statErr, TH1) else 'pe')) + # Define the canvas + nPanelsX, nPanelsY = fempy.utils.GetNPanels(len(panels)) + cPlot = TCanvas("cPlot", "cPlot", 600*nPanelsX, 600*nPanelsY) + cPlot.Divide(nPanelsX, nPanelsY) + pad = cPlot.cd(1) + pad.SetLogx(plot["opt"]["logx"]) + pad.SetLogy(plot["opt"]["logy"]) + if(plot["opt"]["padtopmargin"]): + pad.SetTopMargin(plot["opt"]["padtopmargin"]) + if(plot["opt"]["padbottommargin"]): + pad.SetBottomMargin(plot["opt"]["padbottommargin"]) + if(plot["opt"]["padrightmargin"]): + pad.SetRightMargin(plot["opt"]["padrightmargin"]) + if(plot["opt"]["padleftmargin"]): + pad.SetLeftMargin(plot["opt"]["padleftmargin"]) + if(plot['opt']['ytitleoffset'] is not None): + print(plot['opt']['ytitleoffset']) + gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y") + + fx1 = plot['opt']['rangex'][0] + fy1 = plot['opt']['rangey'][0] + fx2 = plot['opt']['rangex'][1] + fy2 = plot['opt']['rangey'][1] + pad.DrawFrame(fx1, fy1, fx2, fy2, TranslateToLatex(plot['opt']['title'])) + + legx1 = plot['opt']['leg']['posx'][0] + legy1 = plot['opt']['leg']['posy'][0] + legx2 = plot['opt']['leg']['posx'][1] + legy2 = plot['opt']['leg']['posy'][1] + leg = TLegend(legx1, legy1, legx2, legy2) + + for iObj, (inObjStat, inObjSyst, legend) in enumerate(zip(graphsStat, graphsSyst, legends)): + inObjStat.Draw(inputCfg['drawoptstat']) + inObjSyst.Draw(inputCfg['drawoptsyst']) + + # Compute statistics for hist in the displayed range + if isinstance(inObjStat, TH1): + firstBin = inObjStat.FindBin(plot['opt']['rangex'][0]*1.0001) + lastBin = inObjStat.FindBin(plot['opt']['rangex'][1]*0.9999) + inObjStat.GetXaxis().SetRange(firstBin, lastBin) + print(f'{legend}: mean = {inObjStat.GetMean()} sigma = {inObjStat.GetStdDev()}') + if plot['opt']['leg']['mean']: + legend += f'; #mu={inObjStat.GetMean():.3f}' + if plot['opt']['leg']['sigma']: + legend += f'; #sigma={inObjStat.GetStdDev():.3f}' + leg.AddEntry(inObjStat, legend, 'lp') + + if(plot['opt']['leg']['center']): + leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') + else: + leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header'])) + + leg.Draw() + + cPlot.Modified() + cPlot.Update() + + # save canvas + for ext in plot["opt"]["ext"]: + cPlot.SaveAs(f'{os.path.splitext(plot["output"])[0]}.{ext}') + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#import argparse +#import os +#import yaml +#import numpy as np +#from rich import print +# +#from ROOT import TFile, TCanvas, TH1, TLegend, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, TBox, TLatex, TText +# +#import fempy +#from fempy import logger as log +#from fempy.utils.format import TranslateToLatex +#from fempy.utils.io import Load +#from fempy.utils import style +# +#parser = argparse.ArgumentParser(description='Arguments') +#parser.add_argument('cfg') +#args = parser.parse_args() +# +## Load configuration file +#with open(args.cfg, "r") as stream: +# try: +# cfg = yaml.safe_load(stream) +# except yaml.YAMLError: +# log.critical('Yaml file not loaded') +# +#style.SetStyle() +# +#for plot in cfg: +# plot = plot["plot"] +# +# nInputs = len(plot['input']) +# panels = {'default': 1} +# if(nInputs>1): +# panels['uncratio'] = len(panels)+1 +# +# # Define the canvas +# nPanelsX, nPanelsY = fempy.utils.GetNPanels(len(panels)) +# cPlot = TCanvas("cPlot", "cPlot", 600*nPanelsX, 600*nPanelsY) +# cPlot.Divide(nPanelsX, nPanelsY) +# pad = cPlot.cd(1) +# pad.SetLogx(plot["opt"]["logx"]) +# pad.SetLogy(plot["opt"]["logy"]) +# +# fx1 = plot['opt']['rangex'][0] +# fy1 = plot['opt']['rangey'][0] +# fx2 = plot['opt']['rangex'][1] +# fy2 = plot['opt']['rangey'][1] +# print(fx1) +# pad.DrawFrame(fx1, fy1, fx2, fy2, TranslateToLatex(plot['opt']['title'])) +# +# boxes = [] +# inObjStatGraphs = [] +# legends = [] +# +# # Load the objects to draw +# for inputCfg in plot["input"]: +# inFile = TFile(inputCfg['file']) +# +# inObjStat = Load(inFile, inputCfg['name']) +# legends.append(inputCfg['legend']) +# print(inputCfg['legend']) +# if(isinstance(inObjStat, TH1)): +# inObjStat.SetDirectory(0) +# inObjStat.Rebin(inputCfg['rebin']) +# if inputCfg['normalize']: +# inObjStat.Scale(1./inObjStat.Integral()) +# +# binCenters = [] +# binWidths = [] +# binContents = [] +# binErrors = [] +# for iBin in range(inObjStat.GetNbinsX()): +# binCenters.append(inObjStat.GetBinCenter(iBin + 1)) +# binWidths.append(inObjStat.GetBinWidth(iBin + 1)) +# binContents.append(inObjStat.GetBinContent(iBin +1)) +# binErrors.append(inObjStat.GetBinError(iBin + 1)) +# if(nInputs==1): +# if(inputCfg['errbarfillcolor'] is not None): +# box = TBox(binCenters[-1] - binWidths[-1]/4, binContents[-1] - binErrors[-1], +# binCenters[-1] + binWidths[-1]/4, binContents[-1] + binErrors[-1]) +# box.SetFillStyle(inputCfg['errbarfillstyle']) +# box.SetFillColorAlpha(inputCfg['errbarfillcolor'], inputCfg['errbarfillalpha']) +# #box.Draw('same') +# boxes.append(box) +# binCentersNp = np.array(binCenters, dtype='double') +# binContentsNp = np.array(binContents, dtype='double') +# binXErrLowNp = np.array([binWidth/2 for binWidth in binWidths], dtype='double') +# binXErrUppNp = np.array([binWidth/2 for binWidth in binWidths], dtype='double') +# binYErrLowNp = np.array([binErr/2 for binErr in binErrors], dtype='double') +# binYErrUppNp = np.array([binErr/2 for binErr in binErrors], dtype='double') +# inObjStatGraph = TGraphAsymmErrors(inObjStat.GetNbinsX(), binCentersNp, binContentsNp, binXErrLowNp, +# binXErrUppNp, binYErrLowNp, binYErrUppNp) +# inObjStatGraph.GetXaxis().SetLimits(fx1, fx2) +# inObjStatGraph.GetYaxis().SetLimits(fy1, fy2) +# inObjStatGraph.GetXaxis().SetRangeUser(fx1, fx2) +# inObjStatGraph.GetYaxis().SetRangeUser(fy1, fy2) +# inObjStatGraph.SetLineColor(style.GetColor(inputCfg['color'])) +# inObjStatGraph.SetMarkerColor(style.GetColor(inputCfg['color'])) +# inObjStatGraph.SetMarkerStyle(inputCfg['markerstyle']) +# inObjStatGraph.SetMarkerSize(inputCfg['markersize']) +# inObjStatGraph.SetTitle(TranslateToLatex(plot['opt']['title'])) +# inObjStatGraphs.append(inObjStatGraph) +# print('ciao') +# inObjStatGraph.Draw('same ap') +# +# cPlot.Modified() +# cPlot.Update() +# +# if(nInputs==1): +# for iBox in boxes: +# cPlot.Modified() +# cPlot.Update() +# iBox.Draw('same') +# +# #print(len(inObjStatGraphs)) +# #for inObjStatGraph in inObjStatGraphs: +# # cPlot.Modified() +# # cPlot.Update() +# # inObjStatGraph.Draw('same ap') +# +# cPlot.Modified() +# cPlot.Update() +# +# legx1 = plot['opt']['leg']['posx'][0] +# legy1 = plot['opt']['leg']['posy'][0] +# legx2 = plot['opt']['leg']['posx'][1] +# legy2 = plot['opt']['leg']['posy'][1] +# leg = TLegend(legx1, legy1, legx2, legy2) +# +# print(inObjStatGraphs) +# print(legends) +# print(len(boxes)) +# for (inObjStatGraph, legend) in zip(inObjStatGraphs, legends): +# leg.AddEntry(inObjStatGraph, legend, 'lp') +# +# leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') +# if(plot['opt']['leg']['enable']): +# 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() +# +# if(nInputs==1): +# pad = cPlot.cd(panels['uncratio']) +# pad.SetLogx(plot['ratio']['logx']) +# pad.SetLogy(plot['ratio']['logy']) +# x1 = plot['opt']['rangex'][0] +# y1 = plot['ratio']['rangey'][0] +# x2 = plot['opt']['rangex'][1] +# y2 = plot['ratio']['rangey'][1] +# frame = pad.DrawFrame(x1, y1, x2, y2, 'Rel. Unc. comparison') +# frame.GetYaxis().SetTitle('Ratio') +# hDen = inObjStats[0].Clone() +# hDen.Rebin(plot['ratio']['rebin']) +# hDen.Sumw2() +# +# if isinstance(inObjStat, TH1): +# for inObjStat in inObjStats[1:]: +# hRatio = inObjStat.Clone() +# hRatio.Rebin(plot['ratio']['rebin']) +# hRatio.Divide(hDen) +# hRatio.Draw('same pe') +# else: +# log.error('Ratio for type %s is not implemented. Skipping this object', type(inObjStat)) +# continue +# +# line = TLine(plot['opt']['rangex'][0], 1, plot['opt']['rangex'][1], 1) +# line.SetLineColor(13) +# line.SetLineStyle(7) +# line.Draw('same pe') +# +# cPlot.Modified() +# cPlot.Update() +# +# # save canvas +# for ext in plot["opt"]["ext"]: +# cPlot.SaveAs(f'{os.path.splitext(plot["output"])[0]}.{ext}') \ No newline at end of file From 729016703718b2698d2e36d8c1fe3dfc10288e3c Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 12:32:12 +0100 Subject: [PATCH 05/17] option to avoid legend header centering --- CompareGraphs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index 1c7676d..efc64bd 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -119,7 +119,10 @@ inputline.Draw("same") leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") - leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') + if(plot['opt']['leg']['center']): + leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') + else: + leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header'])) leg.Draw() # Compute ratio wrt the first obj From 8f89a10dc46627b71df86c1a47ec2a01d87f194b Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Wed, 28 Feb 2024 13:48:28 +0100 Subject: [PATCH 06/17] added option to shift histogram in comparegraphs --- CompareGraphs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CompareGraphs.py b/CompareGraphs.py index efc64bd..ba46501 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -50,6 +50,9 @@ 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'])) From ad8a6d20f8ec71c0e3430e72fb4e0c0694a61651 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 29 Feb 2024 15:17:51 +0100 Subject: [PATCH 07/17] comment config alice3 --- fempy/sim/alice3/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fempy/sim/alice3/__init__.py b/fempy/sim/alice3/__init__.py index d1d161d..7d08cc2 100644 --- a/fempy/sim/alice3/__init__.py +++ b/fempy/sim/alice3/__init__.py @@ -1 +1 @@ -from . import alice3 +#from . import alice3 From 504669ad530667bc7b99ad8979b74cd00efcdab2 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 29 Feb 2024 22:36:40 +0100 Subject: [PATCH 08/17] added option for text lines --- CompareGraphs.py | 18 +++++++++++++++++- CompareWithSystematics.py | 20 ++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index ba46501..e5da2a8 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -3,7 +3,7 @@ import yaml from rich import print -from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle +from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle, TLatex import fempy from fempy import logger as log @@ -128,6 +128,22 @@ 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']) diff --git a/CompareWithSystematics.py b/CompareWithSystematics.py index 0d563af..04ff698 100644 --- a/CompareWithSystematics.py +++ b/CompareWithSystematics.py @@ -3,7 +3,7 @@ import yaml from rich import print -from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle +from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle, TLatex import fempy from fempy import logger as log @@ -135,9 +135,25 @@ leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') else: leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header'])) - + leg.SetTextSize(0.055) 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() + cPlot.Modified() cPlot.Update() From 49e1fa0089b3612d484bad3218d6c6194c30b5fc Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 22:40:23 +0100 Subject: [PATCH 09/17] fixed alice3 imports --- fempy/sim/__init__.py | 5 ++++- fempy/sim/alice3/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fempy/sim/__init__.py b/fempy/sim/__init__.py index d1d161d..aeff4b8 100644 --- a/fempy/sim/__init__.py +++ b/fempy/sim/__init__.py @@ -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 diff --git a/fempy/sim/alice3/__init__.py b/fempy/sim/alice3/__init__.py index 7d08cc2..aeff4b8 100644 --- a/fempy/sim/alice3/__init__.py +++ b/fempy/sim/alice3/__init__.py @@ -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 From f2804fa5c24e926fb26145b385d21711bed12ffa Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 22:44:14 +0100 Subject: [PATCH 10/17] removed commented code in systematics script --- CompareWithSystematics.py | 221 -------------------------------------- 1 file changed, 221 deletions(-) diff --git a/CompareWithSystematics.py b/CompareWithSystematics.py index 04ff698..bba0cf4 100644 --- a/CompareWithSystematics.py +++ b/CompareWithSystematics.py @@ -160,224 +160,3 @@ # save canvas for ext in plot["opt"]["ext"]: cPlot.SaveAs(f'{os.path.splitext(plot["output"])[0]}.{ext}') - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#import argparse -#import os -#import yaml -#import numpy as np -#from rich import print -# -#from ROOT import TFile, TCanvas, TH1, TLegend, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, TBox, TLatex, TText -# -#import fempy -#from fempy import logger as log -#from fempy.utils.format import TranslateToLatex -#from fempy.utils.io import Load -#from fempy.utils import style -# -#parser = argparse.ArgumentParser(description='Arguments') -#parser.add_argument('cfg') -#args = parser.parse_args() -# -## Load configuration file -#with open(args.cfg, "r") as stream: -# try: -# cfg = yaml.safe_load(stream) -# except yaml.YAMLError: -# log.critical('Yaml file not loaded') -# -#style.SetStyle() -# -#for plot in cfg: -# plot = plot["plot"] -# -# nInputs = len(plot['input']) -# panels = {'default': 1} -# if(nInputs>1): -# panels['uncratio'] = len(panels)+1 -# -# # Define the canvas -# nPanelsX, nPanelsY = fempy.utils.GetNPanels(len(panels)) -# cPlot = TCanvas("cPlot", "cPlot", 600*nPanelsX, 600*nPanelsY) -# cPlot.Divide(nPanelsX, nPanelsY) -# pad = cPlot.cd(1) -# pad.SetLogx(plot["opt"]["logx"]) -# pad.SetLogy(plot["opt"]["logy"]) -# -# fx1 = plot['opt']['rangex'][0] -# fy1 = plot['opt']['rangey'][0] -# fx2 = plot['opt']['rangex'][1] -# fy2 = plot['opt']['rangey'][1] -# print(fx1) -# pad.DrawFrame(fx1, fy1, fx2, fy2, TranslateToLatex(plot['opt']['title'])) -# -# boxes = [] -# inObjStatGraphs = [] -# legends = [] -# -# # Load the objects to draw -# for inputCfg in plot["input"]: -# inFile = TFile(inputCfg['file']) -# -# inObjStat = Load(inFile, inputCfg['name']) -# legends.append(inputCfg['legend']) -# print(inputCfg['legend']) -# if(isinstance(inObjStat, TH1)): -# inObjStat.SetDirectory(0) -# inObjStat.Rebin(inputCfg['rebin']) -# if inputCfg['normalize']: -# inObjStat.Scale(1./inObjStat.Integral()) -# -# binCenters = [] -# binWidths = [] -# binContents = [] -# binErrors = [] -# for iBin in range(inObjStat.GetNbinsX()): -# binCenters.append(inObjStat.GetBinCenter(iBin + 1)) -# binWidths.append(inObjStat.GetBinWidth(iBin + 1)) -# binContents.append(inObjStat.GetBinContent(iBin +1)) -# binErrors.append(inObjStat.GetBinError(iBin + 1)) -# if(nInputs==1): -# if(inputCfg['errbarfillcolor'] is not None): -# box = TBox(binCenters[-1] - binWidths[-1]/4, binContents[-1] - binErrors[-1], -# binCenters[-1] + binWidths[-1]/4, binContents[-1] + binErrors[-1]) -# box.SetFillStyle(inputCfg['errbarfillstyle']) -# box.SetFillColorAlpha(inputCfg['errbarfillcolor'], inputCfg['errbarfillalpha']) -# #box.Draw('same') -# boxes.append(box) -# binCentersNp = np.array(binCenters, dtype='double') -# binContentsNp = np.array(binContents, dtype='double') -# binXErrLowNp = np.array([binWidth/2 for binWidth in binWidths], dtype='double') -# binXErrUppNp = np.array([binWidth/2 for binWidth in binWidths], dtype='double') -# binYErrLowNp = np.array([binErr/2 for binErr in binErrors], dtype='double') -# binYErrUppNp = np.array([binErr/2 for binErr in binErrors], dtype='double') -# inObjStatGraph = TGraphAsymmErrors(inObjStat.GetNbinsX(), binCentersNp, binContentsNp, binXErrLowNp, -# binXErrUppNp, binYErrLowNp, binYErrUppNp) -# inObjStatGraph.GetXaxis().SetLimits(fx1, fx2) -# inObjStatGraph.GetYaxis().SetLimits(fy1, fy2) -# inObjStatGraph.GetXaxis().SetRangeUser(fx1, fx2) -# inObjStatGraph.GetYaxis().SetRangeUser(fy1, fy2) -# inObjStatGraph.SetLineColor(style.GetColor(inputCfg['color'])) -# inObjStatGraph.SetMarkerColor(style.GetColor(inputCfg['color'])) -# inObjStatGraph.SetMarkerStyle(inputCfg['markerstyle']) -# inObjStatGraph.SetMarkerSize(inputCfg['markersize']) -# inObjStatGraph.SetTitle(TranslateToLatex(plot['opt']['title'])) -# inObjStatGraphs.append(inObjStatGraph) -# print('ciao') -# inObjStatGraph.Draw('same ap') -# -# cPlot.Modified() -# cPlot.Update() -# -# if(nInputs==1): -# for iBox in boxes: -# cPlot.Modified() -# cPlot.Update() -# iBox.Draw('same') -# -# #print(len(inObjStatGraphs)) -# #for inObjStatGraph in inObjStatGraphs: -# # cPlot.Modified() -# # cPlot.Update() -# # inObjStatGraph.Draw('same ap') -# -# cPlot.Modified() -# cPlot.Update() -# -# legx1 = plot['opt']['leg']['posx'][0] -# legy1 = plot['opt']['leg']['posy'][0] -# legx2 = plot['opt']['leg']['posx'][1] -# legy2 = plot['opt']['leg']['posy'][1] -# leg = TLegend(legx1, legy1, legx2, legy2) -# -# print(inObjStatGraphs) -# print(legends) -# print(len(boxes)) -# for (inObjStatGraph, legend) in zip(inObjStatGraphs, legends): -# leg.AddEntry(inObjStatGraph, legend, 'lp') -# -# leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') -# if(plot['opt']['leg']['enable']): -# 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() -# -# if(nInputs==1): -# pad = cPlot.cd(panels['uncratio']) -# pad.SetLogx(plot['ratio']['logx']) -# pad.SetLogy(plot['ratio']['logy']) -# x1 = plot['opt']['rangex'][0] -# y1 = plot['ratio']['rangey'][0] -# x2 = plot['opt']['rangex'][1] -# y2 = plot['ratio']['rangey'][1] -# frame = pad.DrawFrame(x1, y1, x2, y2, 'Rel. Unc. comparison') -# frame.GetYaxis().SetTitle('Ratio') -# hDen = inObjStats[0].Clone() -# hDen.Rebin(plot['ratio']['rebin']) -# hDen.Sumw2() -# -# if isinstance(inObjStat, TH1): -# for inObjStat in inObjStats[1:]: -# hRatio = inObjStat.Clone() -# hRatio.Rebin(plot['ratio']['rebin']) -# hRatio.Divide(hDen) -# hRatio.Draw('same pe') -# else: -# log.error('Ratio for type %s is not implemented. Skipping this object', type(inObjStat)) -# continue -# -# line = TLine(plot['opt']['rangex'][0], 1, plot['opt']['rangex'][1], 1) -# line.SetLineColor(13) -# line.SetLineStyle(7) -# line.Draw('same pe') -# -# cPlot.Modified() -# cPlot.Update() -# -# # save canvas -# for ext in plot["opt"]["ext"]: -# cPlot.SaveAs(f'{os.path.splitext(plot["output"])[0]}.{ext}') \ No newline at end of file From 246475a3317aafc2eb7a4e149f72fdc552c36050 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 22:48:53 +0100 Subject: [PATCH 11/17] remback compatibility with previous config files --- CompareGraphs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index e5da2a8..f813da2 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -70,15 +70,15 @@ pad = cPlot.cd(1) pad.SetLogx(plot["opt"]["logx"]) pad.SetLogy(plot["opt"]["logy"]) - if(plot["opt"]["padtopmargin"]): + if("padtopmargin" in plot["opt"]): pad.SetTopMargin(plot["opt"]["padtopmargin"]) - if(plot["opt"]["padbottommargin"]): + if("padbottommargin" in plot["opt"]): pad.SetBottomMargin(plot["opt"]["padbottommargin"]) - if(plot["opt"]["padrightmargin"]): + if("padrightmargin" in plot["opt"]): pad.SetRightMargin(plot["opt"]["padrightmargin"]) - if(plot["opt"]["padleftmargin"]): + if("padleftmargin" in plot["opt"]): pad.SetLeftMargin(plot["opt"]["padleftmargin"]) - if(plot['opt']['ytitleoffset'] is not None): + if("ytitleoffset" in plot['opt']): print(plot['opt']['ytitleoffset']) gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y") @@ -122,7 +122,7 @@ inputline.Draw("same") leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") - if(plot['opt']['leg']['center']): + if('center' in plot['opt']['leg']): leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') else: leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header'])) From bd913ef9542b2a4c4eaa7735704573653b0062ed Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 23:21:12 +0100 Subject: [PATCH 12/17] updated yml config file --- CompareGraphs.py | 5 ++++- cfg_compare_example.yml | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index f813da2..b705d81 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -111,6 +111,7 @@ if plot['opt']['leg']['sigma']: legend += f'; #sigma={inObj.GetStdDev():.3f}' leg.AddEntry(inObj, legend, 'lp') + 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] @@ -120,7 +121,9 @@ 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") if('center' in plot['opt']['leg']): leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') diff --git a/cfg_compare_example.yml b/cfg_compare_example.yml index 87eee02..b8ac72b 100644 --- a/cfg_compare_example.yml +++ b/cfg_compare_example.yml @@ -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 From 7471c5e12d4b9527257210a128b0c719329c2cfd Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 23:21:46 +0100 Subject: [PATCH 13/17] fix --- CompareGraphs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index b705d81..46caccf 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -121,7 +121,6 @@ inputline.SetLineColor(style.GetColor(line['color'])) inputline.SetLineWidth(line['thickness']) inputline.Draw("same") - inputLines.append(inputline) if('legendtag' in line): leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") From 08c125d566083eb28f602caf02d90c870edbc32a Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 23:22:52 +0100 Subject: [PATCH 14/17] added list of lines to avoid error --- CompareGraphs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CompareGraphs.py b/CompareGraphs.py index 46caccf..937c881 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -112,6 +112,7 @@ 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] @@ -121,6 +122,7 @@ inputline.SetLineColor(style.GetColor(line['color'])) inputline.SetLineWidth(line['thickness']) inputline.Draw("same") + inputlines.append(inputline) if('legendtag' in line): leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") From b61e14d1033ec1a4a48159ca235120c7e85689b3 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 23:25:38 +0100 Subject: [PATCH 15/17] remove print --- CompareGraphs.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/CompareGraphs.py b/CompareGraphs.py index 937c881..251fda4 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -79,7 +79,6 @@ if("padleftmargin" in plot["opt"]): pad.SetLeftMargin(plot["opt"]["padleftmargin"]) if("ytitleoffset" in plot['opt']): - print(plot['opt']['ytitleoffset']) gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y") fx1 = plot['opt']['rangex'][0] @@ -112,7 +111,6 @@ 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] @@ -122,7 +120,6 @@ inputline.SetLineColor(style.GetColor(line['color'])) inputline.SetLineWidth(line['thickness']) inputline.Draw("same") - inputlines.append(inputline) if('legendtag' in line): leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") From ebf35c9db44415dd92c4436bf4bd8728ef5dc99c Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Thu, 21 Mar 2024 23:26:07 +0100 Subject: [PATCH 16/17] added list of lines to avoid error --- CompareGraphs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CompareGraphs.py b/CompareGraphs.py index 251fda4..cbb92c5 100644 --- a/CompareGraphs.py +++ b/CompareGraphs.py @@ -111,6 +111,7 @@ 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] @@ -120,6 +121,7 @@ inputline.SetLineColor(style.GetColor(line['color'])) inputline.SetLineWidth(line['thickness']) inputline.Draw("same") + inputlines.append(inputline) if('legendtag' in line): leg.AddEntry(inputline, TranslateToLatex(line['legendtag']),"l") From 4d45c88b0574019397152ff2e4f42210f7e59b54 Mon Sep 17 00:00:00 2001 From: Marcellocosti Date: Fri, 22 Mar 2024 10:48:40 +0100 Subject: [PATCH 17/17] remove macro for systematics --- CompareWithSystematics.py | 162 -------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 CompareWithSystematics.py diff --git a/CompareWithSystematics.py b/CompareWithSystematics.py deleted file mode 100644 index bba0cf4..0000000 --- a/CompareWithSystematics.py +++ /dev/null @@ -1,162 +0,0 @@ -import argparse -import os -import yaml -from rich import print - -from ROOT import TFile, TCanvas, TLegend, TLine, TH1, TGraph, TGraphErrors, TGraphAsymmErrors, TH1D, gStyle, TLatex - -import fempy -from fempy import logger as log -from fempy.utils.format import TranslateToLatex -from fempy.utils.io import Load -from fempy.utils import style - -parser = argparse.ArgumentParser(description='Arguments') -parser.add_argument('cfg') -args = parser.parse_args() - -# Load configuration file -with open(args.cfg, "r") as stream: - try: - cfg = yaml.safe_load(stream) - except yaml.YAMLError: - log.critical('Yaml file not loaded') - -style.SetStyle() - -for plot in cfg: - plot = plot["plot"] - - panels = {'default': 1} - if plot['ratio']['enable']: - panels['ratio'] = len(panels)+1 - if plot['relunc']['enable']: - panels['relunc'] = len(panels)+1 - - # Load the objects to draw - graphsStat = [] - graphsSyst = [] - legends = [] - drawOpts = [] - for inputCfg in plot["input"]: - inFile = TFile(inputCfg['file']) - - inObjStat = Load(inFile, inputCfg['histostat']) - inObjSyst = Load(inFile, inputCfg['histosyst']) - - if isinstance(inObjStat, TH1): - inObjStat.SetDirectory(0) - inObjStat.Rebin(inputCfg['rebin']) - - if inputCfg['normalize']: - inObjStat.Scale(1./inObjStat.Integral()) - if inputCfg['normalizecf']: - inObjStat.Scale(inputCfg['normalizecf']) - - statErr = TGraphAsymmErrors(inObjStat) - systErr = TGraphAsymmErrors(inObjSyst) - - statErr.SetLineColor(style.GetColor(inputCfg['color'])) - statErr.SetMarkerColor(style.GetColor(inputCfg['color'])) - statErr.SetLineWidth(inputCfg.get('thickness', 1)) - statErr.SetMarkerStyle(inputCfg['markerstyle']) - statErr.SetMarkerSize(inputCfg['markersize']) - systErr.SetLineColor(style.GetColor(inputCfg['color'])) - systErr.SetMarkerColor(style.GetColor(inputCfg['color'])) - systErr.SetLineWidth(inputCfg.get('thickness', 1)) - systErr.SetMarkerStyle(inputCfg['markerstyle']) - systErr.SetMarkerSize(inputCfg['markersize']) - systErr.SetFillColor(style.GetColor(inputCfg['color'])) - if(inputCfg['fillstylesyst'] is not None): - systErr.SetFillStyle(inputCfg['fillstylesyst']) - systErr.SetFillColorAlpha(style.GetColor(inputCfg['color']), inputCfg['fillalphasyst']) - - for iPoint in range(inObjStat.GetNbinsX()): - errX = inObjStat.GetBinWidth(iPoint)/4 - statErr.SetPointEXlow(iPoint, errX*2) - statErr.SetPointEXhigh(iPoint, errX*2) - systErr.SetPointEXlow(iPoint, errX) - systErr.SetPointEXhigh(iPoint, errX) - - graphsStat.append(statErr) - graphsSyst.append(systErr) - - legends.append(inputCfg['legend']) - - drawOpts.append(inputCfg.get('drawopt', 'p' if isinstance(statErr, TH1) else 'pe')) - # Define the canvas - nPanelsX, nPanelsY = fempy.utils.GetNPanels(len(panels)) - cPlot = TCanvas("cPlot", "cPlot", 600*nPanelsX, 600*nPanelsY) - cPlot.Divide(nPanelsX, nPanelsY) - pad = cPlot.cd(1) - pad.SetLogx(plot["opt"]["logx"]) - pad.SetLogy(plot["opt"]["logy"]) - if(plot["opt"]["padtopmargin"]): - pad.SetTopMargin(plot["opt"]["padtopmargin"]) - if(plot["opt"]["padbottommargin"]): - pad.SetBottomMargin(plot["opt"]["padbottommargin"]) - if(plot["opt"]["padrightmargin"]): - pad.SetRightMargin(plot["opt"]["padrightmargin"]) - if(plot["opt"]["padleftmargin"]): - pad.SetLeftMargin(plot["opt"]["padleftmargin"]) - if(plot['opt']['ytitleoffset'] is not None): - print(plot['opt']['ytitleoffset']) - gStyle.SetTitleOffset(plot['opt']['ytitleoffset'],"Y") - - fx1 = plot['opt']['rangex'][0] - fy1 = plot['opt']['rangey'][0] - fx2 = plot['opt']['rangex'][1] - fy2 = plot['opt']['rangey'][1] - pad.DrawFrame(fx1, fy1, fx2, fy2, TranslateToLatex(plot['opt']['title'])) - - legx1 = plot['opt']['leg']['posx'][0] - legy1 = plot['opt']['leg']['posy'][0] - legx2 = plot['opt']['leg']['posx'][1] - legy2 = plot['opt']['leg']['posy'][1] - leg = TLegend(legx1, legy1, legx2, legy2) - - for iObj, (inObjStat, inObjSyst, legend) in enumerate(zip(graphsStat, graphsSyst, legends)): - inObjStat.Draw(inputCfg['drawoptstat']) - inObjSyst.Draw(inputCfg['drawoptsyst']) - - # Compute statistics for hist in the displayed range - if isinstance(inObjStat, TH1): - firstBin = inObjStat.FindBin(plot['opt']['rangex'][0]*1.0001) - lastBin = inObjStat.FindBin(plot['opt']['rangex'][1]*0.9999) - inObjStat.GetXaxis().SetRange(firstBin, lastBin) - print(f'{legend}: mean = {inObjStat.GetMean()} sigma = {inObjStat.GetStdDev()}') - if plot['opt']['leg']['mean']: - legend += f'; #mu={inObjStat.GetMean():.3f}' - if plot['opt']['leg']['sigma']: - legend += f'; #sigma={inObjStat.GetStdDev():.3f}' - leg.AddEntry(inObjStat, legend, 'lp') - - if(plot['opt']['leg']['center']): - leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header']), 'C') - else: - leg.SetHeader(TranslateToLatex(plot['opt']['leg']['header'])) - leg.SetTextSize(0.055) - 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() - - cPlot.Modified() - cPlot.Update() - - # save canvas - for ext in plot["opt"]["ext"]: - cPlot.SaveAs(f'{os.path.splitext(plot["output"])[0]}.{ext}')