Skip to content

Commit

Permalink
Merge pull request #24017 from davidlange6/printMig_180724T4_Validati…
Browse files Browse the repository at this point in the history
…on_RecoTrack

Print function migration for Validation_RecoTrack
  • Loading branch information
cmsbuild committed Jul 25, 2018
2 parents 76742c4 + 647502a commit 8aecbd4
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 209 deletions.
5 changes: 3 additions & 2 deletions Validation/RecoTrack/python/customiseMTVForBPix123Holes.py
@@ -1,3 +1,4 @@
from __future__ import print_function
# This customise file provides an example (in the form of holes in
# BPix L1-L2 and L3-L3) on how to select a subset of generalTracks
# (e.g. by phi and eta) and setup various MTV instances for those
Expand All @@ -21,8 +22,8 @@ def customiseMTVForBPix123Holes(process):
minRapidity = -0.9, maxRapidity = 2,
minPhi=_minPhi+_binPhi*33, maxPhi=_minPhi+_binPhi + 2*math.pi) # ~2.6 .. ~3.3

print "L1L2 %f %f" % (process.generalTracksL1L2.minPhi.value(), process.generalTracksL1L2.maxPhi.value())
print "L2L3 %f %f" % (process.generalTracksL2L3.minPhi.value(), process.generalTracksL2L3.maxPhi.value())
print("L1L2 %f %f" % (process.generalTracksL1L2.minPhi.value(), process.generalTracksL1L2.maxPhi.value()))
print("L2L3 %f %f" % (process.generalTracksL2L3.minPhi.value(), process.generalTracksL2L3.maxPhi.value()))

from CommonTools.RecoAlgos.trackingParticleRefSelector_cfi import trackingParticleRefSelector as _trackingParticleRefSelector
process.trackingParticlesL1L2 = _trackingParticleRefSelector.clone(
Expand Down
33 changes: 17 additions & 16 deletions Validation/RecoTrack/python/plotting/plotting.py
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import sys
import math
Expand Down Expand Up @@ -48,7 +49,7 @@ def _getObject(tdirectory, name):
obj = tdirectory.Get(name)
if not obj:
if verbose:
print "Did not find {obj} from {dir}".format(obj=name, dir=tdirectory.GetPath())
print("Did not find {obj} from {dir}".format(obj=name, dir=tdirectory.GetPath()))
return None
return obj

Expand Down Expand Up @@ -82,14 +83,14 @@ def _getDirectoryDetailed(tfile, possibleDirs, subDir=None):
return d
else:
if verbose:
print "Did not find subdirectory '%s' from directory '%s' in file %s" % (subDir, pdf, tfile.GetName())
print("Did not find subdirectory '%s' from directory '%s' in file %s" % (subDir, pdf, tfile.GetName()))
# if "Step" in subDir:
# raise Exception("Foo")
return GetDirectoryCode.SubDirNotExist
else:
return d
if verbose:
print "Did not find any of directories '%s' from file %s" % (",".join(possibleDirs), tfile.GetName())
print("Did not find any of directories '%s' from file %s" % (",".join(possibleDirs), tfile.GetName()))
return GetDirectoryCode.PossibleDirsNotExist

def _getDirectory(*args, **kwargs):
Expand Down Expand Up @@ -485,15 +486,15 @@ def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None):
if len(xmins) == 0: # all histograms zero
xmin = min(xmin)
if verbose:
print "Histogram is zero, using the smallest given value for xmin from", str(xmin)
print("Histogram is zero, using the smallest given value for xmin from", str(xmin))
else:
xm = min(xmins)
xmins_below = [x for x in xmin if x<=xm]
if len(xmins_below) == 0:
xmin = min(xmin)
if xm < xmin:
if verbose:
print "Histogram minimum x %f is below all given xmin values %s, using the smallest one" % (xm, str(xmin))
print("Histogram minimum x %f is below all given xmin values %s, using the smallest one" % (xm, str(xmin)))
else:
xmin = max(xmins_below)

Expand All @@ -503,15 +504,15 @@ def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None):
if len(xmaxs) == 0: # all histograms zero
xmax = max(xmax)
if verbose:
print "Histogram is zero, using the smallest given value for xmax from", str(xmin)
print("Histogram is zero, using the smallest given value for xmax from", str(xmin))
else:
xm = max(xmaxs)
xmaxs_above = [x for x in xmax if x>xm]
if len(xmaxs_above) == 0:
xmax = max(xmax)
if xm > xmax:
if verbose:
print "Histogram maximum x %f is above all given xmax values %s, using the maximum one" % (xm, str(xmax))
print("Histogram maximum x %f is above all given xmax values %s, using the maximum one" % (xm, str(xmax)))
else:
xmax = min(xmaxs_above)

Expand Down Expand Up @@ -575,7 +576,7 @@ def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=
ymin = min(ymin)
if ym_unscaled < ymin:
if verbose:
print "Histogram minimum y %f is below all given ymin values %s, using the smallest one" % (ym, str(ymin))
print("Histogram minimum y %f is below all given ymin values %s, using the smallest one" % (ym, str(ymin)))
else:
ymin = max(ymins_below)

Expand All @@ -591,7 +592,7 @@ def _findBoundsY(th1s, ylog, ymin=None, ymax=None, coverage=None, coverageRange=
ymax = max(ymax)
if ym_unscaled > ymax:
if verbose:
print "Histogram maximum y %f is above all given ymax values %s, using the maximum one" % (ym_unscaled, str(ymax))
print("Histogram maximum y %f is above all given ymax values %s, using the maximum one" % (ym_unscaled, str(ymax)))
else:
ymax = min(ymaxs_above)

Expand Down Expand Up @@ -1057,7 +1058,7 @@ def create(self, tdirectory):
if self._normalizeTo is not None:
bin = th1.GetXaxis().FindBin(self._normalizeTo)
if bin <= 0:
print "Trying to normalize {name} to {binlabel}, which does not exist".format(name=self._name, binlabel=self._normalizeTo)
print("Trying to normalize {name} to {binlabel}, which does not exist".format(name=self._name, binlabel=self._normalizeTo))
sys.exit(1)
value = th1.GetBinContent(bin)
if value != 0:
Expand Down Expand Up @@ -2034,7 +2035,7 @@ def _styleHist(h, msty, col):
histos.append(h)
if len(histos) == 0:
if verbose:
print "No histograms for plot {name}".format(name=self.getName())
print("No histograms for plot {name}".format(name=self.getName()))
return

# Extract x bin labels, make sure that only bins with same
Expand Down Expand Up @@ -2064,20 +2065,20 @@ def _styleHist(h, msty, col):
self._tmp_histos = histos # need to keep these in memory too ...
if len(histos) == 0:
if verbose:
print "No histograms with non-empty bins for plot {name}".format(name=self.getName())
print("No histograms with non-empty bins for plot {name}".format(name=self.getName()))
return

if self._printBins and histosHaveBinLabels:
print "####################"
print self._name
print("####################")
print(self._name)
width = max([len(l) for l in xbinlabels])
tmp = "%%-%ds " % width
for b in xrange(1, histos[0].GetNbinsX()+1):
s = tmp % xbinlabels[b-1]
for h in histos:
s += "%.3f " % h.GetBinContent(b)
print s
print
print(s)
print()

bounds = _findBounds(histos, self._ylog,
xmin=self._xmin, xmax=self._xmax,
Expand Down

0 comments on commit 8aecbd4

Please sign in to comment.