Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-16 05:06:45

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import os
0005 import argparse
0006 import datetime
0007 
0008 from RecoHGCal.TICL.iterativeTICL_cff import ticlIterLabels, ticlIterLabels_v5
0009 
0010 from Validation.RecoTrack.plotting.validation import SeparateValidation, SimpleValidation, SimpleSample
0011 from Validation.HGCalValidation.HGCalValidator_cff 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 candidatesLabel = 'candidates'
0023 simLabel = 'simulation'
0024 allLabel = 'all'
0025 ticlVersions = [4, 5]
0026 ticlVersion = 4
0027 collection_choices = [allLabel]
0028 collection_choices.extend([hitCalLabel]+[hitValLabel]+[layerClustersLabel]+[trackstersLabel]+[trackstersWithEdgesLabel]+[candidatesLabel]+[simLabel])
0029 tracksters = []
0030 
0031 def main(opts):
0032 
0033     drawArgs={}
0034     extendedFlag = False
0035     if opts.no_ratio:
0036         drawArgs["ratio"] = False
0037     if opts.separate:
0038         drawArgs["separate"] = True
0039     if opts.png:
0040         drawArgs["saveFormat"] = ".png"
0041     if opts.extended:
0042         extendedFlag = True
0043     if opts.verbose:
0044         plotting.verbose = True
0045     if opts.ticlv == 5:
0046         ticlVersion = 5
0047 
0048     filenames = [(f, f.replace(".root", "")) for f in opts.files]
0049     sample = SimpleSample(opts.subdirprefix[0], opts.html_sample, filenames)
0050 
0051     val = SimpleValidation([sample], opts.outputDir[0], nProc=opts.jobs)
0052     if opts.separate:
0053         val = SeparateValidation([sample], opts.outputDir[0])
0054     htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])
0055     trackstersIters = []
0056     if (ticlVersion == 5):
0057         trackstersIters = ticlIterLabels_v5.copy()
0058         trackstersIters.extend(['ticlTracksterLinksSuperclusteringDNN','ticlTracksterLinksSuperclusteringMustache'])
0059     else:
0060         trackstersIters = ticlIterLabels.copy()
0061     trackstersIters.extend(['ticlSimTracksters', 'ticlSimTracksters_fromCPs'])
0062     #layerClusters
0063     def plot_LC():
0064         hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
0065         hgcalPlots.append_hgcalLayerClustersPlots(hgcalValidator.label_layerClusterPlots._InputTag__moduleLabel, "Layer Clusters", extendedFlag)
0066         val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)
0067 
0068     #simClusters
0069     def plot_SC():
0070         hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
0071         for i_iter in simClustersIters:
0072             hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter)
0073         val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)
0074 
0075     #tracksters
0076     def plot_Tst():
0077 
0078         hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
0079         for tracksterCollection in trackstersIters :
0080             print("Searching for tracksters collection in DQM files: ", tracksterCollection)
0081 
0082             hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection)
0083         val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
0084 
0085     #trackstersWithEdges
0086     def plot_TstEdges():
0087         plot_Tst()
0088         for tracksterCollection in trackstersIters :
0089             hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
0090             val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
0091 
0092     #caloParticles
0093     def plot_CP():
0094         particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
0095                          "muon-": "-13", "muon+":"13",
0096                          "electron-": "-11", "electron+": "11", "photon": "22",
0097                          "kaon0L": "310", "kaon0S": "130",
0098                          "kaon-": "-321", "kaon+": "321"}
0099         hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
0100         for i_part, i_partID in particletypes.items() :
0101             hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
0102         val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)
0103 
0104     #hitValidation
0105     def plot_hitVal():
0106         hgchit = [hgcalPlots.hgcalHitPlotter]
0107         hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
0108         hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
0109         hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
0110         val.doPlots(hgchit, plotterDrawArgs=drawArgs)
0111 
0112     #hitCalibration
0113     def plot_hitCal():
0114         hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
0115         val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
0116 
0117     def plotCand():
0118         ticlcand = [hgcalPlots.hgcalTICLCandPlotter]
0119         val.doPlots(ticlcand, plotterDrawArgs=drawArgs)
0120 
0121     plotDict = {hitCalLabel:[plot_hitCal], hitValLabel:[plot_hitVal], layerClustersLabel:[plot_LC], trackstersLabel:[plot_Tst], trackstersWithEdgesLabel:[plot_TstEdges], simLabel:[plot_SC, plot_CP], candidatesLabel:[plotCand]}
0122 
0123     if (opts.collection != allLabel):
0124         for task in plotDict[opts.collection]:
0125             task()
0126     else:
0127         for label in plotDict:
0128             if (label == trackstersLabel): continue # already run in trackstersWithEdges
0129             for task in plotDict[label]:
0130                 task()
0131 
0132     if opts.no_html:
0133         print("Plots created into directory '%s'." % opts.outputDir)
0134     else:
0135         htmlReport.write()
0136 
0137         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)))
0138 
0139 if __name__ == "__main__":
0140     parser = argparse.ArgumentParser(description="Create set of HGCal validation plots from one or more DQM files.")
0141     parser.add_argument("files", metavar="file", type=str, nargs="+",
0142                         default = "DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root",
0143                         help="DQM file to plot the validation plots from")
0144     parser.add_argument("-o", "--outputDir", type=str, default=["plots1","plots2"], nargs="+",
0145                         help="Plot output directories (default: 'plots1'")
0146     parser.add_argument("--subdirprefix", type=str, default=["plots1","plots2"], nargs="+",
0147                         help="Prefix for subdirectories inside outputDir (default: 'plots1')")
0148     parser.add_argument("--no-ratio", action="store_true", default = False,
0149                         help="Disable ratio pads")
0150     parser.add_argument("--separate", action="store_true", default = False,
0151                         help="Save all plots separately instead of grouping them")
0152     parser.add_argument("--png", action="store_true", default = True,
0153                         help="Save plots in PNG instead of PDF")
0154     parser.add_argument("--no-html", action="store_true", default = False,
0155                         help="Disable HTML page generation")
0156     parser.add_argument("--html-sample", default=os.environ['CMSSW_VERSION'],
0157                         help="Sample name for HTML page generation (default: CMSSW version)")
0158     parser.add_argument("--html-validation-name", type=str, default=["TICL Validation",""], nargs="+",
0159                         help="Validation name for HTML page generation (enters to <title> element) (default 'TICL Validation')")
0160     parser.add_argument("--collection", choices=collection_choices, default=layerClustersLabel,
0161                         help="Choose output plots collections among possible choices")
0162     parser.add_argument("--extended", action="store_true", default = False,
0163                         help="Include extended set of plots (e.g. bunch of distributions; default off)")
0164     parser.add_argument("--jobs", default=0, type=int,
0165                         help="Number of jobs to run in parallel for generating plots. Default is 0 i.e. run number of cpu cores jobs.")
0166     parser.add_argument("--ticlv", choices=ticlVersions, default=4, type=int,
0167                         help="TICL Version. Specify 4 or 5. Default 4.")
0168     parser.add_argument("--verbose", action="store_true", default = False,
0169                         help="Be verbose")
0170 
0171     opts = parser.parse_args()
0172 
0173     for f in opts.files:
0174         if not os.path.exists(f):
0175             parser.error("DQM file %s does not exist" % f)
0176 
0177     main(opts)