CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
makeHGCalValidationPlots.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 from time import time
7 
8 from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, ticlIterLabelsMerge
9 
10 from Validation.RecoTrack.plotting.validation import SeparateValidation, SimpleValidation, SimpleSample
11 from Validation.HGCalValidation.HGCalValidator_cfi import hgcalValidator
12 import Validation.HGCalValidation.hgcalPlots as hgcalPlots
13 import Validation.RecoTrack.plotting.plotting as plotting
14 
15 simClustersIters = [hgcalValidator.label_SimClustersLevel._InputTag__moduleLabel, "ticlSimTracksters"]
16 trackstersIters = ['ticlTracksters'+iteration for iteration in ticlIterLabelsMerge]
17 trackstersIters.extend(["ticlSimTracksters"])
18 
19 hitCalLabel = 'hitCalibration'
20 hitValLabel = 'hitValidation'
21 layerClustersLabel = 'layerClusters'
22 trackstersLabel = 'tracksters'
23 trackstersWithEdgesLabel = 'trackstersWithEdges'
24 simLabel = 'simulation'
25 allLabel = 'all'
26 
27 collection_choices = [allLabel]
28 collection_choices.extend([hitCalLabel]+[hitValLabel]+[layerClustersLabel]+[trackstersLabel]+[trackstersWithEdgesLabel]+[simLabel])
29 
30 def main(opts):
31 
32  drawArgs={}
33  extendedFlag = False
34  if opts.no_ratio:
35  drawArgs["ratio"] = False
36  if opts.separate:
37  drawArgs["separate"] = True
38  if opts.png:
39  drawArgs["saveFormat"] = ".png"
40  if opts.extended:
41  extendedFlag = True
42  if opts.verbose:
43  plotting.verbose = True
44 
45  filenames = [(f, f.replace(".root", "")) for f in opts.files]
46  sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
47 
48  val = SimpleValidation([sample], opts.outputDir[0])
49  if opts.separate:
50  val = SeparateValidation([sample], opts.outputDir[0])
51  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
52 
53  #layerClusters
54  def plot_LC():
55  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
56  hgcalPlots.append_hgcalLayerClustersPlots(hgcalValidator.label_layerClusterPlots._InputTag__moduleLabel, "Layer Clusters", extendedFlag)
57  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
58 
59  #simClusters
60  def plot_SC():
61  hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
62  for i_iter in simClustersIters:
64  val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)
65 
66  #tracksters
67  def plot_Tst():
68  hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
69  for tracksterCollection in trackstersIters :
70  hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection)
71  val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
72 
73  #trackstersWithEdges
74  def plot_TstEdges():
75  plot_Tst()
76  for tracksterCollection in trackstersIters :
77  hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
78  val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
79 
80  #caloParticles
81  def plot_CP():
82  particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
83  "muon-": "-13", "muon+":"13",
84  "electron-": "-11", "electron+": "11", "photon": "22",
85  "kaon0L": "310", "kaon0S": "130",
86  "kaon-": "-321", "kaon+": "321"}
87  hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
88  for i_part, i_partID in particletypes.items() :
89  hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
90  val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)
91 
92  #hitValidation
93  def plot_hitVal():
94  hgchit = [hgcalPlots.hgcalHitPlotter]
95  hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
96  hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
97  hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
98  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
99 
100  #hitCalibration
101  def plot_hitCal():
102  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
103  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
104 
105 
106  plotDict = {hitCalLabel:[plot_hitCal], hitValLabel:[plot_hitVal], layerClustersLabel:[plot_LC], trackstersLabel:[plot_Tst], trackstersWithEdgesLabel:[plot_TstEdges], simLabel:[plot_SC, plot_CP]}
107 
108  if (opts.collection != allLabel):
109  for task in plotDict[opts.collection]:
110  task()
111  else:
112  for label in plotDict:
113  if (label == trackstersLabel): continue # already run in trackstersWithEdges
114  for task in plotDict[label]:
115  task()
116 
117  if opts.no_html:
118  print("Plots created into directory '%s'." % opts.outputDir)
119  else:
120  htmlReport.write()
121 
122  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)))
123 
124 if __name__ == "__main__":
125  parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
126  parser.add_argument("files", metavar="file", type=str, nargs="+",
127  default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
128  help="DQM file to plot the validation plots from")
129  parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
130  help="Plot output directories (default: 'plots1'")
131  parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
132  help="Prefix for subdirectories inside outputDir (default: 'plots1')")
133  parser.add_argument("--no-ratio", action="store_true", default = False,
134  help="Disable ratio pads")
135  parser.add_argument("--separate", action="store_true", default = False,
136  help="Save all plots separately instead of grouping them")
137  parser.add_argument("--png", action="store_true",
138  help="Save plots in PNG instead of PDF")
139  parser.add_argument("--no-html", action="store_true", default = False,
140  help="Disable HTML page generation")
141  parser.add_argument("--html-sample", default="Sample",
142  help="Sample name for HTML page generation (default 'Sample')")
143  parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
144  help="Validation name for HTML page generation (enters to <title> element) (default '')")
145  parser.add_argument("--collection", choices=collection_choices, default=layerClustersLabel,
146  help="Choose output plots collections among possible choices")
147  parser.add_argument("--extended", action="store_true", default = False,
148  help="Include extended set of plots (e.g. bunch of distributions; default off)")
149  parser.add_argument("--verbose", action="store_true", default = False,
150  help="Be verbose")
151 
152  opts = parser.parse_args()
153 
154  for f in opts.files:
155  if not os.path.exists(f):
156  parser.error("DQM file %s does not exist" % f)
157 
158  main(opts)
def append_hgcalSimClustersPlots
Definition: hgcalPlots.py:2414
def append_hgcalDigisPlots
Definition: hgcalPlots.py:2764
def append_hgcalCaloParticlesPlots
Definition: hgcalPlots.py:2507
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def append_hgcalTrackstersPlots
Definition: hgcalPlots.py:2466
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def create_hgcalTrackstersPlotter
Definition: hgcalPlots.py:2558
def append_hgcalHitsPlots
Definition: hgcalPlots.py:2695
Definition: main.py:1
def append_hgcalLayerClustersPlots
Definition: hgcalPlots.py:2274