File indexing completed on 2023-03-17 11:27:53
0001
0002
0003 from __future__ import print_function
0004 import os
0005 import argparse
0006 from time import time
0007
0008 from Validation.HGCalValidation.PostProcessorHGCAL_cfi import tracksterLabels as trackstersIters
0009
0010 from Validation.RecoTrack.plotting.validation import SeparateValidation, SimpleValidation, SimpleSample
0011 from Validation.HGCalValidation.HGCalValidator_cfi import hgcalValidator
0012 import Validation.HGCalValidation.hgcalPlots as hgcalPlots
0013 import Validation.RecoTrack.plotting.plotting as plotting
0014
0015 simClustersIters = [hgcalValidator.label_SimClustersLevel._InputTag__moduleLabel, "ticlSimTracksters"]
0016
0017 hitCalLabel = 'hitCalibration'
0018 hitValLabel = 'hitValidation'
0019 layerClustersLabel = 'layerClusters'
0020 trackstersLabel = 'tracksters'
0021 trackstersWithEdgesLabel = 'trackstersWithEdges'
0022 simLabel = 'simulation'
0023 allLabel = 'all'
0024
0025 collection_choices = [allLabel]
0026 collection_choices.extend([hitCalLabel]+[hitValLabel]+[layerClustersLabel]+[trackstersLabel]+[trackstersWithEdgesLabel]+[simLabel])
0027
0028 def main(opts):
0029
0030 drawArgs={}
0031 extendedFlag = False
0032 if opts.no_ratio:
0033 drawArgs["ratio"] = False
0034 if opts.separate:
0035 drawArgs["separate"] = True
0036 if opts.png:
0037 drawArgs["saveFormat"] = ".png"
0038 if opts.extended:
0039 extendedFlag = True
0040 if opts.verbose:
0041 plotting.verbose = True
0042
0043 filenames = [(f, f.replace(".root", "")) for f in opts.files]
0044 sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
0045
0046 val = SimpleValidation([sample], opts.outputDir[0])
0047 if opts.separate:
0048 val = SeparateValidation([sample], opts.outputDir[0])
0049 htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
0050
0051
0052 def plot_LC():
0053 hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
0054 hgcalPlots.append_hgcalLayerClustersPlots(hgcalValidator.label_layerClusterPlots._InputTag__moduleLabel, "Layer Clusters", extendedFlag)
0055 val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
0056
0057
0058 def plot_SC():
0059 hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
0060 for i_iter in simClustersIters:
0061 hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter)
0062 val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)
0063
0064
0065 def plot_Tst():
0066 hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
0067 for tracksterCollection in trackstersIters :
0068 hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection)
0069 val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
0070
0071
0072 def plot_TstEdges():
0073 plot_Tst()
0074 for tracksterCollection in trackstersIters :
0075 hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
0076 val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
0077
0078
0079 def plot_CP():
0080 particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
0081 "muon-": "-13", "muon+":"13",
0082 "electron-": "-11", "electron+": "11", "photon": "22",
0083 "kaon0L": "310", "kaon0S": "130",
0084 "kaon-": "-321", "kaon+": "321"}
0085 hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
0086 for i_part, i_partID in particletypes.items() :
0087 hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
0088 val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)
0089
0090
0091 def plot_hitVal():
0092 hgchit = [hgcalPlots.hgcalHitPlotter]
0093 hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
0094 hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
0095 hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
0096 val.doPlots(hgchit, plotterDrawArgs=drawArgs)
0097
0098
0099 def plot_hitCal():
0100 hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
0101 val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
0102
0103
0104 plotDict = {hitCalLabel:[plot_hitCal], hitValLabel:[plot_hitVal], layerClustersLabel:[plot_LC], trackstersLabel:[plot_Tst], trackstersWithEdgesLabel:[plot_TstEdges], simLabel:[plot_SC, plot_CP]}
0105
0106 if (opts.collection != allLabel):
0107 for task in plotDict[opts.collection]:
0108 task()
0109 else:
0110 for label in plotDict:
0111 if (label == trackstersLabel): continue
0112 for task in plotDict[label]:
0113 task()
0114
0115 if opts.no_html:
0116 print("Plots created into directory '%s'." % opts.outputDir)
0117 else:
0118 htmlReport.write()
0119
0120 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)))
0121
0122 if __name__ == "__main__":
0123 parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
0124 parser.add_argument("files", metavar="file", type=str, nargs="+",
0125 default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
0126 help="DQM file to plot the validation plots from")
0127 parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
0128 help="Plot output directories (default: 'plots1'")
0129 parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
0130 help="Prefix for subdirectories inside outputDir (default: 'plots1')")
0131 parser.add_argument("--no-ratio", action="store_true", default = False,
0132 help="Disable ratio pads")
0133 parser.add_argument("--separate", action="store_true", default = False,
0134 help="Save all plots separately instead of grouping them")
0135 parser.add_argument("--png", action="store_true",
0136 help="Save plots in PNG instead of PDF")
0137 parser.add_argument("--no-html", action="store_true", default = False,
0138 help="Disable HTML page generation")
0139 parser.add_argument("--html-sample", default="Sample",
0140 help="Sample name for HTML page generation (default 'Sample')")
0141 parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
0142 help="Validation name for HTML page generation (enters to <title> element) (default '')")
0143 parser.add_argument("--collection", choices=collection_choices, default=layerClustersLabel,
0144 help="Choose output plots collections among possible choices")
0145 parser.add_argument("--extended", action="store_true", default = False,
0146 help="Include extended set of plots (e.g. bunch of distributions; default off)")
0147 parser.add_argument("--verbose", action="store_true", default = False,
0148 help="Be verbose")
0149
0150 opts = parser.parse_args()
0151
0152 for f in opts.files:
0153 if not os.path.exists(f):
0154 parser.error("DQM file %s does not exist" % f)
0155
0156 main(opts)