CMS 3D CMS Logo

makeHGCalValidationPlots.py
Go to the documentation of this file.
1 #!/usr/bin/env python
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.HGCalValidation.hgcalPlots as hgcalPlots
9 import Validation.RecoTrack.plotting.plotting as plotting
10 
11 def main(opts):
12 
13  drawArgs={}
14  if opts.no_ratio:
15  drawArgs["ratio"] = False
16  if opts.separate:
17  drawArgs["separate"] = True
18  if opts.png:
19  drawArgs["saveFormat"] = ".png"
20  if opts.verbose:
21  plotting.verbose = True
22 
23  filenames = [(f, f.replace(".root", "")) for f in opts.files]
24  sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
25 
26  val = SimpleValidation([sample], opts.outputDir[0])
27  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
28 
29  if opts.collection=="hgcalLayerClusters":
30  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
31  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
32  elif opts.collection in ["hgcalMultiClusters", "multiClustersFromTrackstersMIP", "multiClustersFromTrackstersTrk", "multiClustersFromTrackstersEM", "multiClustersFromTrackstersHAD"]:
33  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
34  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
35  elif opts.collection=="hitValidation":
36  hgchit = [hgcalPlots.hgcalHitPlotter]
37  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
38  elif opts.collection=="hitCalibration":
39  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
40  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
41  else :
42  #In case of all you have to keep a specific order in one to one
43  #correspondance between subdirprefix and collections and validation names
44  #layer clusters
45  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
46  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
47  #multiclusters
48  sample = SimpleSample(opts.subdirprefix[1], opts.html_sample, filenames)
49  val = SimpleValidation([sample], opts.outputDir[1])
50  htmlReport_2 = val.createHtmlReport(validationName=opts.html_validation_name[1])
51  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
52  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
53  #hits
54  sample = SimpleSample(opts.subdirprefix[2], opts.html_sample, filenames)
55  val = SimpleValidation([sample], opts.outputDir[2])
56  htmlReport_3 = val.createHtmlReport(validationName=opts.html_validation_name[2])
57  hgchit = [hgcalPlots.hgcalHitPlotter]
58  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
59  #calib
60  sample = SimpleSample(opts.subdirprefix[3], opts.html_sample, filenames)
61  val = SimpleValidation([sample], opts.outputDir[3])
62  htmlReport_4 = val.createHtmlReport(validationName=opts.html_validation_name[3])
63  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
64  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
65 
66  if opts.no_html:
67  print("Plots created into directory '%s'." % opts.outputDir)
68  else:
69  htmlReport.write()
70  if(opts.collection=="all"):
71  htmlReport_2.write()
72  htmlReport_3.write()
73  htmlReport_4.write()
74 
75  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" % (','.join(opts.outputDir)))
76 
77 if __name__ == "__main__":
78  parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
79  parser.add_argument("files", metavar="file", type=str, nargs="+",
80  default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
81  help="DQM file to plot the validation plots from")
82  parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
83  help="Plot output directories (default: 'plots1'")
84  parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
85  help="Prefix for subdirectories inside outputDir (default: 'plots1')")
86  parser.add_argument("--no-ratio", action="store_true", default = False,
87  help="Disable ratio pads")
88  parser.add_argument("--separate", action="store_true", default = False,
89  help="Save all plots separately instead of grouping them")
90  parser.add_argument("--png", action="store_true",
91  help="Save plots in PNG instead of PDF")
92  parser.add_argument("--no-html", action="store_true", default = False,
93  help="Disable HTML page generation")
94  parser.add_argument("--html-sample", default="Sample",
95  help="Sample name for HTML page generation (default 'Sample')")
96  parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
97  help="Validation name for HTML page generation (enters to <title> element) (default '')")
98  parser.add_argument("--verbose", action="store_true", default = False,
99  help="Be verbose")
100  parser.add_argument("--collection", choices=["hgcalLayerClusters", "hgcalMultiClusters", "multiClustersFromTrackstersMIP", "multiClustersFromTrackstersTrk", "multiClustersFromTrackstersEM", "multiClustersFromTrackstersHAD", "hitValidation", "hitCalibration", "all"], default="hgcalLayerClusters",
101  help="Choose output plots collections: hgcalLayerCluster, hgcalMultiClusters, multiClustersFromTrackstersMIP, multiClustersFromTrackstersTrk, multiClustersFromTrackstersEM, multiClustersFromTrackstersHAD, hitValidation, hitCalibration, all")
102 
103  opts = parser.parse_args()
104 
105  if opts.collection == "all" and len(opts.outputDir)==1:
106  raise RuntimeError("need to assign names for all dirrectories")
107 
108  for f in opts.files:
109  if not os.path.exists(f):
110  parser.error("DQM file %s does not exist" % f)
111 
112  main(opts)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
Definition: main.py:1