CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
makeTrackValidationPlots.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import argparse
5 
6 from Validation.RecoTrack.plotting.validation import SimpleValidation, SimpleSample
7 import Validation.RecoTrack.plotting.trackingPlots as trackingPlots
8 import Validation.RecoVertex.plotting.vertexPlots as vertexPlots
9 import Validation.RecoTrack.plotting.plotting as plotting
10 
11 def main(opts):
12  files = opts.files
13  labels = [f.replace(".root", "") for f in files]
14 
15  drawArgs={}
16  if opts.ratio:
17  drawArgs["ratio"] = True
18  if opts.separate:
19  drawArgs["separate"] = True
20  if opts.png:
21  drawArgs["saveFormat"] = ".png"
22  if opts.verbose:
23  plotting.verbose = True
24 
25  val = SimpleValidation(files, labels, opts.outputDir)
26  kwargs = {}
27  if opts.html:
28  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name)
29  htmlReport.beginSample(SimpleSample(opts.html_prefix, opts.html_sample))
30  kwargs["htmlReport"] = htmlReport
31  val.doPlots(trackingPlots.plotter, subdirprefix=opts.subdirprefix, plotterDrawArgs=drawArgs, **kwargs)
32  val.doPlots(trackingPlots.timePlotter, subdirprefix=opts.subdirprefix, plotterDrawArgs=drawArgs, **kwargs)
33  val.doPlots(vertexPlots.plotter, subdirprefix=opts.subdirprefix, plotterDrawArgs=drawArgs, **kwargs)
34  print
35  if opts.html:
36  htmlReport.write()
37  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
38  else:
39  print "Plots created into directory '%s'." % opts.outputDir
40 
41 if __name__ == "__main__":
42  parser = argparse.ArgumentParser(description="Create standard set of tracking validation plots from one or more DQM files.")
43  parser.add_argument("files", metavar="file", type=str, nargs="+",
44  help="DQM file to plot the validation plots from")
45  parser.add_argument("-o", "--outputDir", type=str, default="plots",
46  help="Plot output directory (default: 'plots')")
47  parser.add_argument("--subdirprefix", type=str, default="plots",
48  help="Prefix for subdirectories inside outputDir (default: 'plots')")
49  parser.add_argument("--ignoreMissing", action="store_true",
50  help="Ignore missing histograms and directories")
51  parser.add_argument("--ratio", action="store_true",
52  help="Create ratio pads")
53  parser.add_argument("--separate", action="store_true",
54  help="Save all plots separately instead of grouping them")
55  parser.add_argument("--png", action="store_true",
56  help="Save plots in PNG instead of PDF")
57  parser.add_argument("--html", action="store_true",
58  help="Generate HTML pages")
59  parser.add_argument("--html-prefix", default="plots",
60  help="Prefix for HTML page generation (default 'plots')")
61  parser.add_argument("--html-sample", default="Sample",
62  help="Sample name for HTML page generation (default 'Sample')")
63  parser.add_argument("--html-validation-name", default="",
64  help="Validation name for HTML page generation (enters to <title> element) (default '')")
65  parser.add_argument("--verbose", action="store_true",
66  help="Be verbose")
67 
68  opts = parser.parse_args()
69  for f in opts.files:
70  if not os.path.exists(f):
71  parser.error("DQM file %s does not exist" % f)
72 
73  if opts.ignoreMissing:
74  print "--ignoreMissing is now the only operation mode, so you can stop using this parameter"
75 
76  main(opts)
Definition: main.py:1