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