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