Skip to content

Commit

Permalink
Merge pull request #33639 from lecriste/makeHGCalValidationPlots_simp…
Browse files Browse the repository at this point in the history
…lify_master

[HGCAL] Simplify makeHGCalValidationPlots
  • Loading branch information
cmsbuild committed May 7, 2021
2 parents 074f0c6 + e1963e7 commit 02a115f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 89 deletions.
52 changes: 28 additions & 24 deletions Validation/HGCalValidation/python/hgcalPlots.py
Expand Up @@ -2505,7 +2505,7 @@ def append_hgcalCaloParticlesPlots(files, collection = '-211', name_collection =
name = obj.GetName()
fileName = TString(name)
fileName.ReplaceAll(" ","_")
pg= PlotGroup(fileName.Data(),[
pg = PlotGroup(fileName.Data(),[
Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
drawCommand = "",
Expand All @@ -2514,7 +2514,7 @@ def append_hgcalCaloParticlesPlots(files, collection = '-211', name_collection =
ncols=1)

if name in list_2D_histos :
pg= PlotOnSideGroup(plotName.Data(),
pg = PlotOnSideGroup(plotName.Data(),
Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
drawCommand = "COLZ",
Expand Down Expand Up @@ -2576,7 +2576,7 @@ def create_hgcalTrackstersPlotter(files, collection = 'ticlTrackstersMerge', nam
drawCommand = "COLZ",
**_common),
ncols=1)
else:
elif obj.InheritsFrom("TH1"):
pg = PlotGroup(plotName.Data(),
[Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
Expand All @@ -2585,12 +2585,13 @@ def create_hgcalTrackstersPlotter(files, collection = 'ticlTrackstersMerge', nam
],
ncols=1, legendDh=-0.03 * len(files))

hgcalTrackstersPlotter.append(name_collection+"_TICLDebugger",
[dqmfolder], PlotFolder(pg,
loopSubFolders=False,
purpose=PlotPurpose.Timing, page="Tracksters", section=name_collection)
#numberOfEventsHistogram=_multiplicity_tracksters_numberOfEventsHistogram)
)
if (pg is not None):
hgcalTrackstersPlotter.append(name_collection+"_TICLDebugger",
[dqmfolder], PlotFolder(pg,
loopSubFolders=False,
purpose=PlotPurpose.Timing, page="Tracksters", section=name_collection)
#numberOfEventsHistogram=_multiplicity_tracksters_numberOfEventsHistogram)
)

key = keys.After(key)

Expand Down Expand Up @@ -2623,29 +2624,32 @@ def append_hgcalCaloParticlesPlots(files, collection = '-211', name_collection =
name = obj.GetName()
plotName = TString(name)
plotName.ReplaceAll(" ","_")
pg= PlotGroup(plotName.Data(),[
Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
drawCommand = "", # may want to customize for TH2 (colz, etc.)
normalizeToNumberOfEvents = True, **_common_Calo)
],
ncols=1)

pg = None
if obj.InheritsFrom("TH2"):
pg= PlotOnSideGroup(plotName.Data(),
pg = PlotOnSideGroup(plotName.Data(),
Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
drawCommand = "COLZ",
normalizeToNumberOfEvents = True, **_common_Calo),
ncols=1)
elif obj.InheritsFrom("TH1"):
pg = PlotGroup(plotName.Data(),[
Plot(name,
xtitle=obj.GetXaxis().GetTitle(), ytitle=obj.GetYaxis().GetTitle(),
drawCommand = "", # may want to customize for TH2 (colz, etc.)
normalizeToNumberOfEvents = True, **_common_Calo)
],
ncols=1)

hgcalCaloParticlesPlotter.append("CaloParticles_"+name_collection, [
dqmfolder
], PlotFolder(
pg,
loopSubFolders=False,
purpose=PlotPurpose.Timing, page="CaloParticles", section=name_collection)
)
if (pg is not None):
hgcalCaloParticlesPlotter.append("CaloParticles_"+name_collection, [
dqmfolder
], PlotFolder(
pg,
loopSubFolders=False,
purpose=PlotPurpose.Timing, page="CaloParticles", section=name_collection)
)

key = keys.After(key)

Expand Down
98 changes: 33 additions & 65 deletions Validation/HGCalValidation/scripts/makeHGCalValidationPlots.py
Expand Up @@ -12,22 +12,18 @@
import Validation.RecoTrack.plotting.plotting as plotting

simClustersIters = ["ClusterLevel","ticlSimTracksters"]
simClustersIters.extend('ticlTracksters'+iteration for iteration in ticlIterLabels)

trackstersIters = ['ticlTracksters'+iteration for iteration in ticlIterLabelsMerge]
trackstersIters.extend(["ticlSimTracksters"])

simClustersGeneralLabel = 'simClusters'
layerClustersGeneralLabel = 'hgcalLayerClusters'
trackstersGeneralLabel = 'hgcalTracksters'
allTrackstersLabel = 'allTiclTracksters'
hitValidationLabel = 'hitValidation'
hitCalibrationLabel = 'hitCalibration'
caloParticlesLabel = 'caloParticles'
hitLabel = 'recHits'
layerClustersLabel = 'layerClusters'
trackstersLabel = 'tracksters'
trackstersWithEdgesLabel = 'trackstersWithEdges'
simLabel = 'simulation'
allLabel = 'all'

collection_choices = [layerClustersGeneralLabel]
collection_choices.extend([simClustersGeneralLabel]+[trackstersGeneralLabel]+[allTrackstersLabel]+[hitValidationLabel]+[hitCalibrationLabel]+[allLabel]+[caloParticlesLabel])
collection_choices = [allLabel]
collection_choices.extend([hitLabel]+[layerClustersLabel]+[trackstersLabel]+[trackstersWithEdgesLabel]+[simLabel])

def main(opts):

Expand All @@ -53,32 +49,34 @@ def main(opts):
htmlReport = val.createHtmlReport(validationName=opts.html_validation_name[0])

#layerClusters
if (opts.collection == layerClustersGeneralLabel):
def plot_LC():
hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters", extendedFlag)
val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)

#simClusters
elif (opts.collection == simClustersGeneralLabel):
def plot_SC():
hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
for i_iter in simClustersIters:
hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter)
val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)

#tracksters
elif (opts.collection == trackstersGeneralLabel):
hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
hgcalPlots.append_hgcalTrackstersPlots(trackstersGeneralLabel, "Tracksters")
val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
#ticlTracksters
elif (opts.collection == allTrackstersLabel):
def plot_Tst():
hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
for tracksterCollection in trackstersIters :
hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection)
val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
# TICLTrackstersEdges plots

#trackstersWithEdges
def plot_TstEdges():
plot_Tst()
for tracksterCollection in trackstersIters :
hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
elif (opts.collection == caloParticlesLabel):

#caloParticles
def plot_CP():
particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
"muon-": "-13", "muon+":"13",
"electron-": "-11", "electron+": "11", "photon": "22",
Expand All @@ -88,61 +86,31 @@ def main(opts):
for i_part, i_partID in particletypes.iteritems() :
hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)

#hitValidation
elif (opts.collection == hitValidationLabel):
def plot_hitVal():
hgchit = [hgcalPlots.hgcalHitPlotter]
hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
val.doPlots(hgchit, plotterDrawArgs=drawArgs)
#hitCalibration
elif (opts.collection == hitCalibrationLabel):
hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)
elif (opts.collection == allLabel):
#caloparticles
particletypes = {"pion-":"-211", "pion+":"211", "pion0": "111",
"muon-": "-13", "muon+":"13",
"electron-": "-11", "electron+": "11", "photon": "22",
"kaon0L": "310", "kaon0S": "130",
"kaon-": "-321", "kaon+": "321"}
hgcaloPart = [hgcalPlots.hgcalCaloParticlesPlotter]
for i_part, i_partID in particletypes.iteritems() :
hgcalPlots.append_hgcalCaloParticlesPlots(sample.files(), i_partID, i_part)
val.doPlots(hgcaloPart, plotterDrawArgs=drawArgs)

#hits
hgchit = [hgcalPlots.hgcalHitPlotter]
hgcalPlots.append_hgcalHitsPlots('HGCalSimHitsV', "Simulated Hits")
hgcalPlots.append_hgcalHitsPlots('HGCalRecHitsV', "Reconstruced Hits")
hgcalPlots.append_hgcalDigisPlots('HGCalDigisV', "Digis")
val.doPlots(hgchit, plotterDrawArgs=drawArgs)

#calib
#hitCalibration
def plot_hitCal():
hgchitcalib = [hgcalPlots.hgcalHitCalibPlotter]
val.doPlots(hgchitcalib, plotterDrawArgs=drawArgs)

#simClusters
hgcsimclus = [hgcalPlots.hgcalSimClustersPlotter]
for i_iter in simClustersIters :
hgcalPlots.append_hgcalSimClustersPlots(i_iter, i_iter)
val.doPlots(hgcsimclus, plotterDrawArgs=drawArgs)

#layer clusters
hgclayclus = [hgcalPlots.hgcalLayerClustersPlotter]
hgcalPlots.append_hgcalLayerClustersPlots("hgcalLayerClusters", "Layer Clusters", extendedFlag)
val.doPlots(hgclayclus, plotterDrawArgs=drawArgs)

#tracksters
hgctrackster = [hgcalPlots.hgcalTrackstersPlotter]
for tracksterCollection in trackstersIters :
hgcalPlots.append_hgcalTrackstersPlots(tracksterCollection, tracksterCollection)
val.doPlots(hgctrackster, plotterDrawArgs=drawArgs)
#TICLTrackstersEdges plots
for tracksterCollection in trackstersIters :
hgctracksters = [hgcalPlots.create_hgcalTrackstersPlotter(sample.files(), tracksterCollection, tracksterCollection)]
val.doPlots(hgctracksters, plotterDrawArgs=drawArgs)
plotDict = {hitLabel:[plot_hitVal, plot_hitCal], layerClustersLabel:[plot_LC], trackstersLabel:[plot_Tst], trackstersWithEdgesLabel:[plot_TstEdges], simLabel:[plot_SC, plot_CP]}

if (opts.collection != allLabel):
for task in plotDict[opts.collection]:
task()
else:
for label in plotDict:
if (label == trackstersLabel): continue # already run in trackstersWithEdges
for task in plotDict[label]:
task()

if opts.no_html:
print("Plots created into directory '%s'." % opts.outputDir)
Expand Down Expand Up @@ -172,7 +140,7 @@ def main(opts):
help="Sample name for HTML page generation (default 'Sample')")
parser.add_argument("--html-validation-name", type=str, default=["",""], nargs="+",
help="Validation name for HTML page generation (enters to <title> element) (default '')")
parser.add_argument("--collection", choices=collection_choices, default=layerClustersGeneralLabel,
parser.add_argument("--collection", choices=collection_choices, default=layerClustersLabel,
help="Choose output plots collections among possible choices")
parser.add_argument("--extended", action="store_true", default = False,
help="Include extended set of plots (e.g. bunch of distributions; default off)")
Expand Down

0 comments on commit 02a115f

Please sign in to comment.