Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:34:06

0001 #!/usr/bin/env python3
0002 
0003 # This is an example of plotting the standard tracking validation
0004 # plots from an explicit set of DQM root files.
0005 
0006 from Validation.RecoTrack.plotting.validation import SimpleValidation, SimpleSample
0007 import Validation.RecoTrack.plotting.trackingPlots as trackingPlots
0008 import Validation.RecoVertex.plotting.vertexPlots as vertexPlots
0009 
0010 # Below is an example on how to make plots for custom
0011 # track+TrackingParticle selections (e.g. selecting a specific eta-phi
0012 # region). Track selection is handled by defining custom track
0013 # "quality" (string in the track collection names), TrackingParticle
0014 # selection by MTV instances having the same string as their postfix.
0015 # See python/customiseMTVForBPix123Holes.py for a customise function
0016 # setting up the MTV instances for CMSSW job.
0017 #
0018 #trackingPlots._additionalTrackQualities.extend(["L1L2", "L2L3"])
0019 #for pfix in ["L1L2", "L2L3"]:
0020 #    trackingPlots._appendTrackingPlots("Track"+pfix, "", trackingPlots._simBasedPlots+trackingPlots._recoBasedPlots)
0021 #    trackingPlots._appendTrackingPlots("TrackSeeding"+pfix, "", trackingPlots._seedingBuildingPlots, seeding=True)
0022 #    trackingPlots._appendTrackingPlots("TrackBuilding"+pfix, "", trackingPlots._seedingBuildingPlots)
0023 
0024 outputDir = "plots" # Plot output directory
0025 description = "Short description of your comparison"
0026 
0027 plotterDrawArgs = dict(
0028     separate=False, # Set to true if you want each plot in it's own canvas
0029 #    ratio=False,   # Uncomment to disable ratio pad
0030 )
0031 
0032 # Pairs of file names and legend labels
0033 filesLabels = [
0034     ("DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_1.root", "Option 1"),
0035     ("DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_2.root", "Option 2"),
0036 ]
0037 # Files are grouped together as a "sample" (the files don't
0038 # necessarily have to come from the same sample, like ttbar, but this
0039 # is the abstraction here)
0040 sample = SimpleSample("sample_prefix", # Prefix for subdirectory names
0041                       "Sample name",   # The name appears in the HTML pages
0042                       filesLabels)     # Files and legend labels
0043 
0044 # You can produce plots for multiple samples on one. Just construct
0045 # multiple SimpleSample objects like above and add them to the list
0046 # below.
0047 samples = [
0048     sample
0049 ]
0050 
0051 # Example of how to limit tracking plots to specific iterations
0052 kwargs_tracking = {}
0053 class LimitTrackAlgo: # helper class to limit to iterations
0054     def __init__(self, algos):
0055         self._algos = algos
0056     def __call__(self, algo, quality):
0057         if self._algos is not None:
0058             if algo not in self._algos:
0059                 return False
0060         if "Pt09" in quality:
0061             return False
0062         if "ByAlgoMask" in quality or "ByOriginalAlgo" in quality:
0063             return False
0064         return True
0065 limit = LimitTrackAlgo(["ootb", "initialStep"]) # limit to generalTracks (ootb) and initialStep
0066 ignore = lambda algo, quality: False # ignore everything
0067 ignore09 = LimitTrackAlgo(None) # ignore Pt09 plots
0068 
0069 # This specifies how different sets of plots are treated. If some
0070 # "plot set" is not in the dictionary, full set of plots will be
0071 # produced for it
0072 limitSubFolders = {
0073     "":                limit,  # The default set (signal TrackingParticles for efficiency, all TrackingParticles for fakes)
0074     "tpPtLess09":      limit,  # Efficiency for TrackingParticles with pT < 0.9 GeV
0075     "tpEtaGreater2p7": limit,  # Efficiency for TrackingParticles with |eta| > 2.7 (phase 2)
0076     "allTPEffic":      ignore, # Efficiency with all TrackingParticles
0077     "bhadron":         limit,  # Efficiency with B-hadron TrackingParticles
0078     "displaced":       limit,  # Efficiency for TrackingParticles with no tip or lip cuts
0079     "fromPV":          limit,  # Tracks from PV, signal TrackingParticles for efficiency and fakes
0080     "fromPVAllTP":     limit,  # Tracks from PV, all TrackingParticles for fakes
0081     "building":        ignore, # Built tracks (as opposed to selected tracks in above)
0082     "seeding":         ignore, # Seeds
0083 }
0084 # arguments to be passed to tracking val.doPlots() below
0085 kwargs_tracking["limitSubFoldersOnlyTo"]=limitSubFolders
0086 
0087 # Example of how to customize the plots, here applied only if each
0088 # plot is drawn separately
0089 if plotterDrawArgs["separate"]:
0090     common = dict(
0091         title=""
0092     )
0093 
0094     for plotFolderName in ["", "building"]: # these refer to the various cases added with _appendTrackingPlots in trackingPlots.py
0095         # Get the PlotFolder object
0096         plotFolder = trackingPlots.plotter.getPlotFolder(plotFolderName)
0097 
0098         # These are the PlotGroup objects defined in trackingPlots.py,
0099         # name is the same as the first parameter to PlotGroup constructor
0100         plotGroup = plotFolder.getPlotGroup("effandfake1")
0101         # From PlotGroup one can ask an individual Plot, again name is
0102         # the same as used for Plot constructor. The setProperties()
0103         # accepts the same parameters as the constructor, see
0104         # plotting.Plot for more information.
0105         plotGroup.getPlot("efficPt").setProperties(legendDx=-0, legendDy=-0, **common)
0106 
0107     # Example of customization of vertex plots
0108     common["lineWidth"] = 4
0109     plotFolder = vertexPlots.plotterExt.getPlotFolder("gen")
0110     plotGroup = plotFolder.getPlotGroup("genpos")
0111     plotGroup.getPlot("GenAllV_Z").setProperties(xtitle="Simulated vertex z (cm)", legendDy=-0.1, legendDx=-0.45, ratioYmax=2.5, **common)
0112 
0113 
0114 val = SimpleValidation(samples, outputDir)
0115 report = val.createHtmlReport(validationName=description)
0116 val.doPlots([
0117     trackingPlots.plotter,     # standard tracking plots
0118     #trackingPlots.plotterExt, # extended tracking plots (e.g. distributions)
0119 ],
0120             plotterDrawArgs=plotterDrawArgs,
0121             **kwargs_tracking
0122 )
0123 val.doPlots([
0124     #trackingPlots.timePlotter, # tracking timing plots
0125     vertexPlots.plotter,        # standard vertex plots
0126     #vertexPlots.plotterExt,    # extended vertex plots (e.g. distributions)
0127 ],
0128             plotterDrawArgs=plotterDrawArgs,
0129 )
0130 report.write() # comment this if you don't want HTML page generation