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

Print function migration for L1Trigger_L1TCalorimeter #24074

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions L1Trigger/L1TCalorimeter/python/convertParamsToOnlineFormat.py
@@ -1,5 +1,6 @@
#!/bin/env python

from __future__ import print_function
import argparse
import FWCore.ParameterSet.Config as cms
from importlib import import_module
Expand All @@ -19,9 +20,9 @@ def parseOfflineLUTfile(aRelPath):
searchPaths = os.getenv('CMSSW_SEARCH_PATH').split(':')
resolvedPath = None
for baseDir in searchPaths:
print "Looking for '" + aRelPath + "' under '" + baseDir + "'"
print("Looking for '" + aRelPath + "' under '" + baseDir + "'")
if os.path.isfile(os.path.join(baseDir, aRelPath)):
print " success!"
print(" success!")
resolvedPath = os.path.join(baseDir, aRelPath)
break
if resolvedPath is None:
Expand All @@ -42,7 +43,7 @@ def parseOfflineLUTfile(aRelPath):
# Split line into list of whitespace-separated items
items = stripped_line.split()
if len(items) != 2:
print "ERROR parsing file", resolvedPath, "on line", line_nr, "'" + line + "' : Splitting on whitespace produced", len(items), "items"
print("ERROR parsing file", resolvedPath, "on line", line_nr, "'" + line + "' : Splitting on whitespace produced", len(items), "items")
sys.exit(1)

entries.append( (int(items[0]), int(items[1])) )
Expand All @@ -51,17 +52,17 @@ def parseOfflineLUTfile(aRelPath):
entries.sort(key= lambda x : x[0])
# Check that the LUT is not empty
if len(entries) == 0:
print "ERROR parsing file", resolvedPath, ": No LUT entries defined in the file"
print("ERROR parsing file", resolvedPath, ": No LUT entries defined in the file")
sys.exit(1)

# Check that no items from the LUT are missing
if entries[0][0] != 0:
print "ERROR parsing file", resolvedPath, ": LUT entries before index", entries[0][0], "are not defined"
print("ERROR parsing file", resolvedPath, ": LUT entries before index", entries[0][0], "are not defined")
sys.exit(1)

for x1, x2 in pairwiseGen(entries):
if x1[0] != (x2[0]-1):
print "ERROR parsing file", resolvedPath, ": ", x2[0] - x1[0] - 1,"LUT entries between indices", x1[0], "and", x2[0], "are not defined"
print("ERROR parsing file", resolvedPath, ": ", x2[0] - x1[0] - 1,"LUT entries between indices", x1[0], "and", x2[0], "are not defined")
sys.exit(1)

return [x[1] for x in entries]
Expand Down Expand Up @@ -170,7 +171,7 @@ def indent(elem, level=0):
elem.tail = i

def createMIF(aFilePath, aValue):
print "Writing MIF file:", aFilePath
print("Writing MIF file:", aFilePath)
with open(aFilePath, 'w') as f:
if isinstance(aValue, bool):
aValue = (1 if aValue else 0)
Expand Down Expand Up @@ -199,7 +200,7 @@ def createXML(parameters, contextId, outputFilePath):
raise RuntimeError("Do not know how to deal with parameter '" + paramId + "' of type " + str(type(value)))
indent(topNode)

print "Writing XML file:", outputFilePath
print("Writing XML file:", outputFilePath)
with open(outputFilePath, 'w') as f:
f.write(ET.tostring(topNode))

Expand All @@ -219,12 +220,12 @@ def createXML(parameters, contextId, outputFilePath):
args = parser.parse_args()

moduleName = 'L1Trigger.L1TCalorimeter.' + args.params_cfi
print "Importing calo params from module:", moduleName
print("Importing calo params from module:", moduleName)
caloParams = import_module(moduleName).caloStage2Params

print caloParams.egCalibrationLUTFile.value()
print caloParams.egIsoLUTFile.value()
print caloParams.egIsoLUTFile2.value()
print(caloParams.egCalibrationLUTFile.value())
print(caloParams.egIsoLUTFile.value())
print(caloParams.egIsoLUTFile2.value())
os.mkdir(args.output_dir)

