CMS 3D CMS Logo

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