From d6d80c7cf9c2319422baef1992fd454d59366169 Mon Sep 17 00:00:00 2001 From: Christian Weber <ChristianTMWeber@gmal.com> Date: Fri, 16 Jul 2021 16:34:22 -0400 Subject: [PATCH] Add option to pass error calculating function in histToTGraph --- functions/tGraphHelpers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/functions/tGraphHelpers.py b/functions/tGraphHelpers.py index e7cfe59..f11e162 100644 --- a/functions/tGraphHelpers.py +++ b/functions/tGraphHelpers.py @@ -131,8 +131,7 @@ def dictToTGraph(aDict): return listToTGraph( xList, yList ) -def histToTGraph(hist, skipFunction = False): - +def histToTGraph(hist, skipFunction = False, errorFunction = None): tGraph = ROOT.TGraphAsymmErrors() @@ -142,15 +141,19 @@ def histToTGraph(hist, skipFunction = False): x = hist.GetBinCenter(binNr) y = hist.GetBinContent(binNr) - yError = hist.GetBinError(binNr) - if skipFunction: - if skipFunction(x,y,yError): continue + if errorFunction is None: + yErrorLow = hist.GetBinError(binNr) + yErrorHigh = hist.GetBinError(binNr) - graphPointCounter += 1 + else: yErrorLow, yErrorHigh = errorFunction(x,y) + + if skipFunction: + if skipFunction(x,y,yErrorLow,yErrorHigh): continue tGraph.SetPoint( graphPointCounter, x, y) - tGraph.SetPointError( graphPointCounter, 0,0,yError, yError ) + tGraph.SetPointError( graphPointCounter, 0,0, yErrorLow, yErrorHigh ) + graphPointCounter += 1 #import pdb; pdb.set_trace() # import the debugger and instruct it to stop here -- GitLab