CMS 3D CMS Logo

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