diff --git a/Validation/RecoTrack/python/customiseMTVForBPix123Holes.py b/Validation/RecoTrack/python/customiseMTVForBPix123Holes.py index 8af55521619f9..d78a10d27ddc8 100644 --- a/Validation/RecoTrack/python/customiseMTVForBPix123Holes.py +++ b/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 @@ -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( diff --git a/Validation/RecoTrack/python/plotting/plotting.py b/Validation/RecoTrack/python/plotting/plotting.py index 3579ff42b9075..45a7104d645cb 100644 --- a/Validation/RecoTrack/python/plotting/plotting.py +++ b/Validation/RecoTrack/python/plotting/plotting.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import sys import math @@ -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 @@ -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): @@ -485,7 +486,7 @@ 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] @@ -493,7 +494,7 @@ def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None): 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) @@ -503,7 +504,7 @@ 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] @@ -511,7 +512,7 @@ def _findBounds(th1s, ylog, xmin=None, xmax=None, ymin=None, ymax=None): 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) @@ -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) @@ -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) @@ -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: @@ -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 @@ -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, diff --git a/Validation/RecoTrack/python/plotting/validation.py b/Validation/RecoTrack/python/plotting/validation.py index 9ee6dc886fb62..6c7b499c3aced 100644 --- a/Validation/RecoTrack/python/plotting/validation.py +++ b/Validation/RecoTrack/python/plotting/validation.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import re import sys @@ -361,7 +362,7 @@ def _getGlobalTag(sample, release): release -- CMSSW release string """ if not release in _globalTags: - print "Release %s not found from globaltag map in validation.py" % release + print("Release %s not found from globaltag map in validation.py" % release) sys.exit(1) gtmap = _globalTags[release] selectedGT = None @@ -453,7 +454,7 @@ def _getRelValUrl(release): raise Exception("Regex %s does not match to release version %s" % (version_re.pattern, release)) version = "%s_%s_X" % (m.group("X"), m.group("Y")) if not version in _relvalUrls: - print "No RelVal URL for version %s, please update _relvalUrls" % version + print("No RelVal URL for version %s, please update _relvalUrls" % version) sys.exit(1) return _relvalUrls[version] @@ -694,8 +695,8 @@ def __init__(self, fullsimSamples, fastsimSamples, refRelease, refRepository, ne try: self._newRelease = os.environ["CMSSW_VERSION"] except KeyError: - print >>sys.stderr, 'Error: CMSSW environment variables are not available.' - print >>sys.stderr, ' Please run cmsenv' + print('Error: CMSSW environment variables are not available.', file=sys.stderr) + print(' Please run cmsenv', file=sys.stderr) sys.exit() self._fullsimSamples = fullsimSamples @@ -720,30 +721,30 @@ def download(self): filenames = map(self._newFileModifier, filenames) filenames = [f for f in filenames if not os.path.exists(f)] if len(filenames) == 0: - print "All files already downloaded" + print("All files already downloaded") return relvalUrl = _getRelValUrl(self._newRelease) urls = [relvalUrl+f for f in filenames] certfile = os.path.join(os.environ["HOME"], ".globus", "usercert.pem") if not os.path.exists(certfile): - print "Certificate file {certfile} does not exist, unable to download RelVal files from {url}".format(certfile=certfile, url=relvalUrl) + print("Certificate file {certfile} does not exist, unable to download RelVal files from {url}".format(certfile=certfile, url=relvalUrl)) sys.exit(1) keyfile = os.path.join(os.environ["HOME"], ".globus", "userkey.pem") if not os.path.exists(certfile): - print "Private key file {keyfile} does not exist, unable to download RelVal files from {url}".format(keyfile=keyfile, url=relvalUrl) + print("Private key file {keyfile} does not exist, unable to download RelVal files from {url}".format(keyfile=keyfile, url=relvalUrl)) sys.exit(1) # curl --cert-type PEM --cert $HOME/.globus/usercert.pem --key $HOME/.globus/userkey.pem -k -O -O cmd = ["curl", "--cert-type", "PEM", "--cert", certfile, "--key", keyfile, "-k"] for u in urls: cmd.extend(["-O", u]) - print "Downloading %d files from RelVal URL %s:" % (len(filenames), relvalUrl) - print " "+"\n ".join(filenames) - print "Please provide your private key pass phrase when curl asks it" + print("Downloading %d files from RelVal URL %s:" % (len(filenames), relvalUrl)) + print(" "+"\n ".join(filenames)) + print("Please provide your private key pass phrase when curl asks it") ret = subprocess.call(cmd) if ret != 0: - print "Downloading failed with exit code %d" % ret + print("Downloading failed with exit code %d" % ret) sys.exit(1) # verify @@ -752,10 +753,10 @@ def download(self): p = subprocess.Popen(["file", f], stdout=subprocess.PIPE) stdout = p.communicate()[0] if p.returncode != 0: - print "file command failed with exit code %d" % p.returncode + print("file command failed with exit code %d" % p.returncode) sys.exit(1) if not "ROOT" in stdout: - print "File {f} is not ROOT, please check the correct version, GlobalTag etc. from {url}".format(f=f, url=relvalUrl) + print("File {f} is not ROOT, please check the correct version, GlobalTag etc. from {url}".format(f=f, url=relvalUrl)) allFine = False if os.path.exists(f): os.remove(f) @@ -786,7 +787,7 @@ def doPlots(self, plotter, plotterDrawArgs={}, limitSubFoldersOnlyTo=None, htmlR # Check that the new DQM file exists harvestedFile = sample.filename(self._newRelease) if not os.path.exists(harvestedFile): - print "Harvested file %s does not exist!" % harvestedFile + print("Harvested file %s does not exist!" % harvestedFile) sys.exit(1) plotterInstance = plotter.readDirs(harvestedFile) @@ -825,7 +826,7 @@ def _doFastsimFastVsFullPlots(self, limitSubFoldersOnlyTo, htmlReport): else: raise Exception("Got multiple compatible FullSim samples for FastSim sample %s %s" % (fast.name(), fast.pileup())) if correspondingFull is None: - print "WARNING: Did not find compatible FullSim sample for FastSim sample %s %s, omitting FastSim vs. FullSim comparison" % (fast.name(), fast.pileup()) + print("WARNING: Did not find compatible FullSim sample for FastSim sample %s %s, omitting FastSim vs. FullSim comparison" % (fast.name(), fast.pileup())) continue # If we reach here, the harvestedFile must exist @@ -908,10 +909,10 @@ def _createRefSelection(selectionName): if refValFile is None: if len(triedRefValFiles) == 1: if plotting.verbose: - print "Reference file %s not found" % triedRefValFiles[0] + print("Reference file %s not found" % triedRefValFiles[0]) else: if plotting.verbose: - print "None of the possible reference files %s not found" % ",".join(triedRefValFiles) + print("None of the possible reference files %s not found" % ",".join(triedRefValFiles)) return (refValFile, refSelection) @@ -951,9 +952,9 @@ def _doPlots(self, sample, harvestedFile, plotterFolder, dqmSubFolder, htmlRepor # Do the plots if plotting.verbose: - print "Comparing ref and new {sim} {sample} {translatedFolder}".format( + print("Comparing ref and new {sim} {sample} {translatedFolder}".format( sim="FullSim" if not sample.fastsim() else "FastSim", - sample=sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "") + sample=sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "")) rootFiles = [refValFile, newValFile] legendLabels = [ "%s, %s %s" % (sample.name(), _stripRelease(self._refRelease), refSelection) if self._refRelease is not None else "dummy", @@ -978,12 +979,12 @@ def _doPlots(self, sample, harvestedFile, plotterFolder, dqmSubFolder, htmlRepor dups = _findDuplicates(fileList) if len(dups) > 0: - print "Plotter produced multiple files with names", ", ".join(dups) - print "Typically this is a naming problem in the plotter configuration" + print("Plotter produced multiple files with names", ", ".join(dups)) + print("Typically this is a naming problem in the plotter configuration") sys.exit(1) # Move plots to new directory - print "Created plots and %s in %s" % (valname, newdir) + print("Created plots and %s in %s" % (valname, newdir)) return map(lambda n: n.replace(newdir, newsubdir), fileList) def _doPlotsFastFull(self, fastSample, fullSample, plotterFolder, dqmSubFolder, htmlReport): @@ -1012,18 +1013,18 @@ def _doPlotsFastFull(self, fastSample, fullSample, plotterFolder, dqmSubFolder, valname = "val.{sample}.root".format(sample=fastSample.name()) fastValFilePath = os.path.join(fastdir, valname) if not os.path.exists(fastValFilePath) and plotting.verbose: - print "FastSim file %s not found" % fastValFilePath + print("FastSim file %s not found" % fastValFilePath) fullValFilePath = os.path.join(fulldir, valname) if not os.path.exists(fullValFilePath) and plotting.verbose: - print "FullSim file %s not found" % fullValFilePath + print("FullSim file %s not found" % fullValFilePath) fastValFile = ROOT.TFile.Open(fastValFilePath) fullValFile = ROOT.TFile.Open(fullValFilePath) # Do plots if plotting.verbose: - print "Comparing FullSim and FastSim {sample} {translatedFolder}".format( - sample=fastSample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "") + print("Comparing FullSim and FastSim {sample} {translatedFolder}".format( + sample=fastSample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "")) rootFiles = [fullValFile, fastValFile] legendLabels = [ "FullSim %s, %s %s" % (fullSample.name(), _stripRelease(self._newRelease), fullSelection), @@ -1044,12 +1045,12 @@ def _doPlotsFastFull(self, fastSample, fullSample, plotterFolder, dqmSubFolder, dups = _findDuplicates(fileList) if len(dups) > 0: - print "Plotter produced multiple files with names", ", ".join(dups) - print "Typically this is a naming problem in the plotter configuration" + print("Plotter produced multiple files with names", ", ".join(dups)) + print("Typically this is a naming problem in the plotter configuration") sys.exit(1) # Move plots to new directory - print "Created plots in %s" % (newdir) + print("Created plots in %s" % (newdir)) return map(lambda n: n.replace(newdir, newsubdir), fileList) def _doPlotsPileup(self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, htmlReport): @@ -1076,12 +1077,12 @@ def _doPlotsPileup(self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, pu140ValFilePath = os.path.join(pu140dir, valname) if not os.path.exists(pu140ValFilePath): if plotting.verbose: - print "PU140 file %s not found" % pu140ValFilePath + print("PU140 file %s not found" % pu140ValFilePath) return [] pu200ValFilePath = os.path.join(pu200dir, valname) if not os.path.exists(pu200ValFilePath): if plotting.verbose: - print "PU200 file %s not found" % pu200ValFilePath + print("PU200 file %s not found" % pu200ValFilePath) return [] pu140ValFile = ROOT.TFile.Open(pu140ValFilePath) @@ -1089,8 +1090,8 @@ def _doPlotsPileup(self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, # Do plots if plotting.verbose: - print "Comparing PU140 and PU200 {sample} {translatedFolder}".format( - sample=pu200Sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "") + print("Comparing PU140 and PU200 {sample} {translatedFolder}".format( + sample=pu200Sample.name(), translatedFolder=str(dqmSubFolder.translated) if dqmSubFolder is not None else "")) rootFiles = [pu140ValFile, pu200ValFile] legendLabels = [ "%s, %s %s" % (pu140Sample.name(), _stripRelease(self._newRelease), pu140Selection), @@ -1111,12 +1112,12 @@ def _doPlotsPileup(self, pu140Sample, pu200Sample, plotterFolder, dqmSubFolder, dups = _findDuplicates(fileList) if len(dups) > 0: - print "Plotter produced multiple files with names", ", ".join(dups) - print "Typically this is a naming problem in the plotter configuration" + print("Plotter produced multiple files with names", ", ".join(dups)) + print("Typically this is a naming problem in the plotter configuration") sys.exit(1) # Move plots to new directory - print "Created plots in %s" % (newdir) + print("Created plots in %s" % (newdir)) return map(lambda n: n.replace(newdir, newsubdir), fileList) @@ -1250,7 +1251,7 @@ def doPlots(self, plotters, plotterDrawArgs={}, **kwargs): if os.path.exists(f): self._openFiles.append(ROOT.TFile.Open(f)) else: - print "File %s not found (from sample %s), ignoring it" % (f, sample.name()) + print("File %s not found (from sample %s), ignoring it" % (f, sample.name())) self._openFiles.append(None) for plotter in plotters: @@ -1287,9 +1288,9 @@ def _doPlots(self, plotterFolder, dqmSubFolder): dups = _findDuplicates(fileList) if len(dups) > 0: - print "Plotter produced multiple files with names", ", ".join(dups) - print "Typically this is a naming problem in the plotter configuration" + print("Plotter produced multiple files with names", ", ".join(dups)) + print("Typically this is a naming problem in the plotter configuration") sys.exit(1) - print "Created plots in %s" % newdir + print("Created plots in %s" % newdir) return map(lambda n: n.replace(newdir, newsubdir), fileList) diff --git a/Validation/RecoTrack/scripts/diffTrackingNtuple.py b/Validation/RecoTrack/scripts/diffTrackingNtuple.py index cf5c28db69fc9..73f2c7e5e4c77 100755 --- a/Validation/RecoTrack/scripts/diffTrackingNtuple.py +++ b/Validation/RecoTrack/scripts/diffTrackingNtuple.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import argparse import itertools import collections @@ -7,7 +8,7 @@ import Validation.RecoTrack.plotting.ntuple as ntuple def body(opts, ev1, ev2, printTrack): - print ev1.eventIdStr() + print(ev1.eventIdStr()) tracks1 = ev1.tracks() tracks2 = ev2.tracks() @@ -18,8 +19,8 @@ def body(opts, ev1, ev2, printTrack): diff = ntuple.diffTrackListsGeneric(printTrack, tracks1, tracks2, ignoreAdditionalLst2=singleTrack) if diff.hasDifference(): - print str(diff) - print + print(str(diff)) + print() def inOrder(opts, ntpl1, ntpl2, *args, **kwargs): if opts.entry is not None: @@ -55,7 +56,7 @@ def outOfOrder(opts, ntpl1, ntpl2, *args, **kwargs): break if not ev1.eventId() in events2: - print "-", ev1.eventIdStr() + print("-", ev1.eventIdStr()) continue ev2 = ntpl2.getEvent(events2[ev1.eventIdStr()]) @@ -65,14 +66,14 @@ def outOfOrder(opts, ntpl1, ntpl2, *args, **kwargs): for eventIdStr in events2.iterkeys(): - print "+", eventIdStr + print("+", eventIdStr) def main(opts): ntpl1 = ntuple.TrackingNtuple(opts.file1) ntpl2 = ntuple.TrackingNtuple(opts.file2) - print "--- %s" % opts.file1 - print "+++ %s" % opts.file2 + print("--- %s" % opts.file1) + print("+++ %s" % opts.file2) printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(parentage=False), diffForTwiki=opts.twiki) diff --git a/Validation/RecoTrack/scripts/harvestTrackValidationPlots.py b/Validation/RecoTrack/scripts/harvestTrackValidationPlots.py index 8a3229c3c4bf6..9f33b8562a316 100755 --- a/Validation/RecoTrack/scripts/harvestTrackValidationPlots.py +++ b/Validation/RecoTrack/scripts/harvestTrackValidationPlots.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import sys,os,tempfile,shutil,subprocess,glob import argparse @@ -32,7 +33,7 @@ # compile cmsDriver command cmsDriverCommand = "cmsDriver.py harvest --scenario pp --filetype DQM --conditions auto:run2_mc --mc -s HARVESTING:@trackingOnlyValidation+@trackingOnlyDQM+postProcessorHLTtrackingSequence -n -1 --filein {0}".format(filelist) - print "# running cmsDriver" + "\n" + cmsDriverCommand + print("# running cmsDriver" + "\n" + cmsDriverCommand) # run it subprocess.call(cmsDriverCommand.split(" ")) @@ -40,8 +41,8 @@ # find the output and move it to the specified output file path ofiles = glob.glob("DQM*.root") if len(ofiles) != 1: - print "ERROR: expecting exactly one output file matching DQM*.root" - print " ls of current directory({0}):".format(_tempdir) + print("ERROR: expecting exactly one output file matching DQM*.root") + print(" ls of current directory({0}):".format(_tempdir)) os.system("ls -lt") sys.exit() shutil.move(ofiles[0],outputFile) diff --git a/Validation/RecoTrack/scripts/makeTrackValidationPlots.py b/Validation/RecoTrack/scripts/makeTrackValidationPlots.py index ed7c405c6e413..6ba831696525d 100755 --- a/Validation/RecoTrack/scripts/makeTrackValidationPlots.py +++ b/Validation/RecoTrack/scripts/makeTrackValidationPlots.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import os import argparse @@ -70,12 +71,12 @@ def main(opts): other.extend([vertexPlots.plotterExt, trackingPlots.plotterHLTExt]) val.doPlots(trk, plotterDrawArgs=drawArgs, **kwargs_tracking) val.doPlots(other, plotterDrawArgs=drawArgs) - print + print() if opts.no_html: - print "Plots created into directory '%s'." % opts.outputDir + print("Plots created into directory '%s'." % opts.outputDir) else: htmlReport.write() - print "Plots and HTML report created into directory '%s'. You can just move it to some www area and access the pages via web browser" % opts.outputDir + print("Plots and HTML report created into directory '%s'. You can just move it to some www area and access the pages via web browser" % opts.outputDir) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Create standard set of tracking validation plots from one or more DQM files.") @@ -122,13 +123,13 @@ def main(opts): parser.error("DQM file %s does not exist" % f) if opts.ignoreMissing: - print "--ignoreMissing is now the only operation mode, so you can stop using this parameter" + print("--ignoreMissing is now the only operation mode, so you can stop using this parameter") if opts.ratio: - print "--ratio is now the default, so you can stop using this parameter" + print("--ratio is now the default, so you can stop using this parameter") if opts.html: - print "--html is now the default, so you can stop using this parameter" + print("--html is now the default, so you can stop using this parameter") if opts.limit_tracking_algo is not None: if opts.limit_relval: @@ -136,6 +137,6 @@ def main(opts): opts.limit_tracking_algo = opts.limit_tracking_algo.split(",") if opts.limit_relval and opts.ptcut: - print "With --limit-relval enabled, --ptcut option does not have any effect" + print("With --limit-relval enabled, --ptcut option does not have any effect") main(opts) diff --git a/Validation/RecoTrack/scripts/printTrackingNtuple.py b/Validation/RecoTrack/scripts/printTrackingNtuple.py index 8642438d1d83c..57c43d9f35ab3 100755 --- a/Validation/RecoTrack/scripts/printTrackingNtuple.py +++ b/Validation/RecoTrack/scripts/printTrackingNtuple.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import argparse import Validation.RecoTrack.plotting.ntuple as ntuple @@ -25,19 +26,19 @@ def main(opts): if opts.entry is not None: event = ntpl.getEvent(opts.entry) - print event.eventIdStr() + print(event.eventIdStr()) elif opts.event is not None: event = findEvent(ntpl, opts.event) - print "Entry %d" % event.entry() + print("Entry %d" % event.entry()) hasHits = ntpl.hasHits() hasSeeds = ntpl.hasSeeds() if not hasSeeds and opts.seed is not None: - print "Ntuple %s does not have seeds saved!" % opts.file + print("Ntuple %s does not have seeds saved!" % opts.file) return if not hasHits and (opts.pixelHit is not None or opts.stripHit is not None): - print "Ntuple %s does not have hits saved!" % opts.file + print("Ntuple %s does not have hits saved!" % opts.file) return seedArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits) @@ -57,7 +58,7 @@ def main(opts): if opts.track is not None: trks = event.tracks() if opts.track >= len(trks): - print "You requested track %d, but this event has only %d tracks" % (opts.track, len(trks)) + print("You requested track %d, but this event has only %d tracks" % (opts.track, len(trks))) return trk = trks[opts.track] printTrack(trk) @@ -65,7 +66,7 @@ def main(opts): if opts.trackingParticle is not None: tps = event.trackingParticles() if opts.trackingParticle >= len(tps): - print "You requested TrackingParticle %d, but this event has ony %d TrackingParticles" % (opts.trackingParticle, len(tps)) + print("You requested TrackingParticle %d, but this event has ony %d TrackingParticles" % (opts.trackingParticle, len(tps))) return tp = tps[opts.trackingParticle] printTrackingParticle(tp) @@ -75,12 +76,12 @@ def main(opts): if opts.seedIteration is not None: algo = getattr(ntuple.Algo, opts.seedIteration) if opts.seed >= seeds.nSeedsForAlgo(algo): - print "You requested seed %d for algo %s, but this event has only %d seeds for that algo" % (opts.seed, opts.seedIteration, seeds.nSeedsForAlgo(algo)) + print("You requested seed %d for algo %s, but this event has only %d seeds for that algo" % (opts.seed, opts.seedIteration, seeds.nSeedsForAlgo(algo))) return seed = seeds.seedForAlgo(algo, opts.seed) else: if opts.seed >= len(seeds): - print "You requested seed %d, but this event has only %d seeds" % (opts.seed, len(seeds)) + print("You requested seed %d, but this event has only %d seeds" % (opts.seed, len(seeds))) return seed = seeds[opts.seed] printSeed(seed) @@ -88,29 +89,29 @@ def main(opts): if opts.pixelHit is not None: hits = event.pixelHits() if opts.pixelHit >= len(hits): - print "You requested pixel hit %d, but this event has only %d pixel hits" % (opts.pixelHit, len(hits)) + print("You requested pixel hit %d, but this event has only %d pixel hits" % (opts.pixelHit, len(hits))) return hit = hits[opts.pixelHit] - print "Pixel hit %d tracks" % opts.pixelHit + print("Pixel hit %d tracks" % opts.pixelHit) for t in hit.tracks(): printTrack(t) if hasSeeds: - print "Pixel hit %d seeds" % opts.pixelHit + print("Pixel hit %d seeds" % opts.pixelHit) for s in hit.seeds(): printSeed(s) if opts.stripHit is not None: hits = event.stripHits() if opts.stripHit >= len(hits): - print "You requested strip hit %d, but this event has only %d strip hits" % (opts.stripHit, len(hits)) + print("You requested strip hit %d, but this event has only %d strip hits" % (opts.stripHit, len(hits))) return hit = hits[opts.stripHit] - print "Strip hit %d tracks" % opts.stripHit + print("Strip hit %d tracks" % opts.stripHit) for t in hit.tracks(): printTrack(t) if hasSeeds: - print "Strip hit %d seeds" % opts.stripHit + print("Strip hit %d seeds" % opts.stripHit) for s in hit.seeds(): printSeed(s) diff --git a/Validation/RecoTrack/test/analyseDuplicateFake.py b/Validation/RecoTrack/test/analyseDuplicateFake.py index ea7664802dc8c..6611a40572e0a 100755 --- a/Validation/RecoTrack/test/analyseDuplicateFake.py +++ b/Validation/RecoTrack/test/analyseDuplicateFake.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import ROOT from Validation.RecoTrack.plotting.ntuple import * @@ -13,19 +14,19 @@ def main(): printTP = TrackingParticlePrinter(trackPrinter=TrackPrinter()) for event in ntuple: - print "Event", event.eventIdStr() - print "Fake tracks" + print("Event", event.eventIdStr()) + print("Fake tracks") for track in event.tracks(): if track.nMatchedTrackingParticles() == 0: printTrack(track) - print + print() - print "Duplicate tracks" + print("Duplicate tracks") for tp in event.trackingParticles(): if tp.nMatchedTracks() >= 2: printTP(tp) - print - print + print() + print() if event.entry() >= 1: break diff --git a/Validation/RecoTrack/test/fakeAnalysis/analysis.py b/Validation/RecoTrack/test/fakeAnalysis/analysis.py index b56d9dba4eb8e..5b34b32c00490 100644 --- a/Validation/RecoTrack/test/fakeAnalysis/analysis.py +++ b/Validation/RecoTrack/test/fakeAnalysis/analysis.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import ROOT from array import array from collections import OrderedDict @@ -122,7 +123,7 @@ def FindFakes(event): for track in event.tracks(): if track.nMatchedTrackingParticles() == 0: fakes.append(track) - print "Event: " + str(event.entry()+1) + " Number of fake tracks: " + str(len(fakes)) + print("Event: " + str(event.entry()+1) + " Number of fake tracks: " + str(len(fakes))) return fakes def FindTrues(event): @@ -131,7 +132,7 @@ def FindTrues(event): for track in event.tracks(): if track.nMatchedTrackingParticles() >= 0: trues.append(track) - print "Event: " + str(event.entry()+1) + " Number of true tracks: " + str(len(trues)) + print("Event: " + str(event.entry()+1) + " Number of true tracks: " + str(len(trues))) return trues def Distance(x1,x2): @@ -149,7 +150,7 @@ def FindUntrackedParticles(event): for particle in event.trackingParticles(): if (particle.isValid() and particle.nMatchedTracks() == 0 and MTFEfficiencySelector(particle)): untracked.append(particle) - print "Number of untracked particles: " + str(len(untracked)) + print("Number of untracked particles: " + str(len(untracked))) return untracked def MTFEfficiencySelector(particle): @@ -181,10 +182,10 @@ def EfficiencyRate(ntuple, N): if(particle.nMatchedTracks() == 0): untracked += 1 else: tracked += 1 i += 1 - print "In " + str(N) + " events there are:" - print "Tracked particles: " + str(tracked) - print "Untracked particles: " + str(untracked) - print "Efficiency rate: " + str(float(tracked)/(tracked+untracked)) + print("In " + str(N) + " events there are:") + print("Tracked particles: " + str(tracked)) + print("Untracked particles: " + str(untracked)) + print("Efficiency rate: " + str(float(tracked)/(tracked+untracked))) def SharedHitFrac(track, particle, frac = 0): ''' @@ -473,14 +474,14 @@ def MatchPixelHits(fake, particle, real_criterion = ["consecutive", 3]): ''' if start_tolerance == 0: # The end of the particle was reached - print "Match is not a real match :\\" + print("Match is not a real match :\\") if len(hit_candidates)<3 or not start_flag: - print "No hit candidates from a match" - print [hit.index() for hit in fake.hits() if hit.isValidHit()] - print particle_hit_indexes - print [hit.index() for hit in hit_candidates] - print start_tolerance - print start_flag + print("No hit candidates from a match") + print([hit.index() for hit in fake.hits() if hit.isValidHit()]) + print(particle_hit_indexes) + print([hit.index() for hit in hit_candidates]) + print(start_tolerance) + print(start_flag) return -1, -1 return nPix, nPixLayers @@ -575,43 +576,43 @@ def PrintTrackInfo(track, fake = None, frac = 0, fake_info = None): ''' Prints info on the track. Called from PlotFakes method in graphics.py. ''' if isinstance(track, Track): if track.nMatchedTrackingParticles() == 0: # FAKE - print str(track.index()) + ": FAKE \nSTOP REASON: " + StopReason(track) - print "Has " + str(track.nValid()) + " valid hits" + print(str(track.index()) + ": FAKE \nSTOP REASON: " + StopReason(track)) + print("Has " + str(track.nValid()) + " valid hits") if fake_info: fake_info.Print() else: # RECONSTRUCTED reco_str = str(track.index()) + ": RECOVERED " for info in track.matchedTrackingParticleInfos(): reco_str += str(info.trackingParticle().index()) + " " + str(info.shareFrac()) + "\nSTOP REASON: " + StopReason(track) # sharefrac()[0] old version - print reco_str + print(reco_str) else: # REAL - print str(track.index()) + ": REAL" - if track.nMatchedTracks() == 0: print "NOT RECOVERED" - elif track.nMatchedTracks() == 1: print "RECOVERED" - else: print "RECOVERED " + str(track.nMatchedTracks()) + " TIMES" + print(str(track.index()) + ": REAL") + if track.nMatchedTracks() == 0: print("NOT RECOVERED") + elif track.nMatchedTracks() == 1: print("RECOVERED") + else: print("RECOVERED " + str(track.nMatchedTracks()) + " TIMES") decaycount = 0 for decay in track.decayVertices(): decaycount += 1 - if decaycount: print "DECAYED " + str(decaycount) + " TIMES" + if decaycount: print("DECAYED " + str(decaycount) + " TIMES") if fake: # tell the shared hit fraction compared to fake if frac: num, div, npar = SharedHitFrac(fake, track, 1) - print "Fake share fraction: " + str(num) + " / " + str(div) + ", track has " + str(npar) + " hits" + print("Fake share fraction: " + str(num) + " / " + str(div) + ", track has " + str(npar) + " hits") else: dec = SharedHitFrac(fake, track, 0) - print "Fake shares " + str(dec) + " fraction of hits with track" - print "Shared hits from beginning: " + str(SharedHitsFromBeginning(track, fake, 10)) + print("Fake shares " + str(dec) + " fraction of hits with track") + print("Shared hits from beginning: " + str(SharedHitsFromBeginning(track, fake, 10))) if isinstance(track, TrackingParticle): - print "Parameters:" - print "px : " + str(track.px()) + " py : " + str(track.py()) + " pz : " + str(track.pz()) - print "pt : " + str(track.pca_pt()) + " eta : " + str(track.pca_eta()) + " phi : " + str(track.pca_phi()) - print "dxy : " + str(track.pca_dxy()) + " dz : " + str(track.pca_dz()) + " q : " + str(track.q()) + "\n" + print("Parameters:") + print("px : " + str(track.px()) + " py : " + str(track.py()) + " pz : " + str(track.pz())) + print("pt : " + str(track.pca_pt()) + " eta : " + str(track.pca_eta()) + " phi : " + str(track.pca_phi())) + print("dxy : " + str(track.pca_dxy()) + " dz : " + str(track.pca_dz()) + " q : " + str(track.q()) + "\n") else: - print "Parameters:" - print "px : " + str(track.px()) + " py : " + str(track.py()) + " pz : " + str(track.pz()) - print "pt : " + str(track.pt()) + " eta : " + str(track.eta()) + " phi : " + str(track.phi()) - print "dxy : " + str(track.dxy()) + " dz : " + str(track.dz()) + " q : " + str(track.q()) + "\n" + print("Parameters:") + print("px : " + str(track.px()) + " py : " + str(track.py()) + " pz : " + str(track.pz())) + print("pt : " + str(track.pt()) + " eta : " + str(track.eta()) + " phi : " + str(track.phi())) + print("dxy : " + str(track.dxy()) + " dz : " + str(track.dz()) + " q : " + str(track.q()) + "\n") ##### CLASSIFICATION ##### @@ -696,8 +697,8 @@ def Classify(self): def Print(self): ''' Prints fake track classification info with matched particle infos. ''' - print "CLASS: " + str(self.fake_class) + " WITH " + str(self.nMatches) + " MATCHES" - print "Has " + str(self.nIncludedDecayParticles) + " included decay particles, with links: " + str(self.decayLinks) + print("CLASS: " + str(self.fake_class) + " WITH " + str(self.nMatches) + " MATCHES") + print("Has " + str(self.nIncludedDecayParticles) + " included decay particles, with links: " + str(self.decayLinks)) for match in self.matches: match.Print() class MatchInfo(object): @@ -761,9 +762,9 @@ def __init__(self, match, fake, real_criterion = ["consecutive", 3], end_criteri def Print(self): ''' Prints match info. ''' - print "Match " + str(self.index) + ": nReconstructed " + str(self.nReconstructed) +\ + print("Match " + str(self.index) + ": nReconstructed " + str(self.nReconstructed) +\ ", daughters: " + str(self.daughterIndexes) +\ - ", tracking failed in " + self.last_str + ", to " + self.particle_end_str + ", wrong hit in " + self.fake_end_str + ", tracking failed in " + self.last_str + ", to " + self.particle_end_str + ", wrong hit in " + self.fake_end_str) ##### STORAGE CLASSES ##### @@ -1064,7 +1065,7 @@ def Calculate_IndludedDecayHitFractions(ntuple_file, nEvents = 100): for fake in fakes: info = FakeInfo(fake) if info.fake_class == 21: - if len(info.decayLinks) >= 2: print "Double or more decays!!!11" + if len(info.decayLinks) >= 2: print("Double or more decays!!!11") for link in info.decayLinks: par_ind = link[0] dau_ind = link[1] @@ -1159,21 +1160,21 @@ def Save_Normalisation_Coefficients(ntuple_file): ''' norm_c = copy(layer_data_tmp) - print sum([val for ind, val in six.iteritems(norm_c)]) + print(sum([val for ind, val in six.iteritems(norm_c)])) for event in ntuple_file: - print event.entry()+1 + print(event.entry()+1) for particle in event.trackingParticles(): for hit in particle.hits(): if hit.isValidHit(): norm_c[layer_names_rev[hit.layerStr()]] += 1 norm_sum = sum([val for ind, val in six.iteritems(norm_c)]) - print norm_sum - print norm_c + print(norm_sum) + print(norm_c) for i, c in six.iteritems(norm_c): norm_c[i] = 1.0*c/norm_sum #normalisation = [1.0*c/norm_sum for c in norm_c] - print "normalisation_coefficients.dmp" - print norm_c + print("normalisation_coefficients.dmp") + print(norm_c) norm_file = open("normalisation_coefficients.dmp",'w') pickle.dump(norm_c, norm_file) @@ -1279,8 +1280,8 @@ def Analyse_EOT_Error(end_list, bpix3_mask = False, detId_mask = "all", pt_mask error.append(Distance(end.fake_end, end.particle_end)) elif detId_mask == "all": error.append(Distance(end.fake_end, end.particle_end)) - if error and error[-1] == 0.0: print "Error is 0.0?!" - if error and error[-1] > 10: print str(end.fake_end_detId) + " and " + str(end.particle_end_detId) + ": " + str(error[-1]) + " z: " + str(end.fake_end[2]) + " " + str(end.particle_end[2]) + if error and error[-1] == 0.0: print("Error is 0.0?!") + if error and error[-1] > 10: print(str(end.fake_end_detId) + " and " + str(end.particle_end_detId) + ": " + str(error[-1]) + " z: " + str(end.fake_end[2]) + " " + str(end.particle_end[2])) elif not bpix3_mask: if detId_mask == "same" and end.fake_end_detId == end.particle_end_detId: error.append(Distance(end.fake_end[0:2], end.particle_end[0:2])) @@ -1289,7 +1290,7 @@ def Analyse_EOT_Error(end_list, bpix3_mask = False, detId_mask = "all", pt_mask elif detId_mask == "all": error.append(Distance(end.fake_end, end.particle_end)) - print sum(error)/len(error) + print(sum(error)/len(error)) return error def EndOfTrackingDetectorInfo(end_list, end_mask = [0], BPix3mask = False): @@ -1304,8 +1305,8 @@ def EndOfTrackingDetectorInfo(end_list, end_mask = [0], BPix3mask = False): data.append(1) else: data.append(0) - print "Same detector id between fake end and particle end: " + str(sum(data)) - print "Different detector id: " + str(len(data)-sum(data)) + print("Same detector id between fake end and particle end: " + str(sum(data))) + print("Different detector id: " + str(len(data)-sum(data))) def Analyse_EOT_ParticleDoubleHit(end_list, layer = "BPix3", end_mask = [0,4]): ''' @@ -1321,7 +1322,7 @@ def Analyse_EOT_ParticleDoubleHit(end_list, layer = "BPix3", end_mask = [0,4]): #print end.end_class all_particles += 1 - print "In layer " + layer + " there are " + str(doubles) + " end of trackings out of " + str(all_particles) + " (" + str(100.0*doubles/all_particles) + ") which have a double hit in the EOT layer" + print("In layer " + layer + " there are " + str(doubles) + " end of trackings out of " + str(all_particles) + " (" + str(100.0*doubles/all_particles) + ") which have a double hit in the EOT layer") def TrackPt(ntuple_file, nEvents = 100): ''' @@ -1332,7 +1333,7 @@ def TrackPt(ntuple_file, nEvents = 100): i = 0 for event in ntuple_file: - print "Event: " + str(i) + print("Event: " + str(i)) for track in event.tracks(): if track.nMatchedTrackingParticles() == 0: fake_pts.append(track.pt()) diff --git a/Validation/RecoTrack/test/fakeAnalysis/graphics.py b/Validation/RecoTrack/test/fakeAnalysis/graphics.py index 2c6a6090c61f0..9a23281b04883 100644 --- a/Validation/RecoTrack/test/fakeAnalysis/graphics.py +++ b/Validation/RecoTrack/test/fakeAnalysis/graphics.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import ROOT from array import array from copy import copy @@ -241,7 +242,7 @@ def PlotTrack3D(self, track, color = 1): Y.append(hit.y()) Z.append(hit.z()) if(not X): - print "Track has no valid points" + print("Track has no valid points") return plot = ROOT.TPolyLine3D(len(X),array("f",Z),array("f",X),array("f",Y)) plot.SetLineColor(color) @@ -478,7 +479,7 @@ def PlotFakes(self, event, reconstructed = 1, fake_filter = None, end_filter = N elif hit.isValidHit() and hit.z() < 0: self.PlotDetectorRange("n",4) else: self.PlotDetectorRange("b",4) - print "****************************\n" + print("****************************\n") self.Draw() return @@ -488,15 +489,15 @@ def DrawTrackTest(self, track): def ParticleTest(self, particles, draw=False): for particle in particles: - print "\nPARTICLE " + str(particle.index()) + print("\nPARTICLE " + str(particle.index())) for hit in particle.hits(): tof = -1 for simHit in hit.simHits(): if simHit.trackingParticle().index() == particle.index(): #if len(info.tof()): tof = simHit.tof() - print "Index: " + str(hit.index()) + ", Layer: " + str(hit.layerStr()) + ", TOF: " + str(tof) +\ - " XY distance: " + str(sqrt(hit.x()**2 + hit.y()**2)) + ", Z: " + str(hit.z()) + print("Index: " + str(hit.index()) + ", Layer: " + str(hit.layerStr()) + ", TOF: " + str(tof) +\ + " XY distance: " + str(sqrt(hit.x()**2 + hit.y()**2)) + ", Z: " + str(hit.z())) self.DrawTrackTest(particle) if draw: self.Draw() @@ -749,7 +750,7 @@ def ResolutionHistograms(self, res_data, tracks = "fake", fake_mask = [], draw = if normalised: color = ROOT.kBlue else: color = 38 else: - print "Unspecified data type" + print("Unspecified data type") return c1 = ROOT.TCanvas("Resolution_histograms","Resolution histograms", 1000, 900) diff --git a/Validation/RecoTrack/test/fakeAnalysis/graphics_vertical.py b/Validation/RecoTrack/test/fakeAnalysis/graphics_vertical.py index de06223080e7e..09bd743d0a844 100644 --- a/Validation/RecoTrack/test/fakeAnalysis/graphics_vertical.py +++ b/Validation/RecoTrack/test/fakeAnalysis/graphics_vertical.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import ROOT from array import array @@ -231,7 +232,7 @@ def PlotTrack3D(self, track, color = 1): Y.append(hit.y()) Z.append(hit.z()) if(not X): - print "Track has no valid points" + print("Track has no valid points") return plot = ROOT.TPolyLine3D(len(X),array("f",X),array("f",Y),array("f",Z)) plot.SetLineColor(color) @@ -526,7 +527,7 @@ def PlotFakes(self, event, reconstructed = 1, fake_filter = None, end_filter = N elif hit.isValid() and hit.z() < 0: self.PlotDetectorRange("n",4) else: self.PlotDetectorRange("b",4) - print "****************************\n" + print("****************************\n") self.Draw() return @@ -560,15 +561,15 @@ def DrawTrackTest(self, track): def ParticleTest(self, particles, draw=False): for particle in particles: - print "\nPARTICLE " + str(particle.index()) + print("\nPARTICLE " + str(particle.index())) for hit in particle.hits(): tof = -1 for info in hit.matchedTrackingParticleInfos(): if info.trackingParticle().index() == particle.index(): #if len(info.tof()): tof = info.tof() - print "Index: " + str(hit.index()) + ", Layer: " + str(hit.layerStr()) + ", TOF: " + str(tof) +\ - " XY distance: " + str(sqrt(hit.x()**2 + hit.y()**2)) + ", Z: " + str(hit.z()) + print("Index: " + str(hit.index()) + ", Layer: " + str(hit.layerStr()) + ", TOF: " + str(tof) +\ + " XY distance: " + str(sqrt(hit.x()**2 + hit.y()**2)) + ", Z: " + str(hit.z())) self.DrawTrackTest(particle) if draw: self.Draw() diff --git a/Validation/RecoTrack/test/publicPlots/plot.py b/Validation/RecoTrack/test/publicPlots/plot.py index d2b8d9acb537e..1df0b7e55cf3c 100755 --- a/Validation/RecoTrack/test/publicPlots/plot.py +++ b/Validation/RecoTrack/test/publicPlots/plot.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import copy import math import array @@ -531,7 +532,7 @@ def main(): plotMemory("90x_ttbar_phase1_vs_pu", peakrss_trajectory, ["2017 90X IB", "2017 90X IB+#17098"], [stylePhase1, stylePhase1CA]) printEffFake(files1, pileup) - print "With CA" + print("With CA") printEffFake(files1ca, pileup) @@ -883,7 +884,7 @@ def plotFake(files, prefix, pileup): vreco = d[coll] vassoc = dassoc[coll] vfake = vreco[0]-vassoc[0] - print vfake, norm + print(vfake, norm) hnew.SetBinContent(i+1, vfake) hnew.SetBinError(i+1, math.sqrt(vfake)) newhistos.append(hnew) @@ -1173,7 +1174,7 @@ def plotTime(fileCollections, prefix, pileups, legends, styles): gr = ROOT.TGraph(len(pileups), array.array("d", pileups), array.array("d", [t*normfactor for t in times])) graphs.append(gr) - print "Time normalization factor", normfactor + print("Time normalization factor", normfactor) plot = Plot(graphs, legends, styles) @@ -1317,7 +1318,7 @@ def plotMemory(prefix, data, legends, styles): ################################################################################ ################################################################################ def printEffFake(files, pileup): - print "For pileup", pileup + print("For pileup", pileup) for f, l in zip(files.getFiles(), files.getLegends()): eff_h = f.Get("DQMData/Run 1/Tracking/Run summary/Track/effic_vs_coll") fake_h = f.Get("DQMData/Run 1/Tracking/Run summary/Track/fakerate_vs_coll") @@ -1325,16 +1326,16 @@ def printEffFake(files, pileup): eff_d = plotting._th1ToOrderedDict(eff_h) fake_d = plotting._th1ToOrderedDict(fake_h) - print l + print(l) #coll = "generalTracks" #collPt = coll coll = "cutsRecoTracksHp" collPt = "cutsRecoTracksPt09Hp" - print "Efficiency", eff_d[coll] - print "Fake rate ", fake_d[coll] - print "Efficiency (track pt>0.9)", eff_d[collPt] - print "Fake rate (track pt>0.9)", fake_d[collPt] + print("Efficiency", eff_d[coll]) + print("Fake rate ", fake_d[coll]) + print("Efficiency (track pt>0.9)", eff_d[collPt]) + print("Fake rate (track pt>0.9)", fake_d[collPt]) diff --git a/Validation/RecoTrack/test/trackingNtupleExample.py b/Validation/RecoTrack/test/trackingNtupleExample.py index 7749a04ca1390..c9831d49b2390 100755 --- a/Validation/RecoTrack/test/trackingNtupleExample.py +++ b/Validation/RecoTrack/test/trackingNtupleExample.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import ROOT from Validation.RecoTrack.plotting.ntuple import * @@ -265,52 +266,52 @@ def main(): tot_track_seeds_true += ntracktrue - print "Processed %d events" % tot_nevents - print "On average %f tracks from PV" % (float(tot_pv_ntracks)/tot_nevents) - print "On average %f TrackingParticles" % (float(tot_tps)/tot_nevents) - print " with %f %% reconstructed" % (float(tot_recoed)/tot_tps * 100) - print " of which %f %% were reconstructed at least twice" % (float(tot_tp_dups)/tot_recoed * 100) - print " average fraction of non-recoed hits %f %%" % (tot_tp_nonrecohits/tot_tps * 100) - print "On average %f tracks" % (float(tot_ntracks)/tot_nevents) - print " with %f %% being high purity" % (float(tot_hptracks)/tot_ntracks * 100) - print " with %f %% were not used in any vertex fit" % (float(tot_novertex)/tot_ntracks * 100) - print " with %f %% of true tracks being secondaries" % (float(tot_secondaries)/(tot_ntracks-tot_fakes) * 100) - print " with fake rate %f %%" % (float(tot_fakes)/tot_ntracks * 100) + print("Processed %d events" % tot_nevents) + print("On average %f tracks from PV" % (float(tot_pv_ntracks)/tot_nevents)) + print("On average %f TrackingParticles" % (float(tot_tps)/tot_nevents)) + print(" with %f %% reconstructed" % (float(tot_recoed)/tot_tps * 100)) + print(" of which %f %% were reconstructed at least twice" % (float(tot_tp_dups)/tot_recoed * 100)) + print(" average fraction of non-recoed hits %f %%" % (tot_tp_nonrecohits/tot_tps * 100)) + print("On average %f tracks" % (float(tot_ntracks)/tot_nevents)) + print(" with %f %% being high purity" % (float(tot_hptracks)/tot_ntracks * 100)) + print(" with %f %% were not used in any vertex fit" % (float(tot_novertex)/tot_ntracks * 100)) + print(" with %f %% of true tracks being secondaries" % (float(tot_secondaries)/(tot_ntracks-tot_fakes) * 100)) + print(" with fake rate %f %%" % (float(tot_fakes)/tot_ntracks * 100)) if tot_fakes_npixhits > 0: - print " on average %f %% of pixel hits are true" % (float(tot_fakes_npixhits_true)/tot_fakes_npixhits * 100) - print " pixel hits from %f TrackingParticles/track" % (float(tot_fakes_npixhits_tps)/tot_fakes) - print " on average %f %% of strip hits are true" % (float(tot_fakes_nstrhits_true)/tot_fakes_nstrhits * 100) - print " on average %f %% of hits are invalid" % (float(tot_fakes_ninvalidhits)/(tot_fakes_npixhits+tot_fakes_nstrhits) * 100) - print " of those, %f %% were missing" % (float(tot_fakes_ninvalidhits_missing)/tot_fakes_ninvalidhits * 100) - print " of those, %f %% were invalid" % (float(tot_fakes_ninvalidhits_inactive)/tot_fakes_ninvalidhits * 100) - print " with duplicate rate %f %%" % (float(tot_duplicates)/tot_ntracks * 100) + print(" on average %f %% of pixel hits are true" % (float(tot_fakes_npixhits_true)/tot_fakes_npixhits * 100)) + print(" pixel hits from %f TrackingParticles/track" % (float(tot_fakes_npixhits_tps)/tot_fakes)) + print(" on average %f %% of strip hits are true" % (float(tot_fakes_nstrhits_true)/tot_fakes_nstrhits * 100)) + print(" on average %f %% of hits are invalid" % (float(tot_fakes_ninvalidhits)/(tot_fakes_npixhits+tot_fakes_nstrhits) * 100)) + print(" of those, %f %% were missing" % (float(tot_fakes_ninvalidhits_missing)/tot_fakes_ninvalidhits * 100)) + print(" of those, %f %% were invalid" % (float(tot_fakes_ninvalidhits_inactive)/tot_fakes_ninvalidhits * 100)) + print(" with duplicate rate %f %%" % (float(tot_duplicates)/tot_ntracks * 100)) if tot_seeds > 0: - print " of which %f %% had a true seed" % (float(tot_track_seeds_true)/tot_ntracks * 100) - print "On average %f seeds" % (float(tot_seeds)/tot_nevents) - print " of which %f were from lowPtTripletStep" % (float(tot_seeds_lowPtTriplet)/tot_nevents) - print " of which %f %% were true" % (float(tot_seeds_true)/tot_seeds * 100) - print " of which %f %% did not produce a track" % (float(tot_seeds_notrack)/tot_seeds * 100) - print " on average %f pixel hits / seed" % (float(tot_seeds_pixelhits)/tot_seeds) - print " on average %f strip hits / seed" % (float(tot_seeds_striphits)/tot_seeds) - print " on average %f glued hits / seed" % (float(tot_seeds_gluedhits)/tot_seeds) + print(" of which %f %% had a true seed" % (float(tot_track_seeds_true)/tot_ntracks * 100)) + print("On average %f seeds" % (float(tot_seeds)/tot_nevents)) + print(" of which %f were from lowPtTripletStep" % (float(tot_seeds_lowPtTriplet)/tot_nevents)) + print(" of which %f %% were true" % (float(tot_seeds_true)/tot_seeds * 100)) + print(" of which %f %% did not produce a track" % (float(tot_seeds_notrack)/tot_seeds * 100)) + print(" on average %f pixel hits / seed" % (float(tot_seeds_pixelhits)/tot_seeds)) + print(" on average %f strip hits / seed" % (float(tot_seeds_striphits)/tot_seeds)) + print(" on average %f glued hits / seed" % (float(tot_seeds_gluedhits)/tot_seeds)) if tot_pix > 0: - print "On average %f pixel hits" % (float(tot_pix)/tot_nevents) - print " on average %f tracks per hit" % (float(tot_pix_ntracks)/tot_pix) - print " on average %f seeds per hit" % (float(tot_pix_nseeds)/tot_pix) - print " on average %f energy loss per hit" % (tot_pix_eloss/tot_pix) - print " on average %f %% from hard scatter" % (float(tot_pix_signal)/tot_pix*100) - print " on average %f %% from in-time pileup" % (float(tot_pix_itpu)/tot_pix*100) - print " on average %f %% from out-of-time pileup" % (float(tot_pix_ootpu)/tot_pix*100) - print " on average %f %% from noise" % (float(tot_pix_noise)/tot_pix*100) - print "On average %f strip hits" % (float(tot_str)/tot_nevents) - print " on average %f tracks per hit" % (float(tot_str_ntracks)/tot_str) - print " on average %f seeds per hit" % (float(tot_str_nseeds)/tot_str) - print " on average %f %% from hard scatter" % (float(tot_str_signal)/tot_str*100) - print " on average %f %% from in-time pileup" % (float(tot_str_itpu)/tot_str*100) - print " on average %f %% from out-of-time pileup" % (float(tot_str_ootpu)/tot_str*100) - print " on average %f %% from noise" % (float(tot_str_noise)/tot_str*100) - print "On average %f glued hits" % (float(tot_glu)/tot_nevents) - print " on average %f seeds per hit" % (float(tot_glu_nseeds)/tot_glu) + print("On average %f pixel hits" % (float(tot_pix)/tot_nevents)) + print(" on average %f tracks per hit" % (float(tot_pix_ntracks)/tot_pix)) + print(" on average %f seeds per hit" % (float(tot_pix_nseeds)/tot_pix)) + print(" on average %f energy loss per hit" % (tot_pix_eloss/tot_pix)) + print(" on average %f %% from hard scatter" % (float(tot_pix_signal)/tot_pix*100)) + print(" on average %f %% from in-time pileup" % (float(tot_pix_itpu)/tot_pix*100)) + print(" on average %f %% from out-of-time pileup" % (float(tot_pix_ootpu)/tot_pix*100)) + print(" on average %f %% from noise" % (float(tot_pix_noise)/tot_pix*100)) + print("On average %f strip hits" % (float(tot_str)/tot_nevents)) + print(" on average %f tracks per hit" % (float(tot_str_ntracks)/tot_str)) + print(" on average %f seeds per hit" % (float(tot_str_nseeds)/tot_str)) + print(" on average %f %% from hard scatter" % (float(tot_str_signal)/tot_str*100)) + print(" on average %f %% from in-time pileup" % (float(tot_str_itpu)/tot_str*100)) + print(" on average %f %% from out-of-time pileup" % (float(tot_str_ootpu)/tot_str*100)) + print(" on average %f %% from noise" % (float(tot_str_noise)/tot_str*100)) + print("On average %f glued hits" % (float(tot_glu)/tot_nevents)) + print(" on average %f seeds per hit" % (float(tot_glu_nseeds)/tot_glu)) if __name__ == "__main__":