Skip to content

Commit

Permalink
python3 compatibility changes and corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wassmer committed Jan 25, 2024
1 parent 3346184 commit 20b427f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions toolbox/condorSubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion toolbox/harryPlotter/HistogramSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 12 additions & 6 deletions toolbox/harryPlotter/hpUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions toolbox/mrcrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions toolbox/rutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 20b427f

Please sign in to comment.