From 20b427fcb9b131acb442004bd32ea18ef009e15c Mon Sep 17 00:00:00 2001 From: Michael Wassmer Date: Thu, 25 Jan 2024 16:03:57 +0100 Subject: [PATCH] python3 compatibility changes and corrections --- setup.sh | 1 + toolbox/condorSubmit.py | 5 +++-- toolbox/harryPlotter/HistogramSetup.py | 5 ++++- toolbox/harryPlotter/hpUtil.py | 18 ++++++++++++------ toolbox/mrcrab.py | 8 ++++---- toolbox/rutil.py | 6 +++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/setup.sh b/setup.sh index a2f65dc..c856735 100644 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,7 @@ alias fitpy='python -i $TOOLBOX/scripts/fitpy.py' alias dnnpy='python -i $TOOLBOX/scripts/dnnpy.py' alias mrcrab='python $TOOLBOX/scripts/mrcrab.py' +alias mrcrab3='python3 $TOOLBOX/scripts/mrcrab.py' alias yieldTable='python $TOOLBOX/scripts/yieldTable.py' alias condorSubmit='python $TOOLBOX/scripts/condorSubmit.py' diff --git a/toolbox/condorSubmit.py b/toolbox/condorSubmit.py index d173e3e..c410fc1 100644 --- a/toolbox/condorSubmit.py +++ b/toolbox/condorSubmit.py @@ -135,8 +135,9 @@ def condorSubmit(submitPath): process = subprocess.Popen(submitCommand.split(), stdout = subprocess.PIPE, stderr = subprocess.STDOUT, stdin = subprocess.PIPE) process.wait() output = process.communicate() + print(output) try: - jobID = int(output[0].split(".")[0]) + jobID = int(output[0].decode().split(".")[0]) except: print("something went wrong with calling the condir_submit command, submission of jobs was not successful") print("DEBUG:") @@ -188,7 +189,7 @@ def monitorJobStatus(jobIDs = None, queryInterval = 60, nTotalJobs = None): a.wait() qstat = a.communicate()[0] nrunning = 0 - querylines = [line for line in qstat.split("\n") if "Total for query" in line] + querylines = [line for line in qstat.decode().split("\n") if "Total for query" in line] # check if query matches if len(querylines) == 0: diff --git a/toolbox/harryPlotter/HistogramSetup.py b/toolbox/harryPlotter/HistogramSetup.py index e6bf0ac..41816a1 100644 --- a/toolbox/harryPlotter/HistogramSetup.py +++ b/toolbox/harryPlotter/HistogramSetup.py @@ -139,6 +139,9 @@ def getData(self, templates): # build pseudodata histogram pseudodata = None for proc in processes: + if not proc in templates: + printer.printWarning("\tprocess {} not found in templates".format(proc)) + continue if pseudodata is None: pseudodata = templates[proc].nom.Clone() else: @@ -235,7 +238,7 @@ def getPlotRange(self, stackedHistograms, lineHistograms): ''' yMax = 0. yMinMax = 1e10 - hists = lineHistograms.values() + hists = list(lineHistograms.values()) if len(stackedHistograms) > 0: hists.append(stackedHistograms[-1]) for h in hists: diff --git a/toolbox/harryPlotter/hpUtil.py b/toolbox/harryPlotter/hpUtil.py index 2916942..3b96443 100644 --- a/toolbox/harryPlotter/hpUtil.py +++ b/toolbox/harryPlotter/hpUtil.py @@ -44,15 +44,21 @@ def getHistColor(name): "experimental": (1001, ROOT.kRed, 0.3), "theo": (1001, ROOT.kBlue, 0.3), - "btag": (3145, ROOT.kRed+1, 0.7), + "btag": (3145, ROOT.kRed-4, 0.7), "jec": (3145, ROOT.kOrange+1, 1.0), - "qcdscale": (3472, ROOT.kGray+2, 1.0), - "ps": (3227, ROOT.kBlue+1, 1.0), + "jes": (3145, ROOT.kOrange+3, 1.0), + "jer": (3145, ROOT.kOrange+5, 1.0), + "uncl": (3145, ROOT.kOrange+7, 1.0), + "scale": (3472, ROOT.kBlue+1, 1.0), + "ps": (3227, ROOT.kBlue+3, 1.0), + "lindert": (3227, ROOT.kBlue+5, 1.0), "pu": (3244, ROOT.kMagenta, 1.0), "lep": (3257, ROOT.kRed+1, 1.0), - "ele": (3257, ROOT.kRed+2, 1.0), - "muon": (3257, ROOT.kRed+3, 1.0), - "topPt": (3257, ROOT.kRed+4, 1.0), + "ele": (3257, ROOT.kRed+3, 1.0), + "muon": (3257, ROOT.kRed+4, 1.0), + "pho": (3257, ROOT.kRed+2, 1.0), + "topPt": (3257, ROOT.kRed+6, 1.0), + "toptagger": (3257, ROOT.kGreen, 1.0), } def getErrorStyle(sys): diff --git a/toolbox/mrcrab.py b/toolbox/mrcrab.py index b480b55..ab6bd35 100644 --- a/toolbox/mrcrab.py +++ b/toolbox/mrcrab.py @@ -79,9 +79,9 @@ def query(self): stderr = subprocess.STDOUT, stdin = subprocess.PIPE) - process.stdin.write("\n") + process.stdin.write("\n".encode()) process.wait() - self.query = process.communicate()[0] + self.query = process.communicate()[0].decode() if "Enter GRID pass phrase" in self.query: printer.printError("need to init voms proxy") sys.exit() @@ -102,9 +102,9 @@ def query_crab_report(self): stderr = subprocess.STDOUT, stdin = subprocess.PIPE) - process.stdin.write("\n") + process.stdin.write("\n".encode()) process.wait() - self.query = process.communicate()[0] + self.query = process.communicate()[0].decode() if "Enter GRID pass phrase" in self.query: printer.printError("need to init voms proxy") sys.exit() diff --git a/toolbox/rutil.py b/toolbox/rutil.py index d694c11..67df30b 100644 --- a/toolbox/rutil.py +++ b/toolbox/rutil.py @@ -66,7 +66,7 @@ def checkFile(f, treeName = None): return True -def hadd(files, target, entries = -1, treeName = "Events", inChunks=True, chunkSize=500): +def hadd(files, target, entries = -1, treeName = "Events", inChunks=True, chunkSize=200): # check availability of all files ok = True if not treeName is None: @@ -95,10 +95,10 @@ def hadd(files, target, entries = -1, treeName = "Events", inChunks=True, chunkS for i, ch in enumerate(chunks(files, chunkSize)): outFile = target.replace(".root","")+"_chunk_{}.root".format(i) hadd_parts.append(outFile) - cmd = "hadd -v 0 -fk {outFile} {files} ".format(files=" ".join(ch), outFile=outFile) + cmd = "hadd -fk {outFile} {files} ".format(files=" ".join(ch), outFile=outFile) execute(cmd) # hadd all chunks together - cmd = "hadd -f -v 0 {outFile} {files}".format(files =" ".join(hadd_parts), outFile = target) + cmd = "hadd -f {outFile} {files}".format(files =" ".join(hadd_parts), outFile = target) execute(cmd) # remove hadd parts cmd = "rm {files}".format(files = " ".join(hadd_parts))