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 from time import time
7 
8 from Validation.RecoTrack.plotting.validation import SeparateValidation, SimpleValidation, SimpleSample
9 import Validation.HGCalValidation.hgcalPlots as hgcalPlots
10 import Validation.RecoTrack.plotting.plotting as plotting
11 
12 trackstersIters = ["ticlMultiClustersFromTrackstersMerge", "ticlMultiClustersFromTrackstersMIP",
13  "ticlMultiClustersFromTrackstersTrk","ticlMultiClustersFromTrackstersTrkEM",
14  "ticlMultiClustersFromTrackstersEM", "ticlMultiClustersFromTrackstersHAD",
15  "ticlMultiClustersFromTrackstersDummy"]
16 
17 layerClustersGeneralLabel = 'hgcalLayerClusters'
18 multiclustersGeneralLabel = 'hgcalMultiClusters'
19 trackstersGeneralLabel = 'allTiclMultiClusters'
20 hitValidationLabel = 'hitValidation'
21 hitCalibrationLabel = 'hitCalibration'
22 allLabel = 'all'
23 
24 collection_choices = [layerClustersGeneralLabel]
25 collection_choices.extend([multiclustersGeneralLabel]+[trackstersGeneralLabel]+[hitValidationLabel]+[hitCalibrationLabel]+[allLabel])
26 
27 def main(opts):
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  filenames = [(f, f.replace(".root", "")) for f in opts.files]
40  sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
41 
42  val = SimpleValidation([sample], opts.outputDir[0])
43  if opts.separate:
44  val = SeparateValidation([sample], opts.outputDir[0])
45  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
46 
47  if opts.collection==layerClustersGeneralLabel:
48  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
49  hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters")
50  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
51  elif opts.collection == multiclustersGeneralLabel:
52  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
53  hgcalPlots.append_hgcalMultiClustersPlots(multiclustersGeneralLabel, "MultiClusters")
54  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
55  elif (opts.collection == trackstersGeneralLabel) :
56  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
57  for i_iter in trackstersIters :
58  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
59  hgcalPlots.append_hgcalMultiClustersPlots(i_iter, tracksterCollection)
60  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
61  elif opts.collection==hitValidationLabel:
62  hgchit = [hgcalPlots.hgcalHitPlotter]
63  hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
64  hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
65  hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
66  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
67  elif opts.collection==hitCalibrationLabel:
68  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
69  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
70  else :
71 
72  #hits
73  hgchit = [hgcalPlots.hgcalHitPlotter]
74  hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
75  hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
76  hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
77  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
78 
79  #calib
80  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
81  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
82 
83  #layer clusters
84  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
85  hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters")
86  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
87 
88  #multiclusters
89  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
90  for i_iter in trackstersIters :
91  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
92  hgcalPlots.append_hgcalMultiClustersPlots(i_iter, tracksterCollection)
93  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
94 
95  if opts.no_html:
96  print("Plots created into directory '%s'." % opts.outputDir)
97  else:
98  htmlReport.write()
99 
100  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)))
101 
102 if __name__ == "__main__":
103  parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
104  parser.add_argument("files", metavar="file", type=str, nargs="+",
105  default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
106  help="DQM file to plot the validation plots from")
107  parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
108  help="Plot output directories (default: 'plots1'")
109  parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
110  help="Prefix for subdirectories inside outputDir (default: 'plots1')")
111  parser.add_argument("--no-ratio", action="store_true", default = False,
112  help="Disable ratio pads")
113  parser.add_argument("--separate", action="store_true", default = False,
114  help="Save all plots separately instead of grouping them")
115  parser.add_argument("--png", action="store_true",
116  help="Save plots in PNG instead of PDF")
117  parser.add_argument("--no-html", action="store_true", default = False,
118  help="Disable HTML page generation")
119  parser.add_argument("--html-sample", default="Sample",
120  help="Sample name for HTML page generation (default 'Sample')")
121  parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
122  help="Validation name for HTML page generation (enters to <title> element) (default '')")
123  parser.add_argument("--verbose", action="store_true", default = False,
124  help="Be verbose")
125  parser.add_argument("--collection", choices=collection_choices, default=layerClustersGeneralLabel,
126  help="Choose output plots collections among possible choices")
127 
128  opts = parser.parse_args()
129 
130  for f in opts.files:
131  if not os.path.exists(f):
132  parser.error("DQM file %s does not exist" % f)
133 
134  main(opts)
hgcalPlots.append_hgcalDigisPlots
def append_hgcalDigisPlots(collection="HGCalDigisV", name_collection="Digis")
Definition: hgcalPlots.py:2121
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
hgcalPlots.append_hgcalMultiClustersPlots
def append_hgcalMultiClustersPlots(collection='ticlMultiClustersFromTrackstersMerge', name_collection="MultiClustersMerge")
Definition: hgcalPlots.py:2005
makeHGCalValidationPlots.main
def main(opts)
Definition: makeHGCalValidationPlots.py:27
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
hgcalPlots.append_hgcalHitsPlots
def append_hgcalHitsPlots(collection="HGCalSimHitsV", name_collection="Simulated Hits")
Definition: hgcalPlots.py:2052
main
Definition: main.py:1
hgcalPlots.append_hgcalLayerClustersPlots
def append_hgcalLayerClustersPlots(collection="hgcalLayerClusters", name_collection=layerClustersLabel)
Definition: hgcalPlots.py:1961