if args.mif:
Expand Down
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys
import math
Expand All @@ -26,7 +27,7 @@
"Remember to do 'git add " + os.environ['LOCALRT'] + "L1Trigger/L1TCalorimeter/data' when committing the new LUT!")
os.makedirs(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data")

print "Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v7.txt'"
print("Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v7.txt'")
towEtThreshLUTFile = open(os.environ['LOCALRT']+"/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v7.txt", "w")


Expand Down Expand Up @@ -97,6 +98,6 @@
towEtThreshLUTFile.write(str(addr) + " " + str(0) + " # dummy\n")
addr+=1

print "Done. Closing file..."
print("Done. Closing file...")

towEtThreshLUTFile.close()
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys
import math
Expand All @@ -26,7 +27,7 @@
"Remember to do 'git add " + os.environ['LOCALRT'] + "L1Trigger/L1TCalorimeter/data' when committing the new LUT!")
os.makedirs(os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data")

print "Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v4_excl30.txt'"
print("Creating tower Et threshold LUT with filename " + os.environ['LOCALRT'] + "/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v4_excl30.txt'")
towEtThreshLUTFile = open(os.environ['LOCALRT']+"/src/L1Trigger/L1TCalorimeter/data/lut_towEtThresh_2017v4_excl30.txt", "w")


Expand Down Expand Up @@ -94,6 +95,6 @@
towEtThreshLUTFile.write(str(addr) + " " + str(0) + " # dummy\n")
addr+=1

print "Done. Closing file..."
print("Done. Closing file...")

towEtThreshLUTFile.close()
53 changes: 27 additions & 26 deletions L1Trigger/L1TCalorimeter/python/studyJets.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import os
import sys
import math
Expand Down Expand Up @@ -51,54 +52,54 @@ def getJetProperties(jetSeed,etaFwd,etaCen):

def printJetProperties(etaRange):

print "Size \ eta\t",
print("Size \ eta\t", end=' ')
for seedEta in etaRange:
if(seedEta<29):
print str(seedEta)+"\t\t",
print(str(seedEta)+"\t\t", end=' ')
else:
print str(seedEta+1)+"\t\t",
print
print(str(seedEta+1)+"\t\t", end=' ')
print()

for size in jetEtaSizes:

if size%2:
print " 9x"+str(size)+("\t"),
print(" 9x"+str(size)+("\t"), end=' ')
for seedEta in etaRange:
print("\t"),
print(("\t"), end=' ')
etaFwdCen = (size-1)/2
jetProps = getJetProperties(seedEta,etaFwdCen,etaFwdCen)
print("%.2f / %.2f" %(jetProps[0],jetProps[1])),
print
print(("%.2f / %.2f" %(jetProps[0],jetProps[1])), end=' ')
print()

else:
print " 9x"+str(size)+" cen",
print(" 9x"+str(size)+" cen", end=' ')
for seedEta in etaRange:
print("\t"),
print(("\t"), end=' ')
etaFwd = size/2-1
etaCen = size/2
jetProps = getJetProperties(seedEta, etaFwd, etaCen)
print("%.2f / %.2f" %(jetProps[0],jetProps[1])),
print
print " 9x"+str(size)+" fwd",
print(("%.2f / %.2f" %(jetProps[0],jetProps[1])), end=' ')
print()
print(" 9x"+str(size)+" fwd", end=' ')
for seedEta in etaRange:
print("\t"),
print(("\t"), end=' ')
etaFwd = size/2
etaCen = size/2-1
jetProps = getJetProperties(seedEta, etaFwd, etaCen)
print("%.2f / %.2f" %(jetProps[0],jetProps[1])),
print
print(("%.2f / %.2f" %(jetProps[0],jetProps[1])), end=' ')
print()



print "\n"
print "=============================================================================================================================================================================================================================="
print "Eta-dependence of jet sizes & seed centrality"
print "First number = jet diameter in eta, normalised to 0.8 (offline)"
print "Second number = jet size on forward side of jet seed / jet size on central side of jet seed"
print "Ideally, best jet choice is where both numbers are closest to unity!"
print "9xN cen = larger area on side of jet further from beam pipe"
print "9xN fwd = larger area on side of jet closer to beam pipe"
print "=============================================================================================================================================================================================================================="
print("\n")
print("==============================================================================================================================================================================================================================")
print("Eta-dependence of jet sizes & seed centrality")
print("First number = jet diameter in eta, normalised to 0.8 (offline)")
print("Second number = jet size on forward side of jet seed / jet size on central side of jet seed")
print("Ideally, best jet choice is where both numbers are closest to unity!")
print("9xN cen = larger area on side of jet further from beam pipe")
print("9xN fwd = larger area on side of jet closer to beam pipe")
print("==============================================================================================================================================================================================================================")


beEtaRange = xrange(16,29)
Expand All @@ -115,5 +116,5 @@ def printJetProperties(etaRange):
printJetProperties(hfEtaRange)

print("\n")
print "=============================================================================================================================================================================================================================="
print("==============================================================================================================================================================================================================================")
print("\n\n")
3 changes: 2 additions & 1 deletion L1Trigger/L1TCalorimeter/test/generatePattern-Stage2MP.py
@@ -1,3 +1,4 @@
from __future__ import print_function
# Auto generated configuration file
# using:
# Revision: 1.19
Expand Down Expand Up @@ -79,7 +80,7 @@
try:
os.stat(options.outDir)
except:
print 'Output directory does not exist. Creating directory: ' + options.outDir
print('Output directory does not exist. Creating directory: ' + options.outDir)
os.mkdir(options.outDir)

process = cms.Process('L1Emulator')
Expand Down