CMS 3D CMS Logo

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 
12  def __init__(self, algos, includePtCut):
13  self._algos = algos
14  self._includePtCut = includePtCut
15  def __call__(self, algo, quality):
16  if self._algos is not None and algo not in self._algos:
17  return False
18  if not self._includePtCut and "Pt09" in quality:
19  return False
20  return True
21 
22 def limitRelVal(algo, quality):
23  return quality in ["", "highPurity", "ByOriginalAlgo", "highPurityByOriginalAlgo"]
24 
25 def main(opts):
26  sample = SimpleSample(opts.subdirprefix, opts.html_sample, [(f, f.replace(".root", "")) for f in opts.files])
27 
28  drawArgs={}
29  if opts.no_ratio:
30  drawArgs["ratio"] = False
31  if opts.separate:
32  drawArgs["separate"] = True
33  if opts.png:
34  drawArgs["saveFormat"] = ".png"
35  if opts.verbose:
36  plotting.verbose = True
37 
38  val = SimpleValidation([sample], opts.outputDir)
39  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name)
40 
41  limitProcessing = LimitTrackAlgo(opts.limit_tracking_algo, includePtCut=opts.ptcut)
42  kwargs_tracking = {
43  "limitSubFoldersOnlyTo": {
44  "": limitProcessing,
45  "allTPEffic": limitProcessing,
46  "fromPV": limitProcessing,
47  "fromPVAllTP": limitProcessing,
48  "tpPtLess09": limitProcessing,
49  "seeding": limitProcessing,
50  "building": limitProcessing,
51  "bhadron": limitProcessing,
52  }
53  }
54  if opts.limit_relval:
55  ignore = lambda a,q: False
56  kwargs_tracking["limitSubFoldersOnlyTo"] = {
57  "": limitRelVal,
58  "allTPEffic": ignore,
59  "fromPV": ignore,
60  "fromPVAllTP": ignore,
61  "tpPtLess09": limitRelVal,
62  "seeding": ignore,
63  "bhadron": limitRelVal,
64  }
65 
66  trk = [trackingPlots.plotter]
67  other = [trackingPlots.timePlotter, vertexPlots.plotter, trackingPlots.plotterHLT]
68  if opts.extended:
69  trk.append(trackingPlots.plotterExt)
70  other.extend([vertexPlots.plotterExt, trackingPlots.plotterHLTExt])
71  val.doPlots(trk, plotterDrawArgs=drawArgs, **kwargs_tracking)
72  val.doPlots(other, plotterDrawArgs=drawArgs)
73  print
74  if opts.no_html:
75  print "Plots created into directory '%s'." % opts.outputDir
76  else:
77  htmlReport.write()
78  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
79 
80 if __name__ == "__main__":
81  parser = argparse.ArgumentParser(description="Create standard set of tracking validation plots from one or more DQM files.")
82  parser.add_argument("files", metavar="file", type=str, nargs="+",
83  help="DQM file to plot the validation plots from")
84  parser.add_argument("-o", "--outputDir", type=str, default="plots",
85  help="Plot output directory (default: 'plots')")
86  parser.add_argument("--subdirprefix", type=str, default="plots",
87  help="Prefix for subdirectories inside outputDir (default: 'plots')")
88  parser.add_argument("--no-ratio", action="store_true",
89  help="Disable ratio pads")
90  parser.add_argument("--separate", action="store_true",
91  help="Save all plots separately instead of grouping them")
92  parser.add_argument("--png", action="store_true",
93  help="Save plots in PNG instead of PDF")
94  parser.add_argument("--limit-tracking-algo", type=str, default=None,
95  help="Comma separated list of tracking algos to limit to. (default: all algos; conflicts with --limit-relval)")
96  parser.add_argument("--limit-relval", action="store_true",
97  help="Limit set of plots to those in release validation (almost). (default: all plots in the DQM files; conflicts with --limit-tracking-algo)")
98  parser.add_argument("--ptcut", action="store_true",
99  help="Include plots with pT > 0.9 GeV cut (with --limit-relval, does not have any effect)")
100  parser.add_argument("--extended", action="store_true",
101  help="Include extended set of plots (e.g. bunch of distributions; default off)")
102  parser.add_argument("--no-html", action="store_true",
103  help="Disable HTML page genration")
104  parser.add_argument("--html-sample", default="Sample",
105  help="Sample name for HTML page generation (default 'Sample')")
106  parser.add_argument("--html-validation-name", default="",
107  help="Validation name for HTML page generation (enters to <title> element) (default '')")
108  parser.add_argument("--verbose", action="store_true",
109  help="Be verbose")
110 
111  group = parser.add_argument_group("deprecated arguments (they have no effect and will be removed in the future):")
112  group.add_argument("--ignoreMissing", action="store_true",
113  help="Ignore missing histograms and directories (deprecated, is this is already the default mode)")
114  group.add_argument("--ratio", action="store_true",
115  help="Create ratio pads (deprecated, as it is already the default")
116  group.add_argument("--html", action="store_true",
117  help="Generate HTML pages (deprecated, as it is already the default")
118 
119  opts = parser.parse_args()
120  for f in opts.files:
121  if not os.path.exists(f):
122  parser.error("DQM file %s does not exist" % f)
123 
124  if opts.ignoreMissing:
125  print "--ignoreMissing is now the only operation mode, so you can stop using this parameter"
126 
127  if opts.ratio:
128  print "--ratio is now the default, so you can stop using this parameter"
129 
130  if opts.html:
131  print "--html is now the default, so you can stop using this parameter"
132 
133  if opts.limit_tracking_algo is not None:
134  if opts.limit_relval:
135  parser.error("--limit-tracking-algo and --limit-relval conflict with each other")
136  opts.limit_tracking_algo = opts.limit_tracking_algo.split(",")
137 
138  if opts.limit_relval and opts.ptcut:
139  print "With --limit-relval enabled, --ptcut option does not have any effect"
140 
141  main(opts)
Definition: main.py:1