Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:34:05

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import os
0005 import argparse
0006 
0007 from Validation.RecoTrack.plotting.validation import SimpleValidation, SimpleSample
0008 import Validation.RecoTrack.plotting.trackingPlots as trackingPlots
0009 import Validation.RecoVertex.plotting.vertexPlots as vertexPlots
0010 import Validation.RecoTrack.plotting.plotting as plotting
0011 
0012 class LimitTrackAlgo:
0013     def __init__(self, algos, includePtCut):
0014         self._algos = algos
0015         self._includePtCut = includePtCut
0016     def __call__(self, algo, quality):
0017         if self._algos is not None and algo not in self._algos:
0018             return False
0019         if not self._includePtCut and "Pt09" in quality:
0020             return False
0021         return True
0022 
0023 def limitRelVal(algo, quality):
0024     return quality in ["", "highPurity", "ByOriginalAlgo", "highPurityByOriginalAlgo"]
0025 
0026 def main(opts):
0027     sample = SimpleSample(opts.subdirprefix, opts.html_sample, [(f, f.replace(".root", "")) for f in opts.files])
0028 
0029     drawArgs={}
0030     if opts.no_ratio:
0031         drawArgs["ratio"] = False
0032     if opts.separate:
0033         drawArgs["separate"] = True
0034     if opts.png:
0035         drawArgs["saveFormat"] = ".png"
0036     if opts.verbose:
0037         plotting.verbose = True
0038 
0039     val = SimpleValidation([sample], opts.outputDir)
0040     htmlReport = val.createHtmlReport(validationName=opts.html_validation_name)
0041 
0042     limitProcessing = LimitTrackAlgo(opts.limit_tracking_algo, includePtCut=opts.ptcut)
0043     kwargs_tracking = {
0044         "limitSubFoldersOnlyTo": {
0045             "": limitProcessing,
0046             "allTPEffic": limitProcessing,
0047             "fromPV": limitProcessing,
0048             "fromPVAllTP": limitProcessing,
0049             "tpPtLess09": limitProcessing,
0050             "tpEtaGreater2p7": limitProcessing,
0051             "seeding": limitProcessing,
0052             "building": limitProcessing,
0053             "bhadron": limitProcessing,
0054             "displaced": limitProcessing,
0055         }
0056     }
0057     if opts.limit_relval:
0058         ignore = lambda a,q: False
0059         kwargs_tracking["limitSubFoldersOnlyTo"] = {
0060             "": limitRelVal,
0061             "allTPEffic": ignore,
0062             "fromPV": ignore,
0063             "fromPVAllTP": ignore,
0064             "tpPtLess09": limitRelVal,
0065             "tpEtaGreater2p7": limitRelVal,
0066             "seeding": ignore,
0067             "bhadron": limitRelVal,
0068             "displaced": limitRelVal,
0069         }
0070 
0071     trk = [trackingPlots.plotter]
0072     other = [trackingPlots.timePlotter, vertexPlots.plotter, trackingPlots.plotterHLT]
0073     if opts.extended:
0074         trk.append(trackingPlots.plotterExt)
0075         other.extend([vertexPlots.plotterExt, trackingPlots.plotterHLTExt])
0076     val.doPlots(trk, plotterDrawArgs=drawArgs, **kwargs_tracking)
0077     val.doPlots(other, plotterDrawArgs=drawArgs)
0078     print()
0079     if opts.no_html:
0080         print("Plots created into directory '%s'." % opts.outputDir)
0081     else:
0082         htmlReport.write()
0083         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)
0084 
0085 if __name__ == "__main__":
0086     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")
0087     parser.add_argument("files", metavar="file", type=str, nargs="+",
0088                         help="DQM file to plot the validation plots from")
0089     parser.add_argument("-o", "--outputDir", type=str, default="plots",
0090                         help="Plot output directory (default: 'plots')")
0091     parser.add_argument("--subdirprefix", type=str, default="plots",
0092                         help="Prefix for subdirectories inside outputDir (default: 'plots')")
0093     parser.add_argument("--no-ratio", action="store_true",
0094                         help="Disable ratio pads")
0095     parser.add_argument("--separate", action="store_true",
0096                         help="Save all plots separately instead of grouping them")
0097     parser.add_argument("--png", action="store_true",
0098                         help="Save plots in PNG instead of PDF")
0099     parser.add_argument("--limit-tracking-algo", type=str, default=None,
0100                         help="Comma separated list of tracking algos to limit to. (default: all algos; conflicts with --limit-relval)")
0101     parser.add_argument("--limit-relval", action="store_true",
0102                         help="Limit set of plots to those in release validation (almost). (default: all plots in the DQM files; conflicts with --limit-tracking-algo)")
0103     parser.add_argument("--ptcut", action="store_true",
0104                         help="Include plots with pT > 0.9 GeV cut (with --limit-relval, does not have any effect)")
0105     parser.add_argument("--extended", action="store_true",
0106                         help="Include extended set of plots (e.g. bunch of distributions; default off)")
0107     parser.add_argument("--no-html", action="store_true",
0108                         help="Disable HTML page genration")
0109     parser.add_argument("--html-sample", default="Sample",
0110                         help="Sample name for HTML page generation (default 'Sample')")
0111     parser.add_argument("--html-validation-name", default="",
0112                         help="Validation name for HTML page generation (enters to <title> element) (default '')")
0113     parser.add_argument("--verbose", action="store_true",
0114                         help="Be verbose")
0115 
0116     group = parser.add_argument_group("deprecated arguments (they have no effect and will be removed in the future):")
0117     group.add_argument("--ignoreMissing", action="store_true",
0118                        help="Ignore missing histograms and directories (deprecated, is this is already the default mode)")
0119     group.add_argument("--ratio", action="store_true",
0120                        help="Create ratio pads (deprecated, as it is already the default")
0121     group.add_argument("--html", action="store_true",
0122                        help="Generate HTML pages (deprecated, as it is already the default")
0123 
0124     opts = parser.parse_args()
0125     for f in opts.files:
0126         if not os.path.exists(f):
0127             parser.error("DQM file %s does not exist" % f)
0128 
0129     if opts.ignoreMissing:
0130         print("--ignoreMissing is now the only operation mode, so you can stop using this parameter")
0131 
0132     if opts.ratio:
0133         print("--ratio is now the default, so you can stop using this parameter")
0134 
0135     if opts.html:
0136         print("--html is now the default, so you can stop using this parameter")
0137 
0138     if opts.limit_tracking_algo is not None:
0139         if opts.limit_relval:
0140             parser.error("--limit-tracking-algo and --limit-relval conflict with each other")
0141         opts.limit_tracking_algo = opts.limit_tracking_algo.split(",")
0142 
0143     if opts.limit_relval and opts.ptcut:
0144         print("With --limit-relval enabled, --ptcut option does not have any effect")
0145 
0146     main(opts)