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 RecoTauTag_TauTagTools #23870

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
3 changes: 2 additions & 1 deletion RecoTauTag/TauTagTools/python/MVASteering_cfi.py
Expand Up @@ -7,6 +7,7 @@
- which algorithms (shrinkingConePFTauDecayModeProducer, etc)
Define locations of train/test ROOT files
"""
from __future__ import print_function

import sys
import six
Expand All @@ -15,7 +16,7 @@
try:
Project_Area = os.environ["CMSSW_BASE"]
except KeyError:
print "$CMSSW_BASE enviroment variable not set! Please run eval `scramv1 ru -[c]sh`"
print("$CMSSW_BASE enviroment variable not set! Please run eval `scramv1 ru -[c]sh`")
sys.exit(1)

import FWCore.ParameterSet.Config as cms
Expand Down
@@ -1,3 +1,4 @@
from __future__ import print_function
import FWCore.ParameterSet.Config as cms

produceTancMVAInputDiscriminators = cms.EDProducer(
Expand Down Expand Up @@ -73,7 +74,7 @@
def loadMVAInputsIntoPatTauDiscriminants(thePatTauProducer):
return
" Add all of the MVA inputs discriminators to the tauID inputs of a patTau Producer "
print "Embedding MVA inputs into PAT Tau producer "
print("Embedding MVA inputs into PAT Tau producer ")
patTauIDConfig = thePatTauProducer.tauIDSources
for tancInputInfo in produceTancMVAInputDiscriminators.discriminants:
name = tancInputInfo.name.value()
Expand All @@ -94,7 +95,7 @@ class Dummy:
test = Dummy()
test.tauIDSources = cms.PSet()
loadMVAInputsIntoPatTauDiscriminants(test)
print test.tauIDSources
print(test.tauIDSources)



Expand Down
19 changes: 10 additions & 9 deletions RecoTauTag/TauTagTools/test/database/ReblobTancDB_cfg.py
@@ -1,3 +1,4 @@
from __future__ import print_function
#!/usr/bin/env cmsRun

import FWCore.ParameterSet.Config as cms
Expand All @@ -21,15 +22,15 @@
mytag = cms.string('TauNeuralClassifier_v2')
mytimetype = cms.untracked.string('runnumber')

print ""
print "***************************************************"
print "****** Upload Tau Neural Classifier to DB ******"
print "***************************************************"
print "* Using the %s algorithm " % algorithm
print "* DB tag: %s " % mytag.value()
print "* Database: %s " % myconnect.value()
print "* Timetype: %s " % mytimetype.value()
print "* ----------------------------------------------- "
print("")
print("***************************************************")
print("****** Upload Tau Neural Classifier to DB ******")
print("***************************************************")
print("* Using the %s algorithm " % algorithm)
print("* DB tag: %s " % mytag.value())
print("* Database: %s " % myconnect.value())
print("* Timetype: %s " % mytimetype.value())
print("* ----------------------------------------------- ")


process = cms.Process("TaNCCondUpload")
Expand Down
21 changes: 11 additions & 10 deletions RecoTauTag/TauTagTools/test/database/UploadTancToDB.py
Expand Up @@ -5,6 +5,7 @@
Original author: Christopher Saout
Modifications by Evan Friis
'''
from __future__ import print_function

import FWCore.ParameterSet.Config as cms
import RecoTauTag.TauTagTools.TauMVAConfigurations_cfi
Expand Down Expand Up @@ -35,15 +36,15 @@
myconnect = cms.string(options.db) #or frontier, etc
mytag = cms.string(options.tag)
mytimetype = cms.untracked.string('runnumber')
print ""
print "***************************************************"
print "****** Upload Tau Neural Classifier to DB ******"
print "***************************************************"
print "* Using the %s algorithm " % algorithm
print "* DB tag: %s " % mytag.value()
print "* Database: %s " % myconnect.value()
print "* Timetype: %s " % mytimetype.value()
print "* ----------------------------------------------- "
print("")
print("***************************************************")
print("****** Upload Tau Neural Classifier to DB ******")
print("***************************************************")
print("* Using the %s algorithm " % algorithm)
print("* DB tag: %s " % mytag.value())
print("* Database: %s " % myconnect.value())
print("* Timetype: %s " % mytimetype.value())
print("* ----------------------------------------------- ")

# Unpack the TaNC neural nets into a parameter set
tempPSet = cms.PSet()
Expand All @@ -59,7 +60,7 @@
# god bless you, python
tempPSet.__setattr__(aNeuralNet.computerName.value(), cms.string(mvaFileLocation))
toCopyList.append(neuralNetName)
print "* %-20s %-20s " % (neuralNetName, mvaFileLocation )
print("* %-20s %-20s " % (neuralNetName, mvaFileLocation ))

process = cms.Process("TaNCCondUpload")

Expand Down
53 changes: 27 additions & 26 deletions RecoTauTag/TauTagTools/test/training/castor.py
@@ -1,3 +1,4 @@
from __future__ import print_function
# @file castor.py
# @brief A simple helper to handle simple tasks with CASTOR
#
Expand Down Expand Up @@ -209,8 +210,8 @@ def getFileSize( pathToFile = None ) :
#'nsls -l $CASTOR_DIR/$FILE | awk -F ' ' '{print $5}'

if status != 0 :
print "** PyCastor ERROR **"
print output
print("** PyCastor ERROR **")
print(output)
return []

output = output.splitlines()
Expand Down Expand Up @@ -253,12 +254,12 @@ def stagein( fileListPattern = None, nSlices = 10, verbose = True ) :
stageList = ' -M '.join( [''] + [ s for s in slice ] )
cmd = 'stager_get %s' % stageList
if verbose :
print ">>> cmd= ",cmd
print(">>> cmd= ",cmd)
status,output = commands.getstatusoutput(cmd)

if status != 0 :
print "** PyCastor ERROR **"
print output
print("** PyCastor ERROR **")
print(output)
pass
else :
if verbose :
Expand All @@ -279,10 +280,10 @@ def stager_qry(inFiles):
cmd = "stager_qry -M %s " % ( inFile, )
sc,out = commands.getstatusoutput( cmd )
if sc != 0:
print "** PyCastor ERROR **"
print "## Could not check status of this file [%s] !!" % inFile
print "## status sc=", sc
print "## output out=", out
print("** PyCastor ERROR **")
print("## Could not check status of this file [%s] !!" % inFile)
print("## status sc=", sc)
print("## output out=", out)

#for str in out.split():
# print "out_str=", str
Expand Down Expand Up @@ -320,29 +321,29 @@ def grep_path(schema, text):
return paths

path_list = grep_path("rfio", file_text)
print "rfio_file list extracted from input file =", inFile
print "-"*77; print path_list; print "-"*77
print("rfio_file list extracted from input file =", inFile)
print("-"*77); print(path_list); print("-"*77)

def _print(str):
print str
print(str)

status_dict = stager_qry(path_list)
ready_files_list = [file for file in status_dict if status_dict[file] == 1]
print "---STAGED (ready to be copied):";
p = map(_print, ready_files_list); print "-"*77
print("---STAGED (ready to be copied):");
p = map(_print, ready_files_list); print("-"*77)

noready_files_list = [file for file in status_dict if status_dict[file] == 0]
print "---NOT STAGED (not ready to be copied):";
p = map(_print, noready_files_list); print "-"*77
print("---NOT STAGED (not ready to be copied):");
p = map(_print, noready_files_list); print("-"*77)

def _rfcp(file): #aux func. just for reporting purpose
print "rfcp ", file
print("rfcp ", file)
return file
rfcp( map(_rfcp, ready_files_list), #[file for file in ready_files_list],
outDir )

def _stager_get(file): #aux func. just for reporting purpose
print "stager_get -M ", file
print("stager_get -M ", file)
stager_get(file)
map(_stager_get, noready_files_list) #[stager_get(file) for file in noready_files_list if 1 print "stager_get -M ", file]

Expand All @@ -357,8 +358,8 @@ def stager_get(inFile):
cmd = "stager_get -M %s" % (inFile)
sc,out = commands.getstatusoutput( cmd )
if sc != 0:
print "** PyCastor ERROR **"
print "## Could not stager_get this file [%s] !!" % inFile
print("** PyCastor ERROR **")
print("## Could not stager_get this file [%s] !!" % inFile)
allGood = False
pass
if allGood:
Expand All @@ -376,8 +377,8 @@ def rfcp( inFiles, outDir ):
os.path.basename(inFile) ) )
sc,out = commands.getstatusoutput( cmd )
if sc != 0:
print "** PyCastor ERROR **"
print "## Could not copy this file [%s] !!" % inFile
print("** PyCastor ERROR **")
print("## Could not copy this file [%s] !!" % inFile)
allGood = False
pass
pass
Expand All @@ -395,10 +396,10 @@ def rfstat (pathname):
cmd = 'rfstat %s' % pathname
sc, out = commands.getstatusoutput (cmd)
if sc != 0:
print "** PyCastor ERROR **"
print ":: command: [%s]" % cmd
print ":: status: [%s]" % sc
print out
print("** PyCastor ERROR **")
print(":: command: [%s]" % cmd)
print(":: status: [%s]" % sc)
print(out)
raise RuntimeError (sc)

stat = dict()
Expand Down
23 changes: 12 additions & 11 deletions RecoTauTag/TauTagTools/test/training/computeTransform.py
Expand Up @@ -12,6 +12,7 @@
Authors: Evan K. Friis, Christian Veelken (UC Davis)

'''
from __future__ import print_function

from RecoLuminosity.LumiDB import argparse

Expand All @@ -29,7 +30,7 @@
import ROOT
import sys

print "Building transformation:", options.o
print("Building transformation:", options.o)

ROOT.gROOT.SetBatch(True)

Expand All @@ -41,10 +42,10 @@
signal_histo = signal_file.Get("cleanTauPlots/hpsTancTausDiscriminationByTancRaw")
background_histo = background_file.Get("cleanTauPlots/hpsTancTausDiscriminationByTancRaw")

print "Signal has %i entries in clean, %i in total" % (
signal_histo.Integral(), signal_denominator_histo.Integral())
print "Background has %i entries in clean, %i in total" % (
background_histo.Integral(), background_denominator_histo.Integral())
print("Signal has %i entries in clean, %i in total" % (
signal_histo.Integral(), signal_denominator_histo.Integral()))
print("Background has %i entries in clean, %i in total" % (
background_histo.Integral(), background_denominator_histo.Integral()))

# Determine the probability for a given jet to end up in this decay mode stream
signal_scale = signal_histo.Integral()/signal_denominator_histo.Integral()
Expand Down Expand Up @@ -105,9 +106,9 @@ def compute_transform(raw_cut, signal_cdf, signal_scale,
return output

# Build the cumulative distribution functions
print "Building signal c.d.f"
print("Building signal c.d.f")
signal_cdf = make_cdf(signal_histo)
print "Building background c.d.f"
print("Building background c.d.f")
background_cdf = make_cdf(background_histo)
transform = lambda x: compute_transform(x, signal_cdf, signal_scale,
background_cdf, background_scale)
Expand All @@ -118,8 +119,8 @@ def compute_transform(raw_cut, signal_cdf, signal_scale,
transform_values.append(transform_result['transform'])
# Check if this is one of our cuts
if thresholds and transform_result['signal_passing'] < thresholds[0]:
print "***********"
print x, transform_result
print("***********")
print(x, transform_result)
thresholds.pop(0)
threshold_values.append((x, transform_result['transform']))

Expand All @@ -128,7 +129,7 @@ def compute_transform(raw_cut, signal_cdf, signal_scale,
output_object.signalDecayModeWeight = cms.double(signal_scale)
output_object.backgroundDecayModeWeight = cms.double(background_scale)

print threshold_values
print(threshold_values)

# On the chance that a decay mode has nothing in it
if not threshold_values:
Expand All @@ -147,6 +148,6 @@ def compute_transform(raw_cut, signal_cdf, signal_scale,

output_file.close()

print "Transform file %s created" % options.o
print("Transform file %s created" % options.o)

sys.exit(0)
3 changes: 2 additions & 1 deletion RecoTauTag/TauTagTools/test/training/dump_db.py
Expand Up @@ -7,12 +7,13 @@
Author: Evan K. Friis (UC Davis)

'''
from __future__ import print_function

import FWCore.ParameterSet.Config as cms
import sys
import os

print sys.argv
print(sys.argv)

db_file = sys.argv[2]
mva_file = db_file.replace('.db', '.mva')
Expand Down
5 changes: 3 additions & 2 deletions RecoTauTag/TauTagTools/test/training/evaluateMode_cfg.py
Expand Up @@ -10,6 +10,7 @@
Author: Evan K. Friis (UC Davis)

'''
from __future__ import print_function

import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
Expand Down Expand Up @@ -48,7 +49,7 @@


if options.tracks < 0 or options.pizeros < 0:
print "You must specify the [tracks] and [pizeros] arguments."
print("You must specify the [tracks] and [pizeros] arguments.")
sys.exit(1)
# Make a nice tuple of the decay mode
_decay_mode = (options.tracks, options.pizeros)
Expand All @@ -75,7 +76,7 @@
fileName = cms.string(options.outputFile)
)

print "WARNING: input branch workaround!"
print("WARNING: input branch workaround!")
# Input files
process.source = cms.Source(
"PoolSource",
Expand Down
3 changes: 2 additions & 1 deletion RecoTauTag/TauTagTools/test/training/evaluate_cfg.py
Expand Up @@ -9,6 +9,7 @@
Author: Evan K. Friis (UC Davis)

'''
from __future__ import print_function

import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
Expand Down Expand Up @@ -130,7 +131,7 @@
# Remove the lepton discrimination
lepton_discriminants = [name for name in process.PFTau.moduleNames()
if 'Muon' in name or 'Electron' in name]
print "Removing lepton discriminants: %s" % " ".join(lepton_discriminants)
print("Removing lepton discriminants: %s" % " ".join(lepton_discriminants))
for lepton_discriminant in lepton_discriminants:
module = getattr(process, lepton_discriminant)
process.PFTau.remove(module)
Expand Down