Skip to content

Commit

Permalink
Generalize makeTrackValidationPlots.py to work on all subfolders of T…
Browse files Browse the repository at this point in the history
…racking/Track in the DQM files
  • Loading branch information
makortel committed Jun 29, 2015
1 parent 935c79b commit a31046a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
76 changes: 44 additions & 32 deletions Validation/RecoTrack/python/plotting/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,52 +706,64 @@ 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:
algos = [None]

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:
Expand Down
20 changes: 5 additions & 15 deletions Validation/RecoTrack/scripts/makeTrackValidationPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down

0 comments on commit a31046a

Please sign in to comment.