Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:40

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