diff --git a/Validation/RecoTrack/python/plotting/validation.py b/Validation/RecoTrack/python/plotting/validation.py index f6bfbe496aa1c..baeff7338184d 100644 --- a/Validation/RecoTrack/python/plotting/validation.py +++ b/Validation/RecoTrack/python/plotting/validation.py @@ -706,6 +706,13 @@ def doPlots(self, algos, qualities, plotter, algoDirMap=None, newdirFunc=None, p self._newdirFunc = newdirFunc self._plotterDrawArgs = plotterDrawArgs + self._openFiles = [] + for f in self._files: + if not os.path.exists(f): + print "File %s not found" % f + sys.exit(1) + self._openFiles.append(ROOT.TFile.Open(f)) + if qualities is None: qualities = [None] if algos is None: @@ -713,45 +720,50 @@ def doPlots(self, algos, qualities, plotter, algoDirMap=None, newdirFunc=None, p for q in qualities: for a in algos: - self._doPlots(a, q) + subdir = None + if self._algoDirMap is not None: + if hasattr(self._algoDirMap, "__call__"): + subdir = self._algoDirMap(algo, quality) + else: + subdir = self._algoDirMap[quality][algo] + self._doPlots(a, q, subdir) + + for tf in self._openFiles: + tf.Close() + self._openFiles = [] + + def doPlotsAuto(self, plotter, subdirToAlgoQuality, newdirFunc=None, plotterDrawArgs={}): + self._plotter = plotter + self._newdirFunc = newdirFunc + self._plotterDrawArgs = plotterDrawArgs - def _doPlots(self, algo, quality): - openFiles = [] + self._openFiles = [] for f in self._files: if not os.path.exists(f): print "File %s not found" % f sys.exit(1) - openFiles.append(ROOT.TFile.Open(f)) - - # dirs = [] - # for tf in openFiles: - # theDir = None - # for pd in self._plotter.getPossibleDirectoryNames(): - # theDir = tf.GetDirectory(pd) - # if theDir: - # break - # if not theDir: - # print "Did not find any of %s directories from file %s" % (",".join(self._plotter.getPossibleDirectoryNames()), tf.GetName()) - # sys.exit(1) - # if self._algoDirMap is not None: - # d = theDir.Get(self._algoDirMap[quality][algo]) - # if not theDir: - # print "Did not find dir %s from %s" % (self._algoDirMap[quality][algo], theDir.GetPath()) - # sys.exit(1) - # theDir = d - # dirs.append(theDir) - - subdir = None - if self._algoDirMap is not None: - if hasattr(self._algoDirMap, "__call__"): - subdir = self._algoDirMap(algo, quality) - else: - subdir = self._algoDirMap[quality][algo] - self._plotter.create(openFiles, self._labels, subdir=subdir) - fileList = self._plotter.draw(algo, **self._plotterDrawArgs) + self._openFiles.append(ROOT.TFile.Open(f)) + + theDir = None + for pd in self._plotter.getPossibleDirectoryNames(): + theDir = self._openFiles[0].GetDirectory(pd) + if theDir: + break + if not theDir: + print "Did not find any of %s directories from file %s" % (",".join(self._plotter.getPossibleDirectoryNames()), tf.GetName()) + sys.exit(1) + + subdirs = [key.GetName() for key in theDir.GetListOfKeys()] + for s in subdirs: + self._doPlots(*subdirToAlgoQuality(s), subdir=s) - for tf in openFiles: + for tf in self._openFiles: tf.Close() + self._openFiles = [] + + def _doPlots(self, algo, quality, subdir): + self._plotter.create(self._openFiles, self._labels, subdir=subdir) + fileList = self._plotter.draw(algo, **self._plotterDrawArgs) newdir = self._newdir if self._newdirFunc is not None: diff --git a/Validation/RecoTrack/scripts/makeTrackValidationPlots.py b/Validation/RecoTrack/scripts/makeTrackValidationPlots.py index 49a674cce10c1..c29faecd2be95 100755 --- a/Validation/RecoTrack/scripts/makeTrackValidationPlots.py +++ b/Validation/RecoTrack/scripts/makeTrackValidationPlots.py @@ -7,20 +7,11 @@ from Validation.RecoTrack.plotting.validation import SimpleValidation import Validation.RecoTrack.plotting.trackingPlots as trackingPlots -Algos= ['ootb', 'initialStep', 'lowPtTripletStep', 'pixelPairStep', 'detachedTripletStep', 'mixedTripletStep', 'pixelLessStep', 'tobTecStep', 'jetCoreRegionalStep', 'muonSeededStepInOut', 'muonSeededStepOutIn'] -Qualities=['', 'highPurity'] - def newdirname(algo, quality): - ret = "" - if quality != "": - ret += "_"+quality - if not (algo == "ootb" and quality != ""): - ret += "_"+algo - - if ret != "" and ret[0] == "_": - ret = ret[1:] + return algo+"_"+quality - return ret +def subdirToAlgoQuality(subdir): + return subdir.split("_") def main(opts): files = opts.files @@ -35,11 +26,10 @@ def main(opts): drawArgs["saveFormat"] = ".png" val = SimpleValidation(files, labels, opts.outputDir) - val.doPlots(Algos, Qualities, trackingPlots.plotter, algoDirMap=trackingPlots._tracks_map, newdirFunc=newdirname, - plotterDrawArgs=drawArgs) + val.doPlotsAuto(trackingPlots.plotter, subdirToAlgoQuality=subdirToAlgoQuality, newdirFunc=newdirname, plotterDrawArgs=drawArgs) if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Create standard set of tracking validation plots from one or more DQM files") + parser = argparse.ArgumentParser(description="Create standard set of tracking validation plots from one or more DQM files. Note that the output directory structure is not exactly the same as with test/trackingPerformanceValidation.py or test/trackingCompare.py") parser.add_argument("files", metavar="file", type=str, nargs="+", help="DQM file to plot the validation plots from") parser.add_argument("-o", "--outputDir", type=str, default="plots",