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 simClustersIters = ["ClusterLevel","ticlTrackstersTrkEM","ticlTrackstersEM","ticlTrackstersTrk","ticlTrackstersHAD","ticlSimTracksters"]
13 
14 trackstersIters = ["ticlMultiClustersFromTrackstersMerge", "ticlMultiClustersFromTrackstersMIP",
15  "ticlMultiClustersFromTrackstersTrk","ticlMultiClustersFromTrackstersTrkEM",
16  "ticlMultiClustersFromTrackstersEM", "ticlMultiClustersFromTrackstersHAD",
17  "ticlMultiClustersFromSimTracksters"]
18 
19 simClustersGeneralLabel = 'simClusters'
20 layerClustersGeneralLabel = 'hgcalLayerClusters'
21 multiclustersGeneralLabel = 'hgcalMultiClusters'
22 trackstersGeneralLabel = 'allTiclMultiClusters'
23 hitValidationLabel = 'hitValidation'
24 hitCalibrationLabel = 'hitCalibration'
25 caloParticlesLabel = 'caloParticles'
26 allLabel = 'all'
27 
28 collection_choices = [layerClustersGeneralLabel]
29 collection_choices.extend([simClustersGeneralLabel]+[multiclustersGeneralLabel]+[trackstersGeneralLabel]+[hitValidationLabel]+[hitCalibrationLabel]+[allLabel]+[caloParticlesLabel])
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 
46  filenames = [(f, f.replace(".root", "")) for f in opts.files]
47  sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
48 
49  val = SimpleValidation([sample], opts.outputDir[0])
50  if opts.separate:
51  val = SeparateValidation([sample], opts.outputDir[0])
52  htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
53 
54  #layerClusters
55  if (opts.collection == layerClustersGeneralLabel):
56  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
57  hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters", extendedFlag)
58  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
59  #simClusters
60  elif (opts.collection == simClustersGeneralLabel):
61  hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
62  for i_iter in simClustersIters:
64  val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)
65  #multiClusters
66  elif (opts.collection == multiclustersGeneralLabel):
67  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
68  hgcalPlots.append_hgcalMultiClustersPlots(multiclustersGeneralLabel, "MultiClusters")
69  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
70  #ticlTracksters
71  elif (opts.collection == trackstersGeneralLabel):
72  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
73  for i_iter in trackstersIters :
74  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
75  hgcalPlots.append_hgcalMultiClustersPlots(i_iter, tracksterCollection)
76  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
77  # TICLTrackstersEdges plots
78  for i_iter in trackstersIters :
79  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
80  hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
81  val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
82  elif (opts.collection == caloParticlesLabel):
83  particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
84  "muon-": "-13", "muon+":"13",
85  "electron-": "-11", "electron+": "11", "photon": "22",
86  "kaon0L": "310", "kaon0S": "130",
87  "kaon-": "-321", "kaon+": "321"}
88  hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
89  for i_part, i_partID in particletypes.iteritems() :
90  hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
91  val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)
92  #hitValidation
93  elif (opts.collection == hitValidationLabel):
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  #hitCalibration
100  elif (opts.collection == hitCalibrationLabel):
101  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
102  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
103  elif (opts.collection == allLabel):
104  #caloparticles
105  particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
106  "muon-": "-13", "muon+":"13",
107  "electron-": "-11", "electron+": "11", "photon": "22",
108  "kaon0L": "310", "kaon0S": "130",
109  "kaon-": "-321", "kaon+": "321"}
110  hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
111  for i_part, i_partID in particletypes.iteritems() :
112  hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
113  val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)
114 
115  #hits
116  hgchit = [hgcalPlots.hgcalHitPlotter]
117  hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
118  hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
119  hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
120  val.doPlots(hgchit, plotterDrawArgs=drawArgs)
121 
122  #calib
123  hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
124  val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
125 
126  #simClusters
127  hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
128  for i_iter in simClustersIters :
130  val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)
131 
132  #layer clusters
133  hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
134  hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters", extendedFlag)
135  val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
136 
137  #multiclusters
138  hgcmulticlus = [hgcalPlots.hgcalMultiClustersPlotter]
139  for i_iter in trackstersIters :
140  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
141  hgcalPlots.append_hgcalMultiClustersPlots(i_iter, tracksterCollection)
142  val.doPlots(hgcmulticlus, plotterDrawArgs=drawArgs)
143  #TICLTrackstersEdges plots
144  for i_iter in trackstersIters :
145  tracksterCollection = i_iter.replace("ticlMultiClustersFromTracksters","ticlTracksters")
146  hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
147  val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
148 
149 
150  if opts.no_html:
151  print("Plots created into directory '%s'." % opts.outputDir)
152  else:
153  htmlReport.write()
154 
155  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)))
156 
157 if __name__ == "__main__":
158  parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
159  parser.add_argument("files", metavar="file", type=str, nargs="+",
160  default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
161  help="DQM file to plot the validation plots from")
162  parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
163  help="Plot output directories (default: 'plots1'")
164  parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
165  help="Prefix for subdirectories inside outputDir (default: 'plots1')")
166  parser.add_argument("--no-ratio", action="store_true", default = False,
167  help="Disable ratio pads")
168  parser.add_argument("--separate", action="store_true", default = False,
169  help="Save all plots separately instead of grouping them")
170  parser.add_argument("--png", action="store_true",
171  help="Save plots in PNG instead of PDF")
172  parser.add_argument("--no-html", action="store_true", default = False,
173  help="Disable HTML page generation")
174  parser.add_argument("--html-sample", default="Sample",
175  help="Sample name for HTML page generation (default 'Sample')")
176  parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
177  help="Validation name for HTML page generation (enters to <title> element) (default '')")
178  parser.add_argument("--collection", choices=collection_choices, default=layerClustersGeneralLabel,
179  help="Choose output plots collections among possible choices")
180  parser.add_argument("--extended", action="store_true", default = False,
181  help="Include extended set of plots (e.g. bunch of distributions; default off)")
182  parser.add_argument("--verbose", action="store_true", default = False,
183  help="Be verbose")
184 
185  opts = parser.parse_args()
186 
187  for f in opts.files:
188  if not os.path.exists(f):
189  parser.error("DQM file %s does not exist" % f)
190 
191  main(opts)
hgcalPlots.append_hgcalCaloParticlesPlots
def append_hgcalCaloParticlesPlots(files, collection='-211', name_collection="pion-")
Definition: hgcalPlots.py:2489
hgcalPlots.append_hgcalDigisPlots
def append_hgcalDigisPlots(collection="HGCalDigisV", name_collection="Digis")
Definition: hgcalPlots.py:2742
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:2456
hgcalPlots.append_hgcalSimClustersPlots
def append_hgcalSimClustersPlots(collection, name_collection)
Definition: hgcalPlots.py:2407
makeHGCalValidationPlots.main
def main(opts)
Definition: makeHGCalValidationPlots.py:31
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:2673
main
Definition: main.py:1
hgcalPlots.create_hgcalTrackstersPlotter
def create_hgcalTrackstersPlotter(files, collection='ticlTrackstersMerge', name_collection="MultiClustersMerge")
Definition: hgcalPlots.py:2540
hgcalPlots.append_hgcalLayerClustersPlots
def append_hgcalLayerClustersPlots(collection="hgcalLayerClusters", name_collection=layerClustersLabel, extended=False)
Definition: hgcalPlots.py:2267