CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vertexPlots.py
Go to the documentation of this file.
1 from Validation.RecoTrack.plotting.plotting import Plot, PlotGroup, PlotFolder, Plotter
2 import Validation.RecoTrack.plotting.validation as validation
3 from Validation.RecoTrack.plotting.html import PlotPurpose
4 
5 
6 _minPU = [0, 80, 120]
7 _maxPU = [80, 100, 150, 200, 250]
8 _minVtx = [0, 80, 120]
9 _maxVtx = [60, 100, 150, 200, 250]
10 _maxEff = 1.025
11 _maxFake = [0.05, 0.1, 0.2, 0.5, 0.7, 1.025]
12 
13 _common = {"xtitle": "Simulated interactions", "xmin": _minPU, "xmax": _maxPU, "ymin": _minVtx, "ymax": _maxVtx}
14 _recovsgen = PlotGroup("recovsgen", [
15  Plot("RecoVtx_vs_GenVtx", ytitle="Reco vertices", **_common),
16  Plot("MatchedRecoVtx_vs_GenVtx", ytitle="Matched reco vertices", **_common),
17  Plot("merged_vs_ClosestVertexInZ", xtitle="Closest distance in Z (cm)", ytitle="Merge rate", xlog=True, ymax=_maxFake),
18  Plot("merged_vs_Z", xtitle="Z (cm)", ytitle="Merge rate", xmin=-20, xmax=20, ymax=_maxFake),
19 ],
20  legendDy=-0.025
21 )
22 _pvtagging = PlotGroup("pvtagging", [
23  Plot("TruePVLocationIndexCumulative", xtitle="Signal PV status in reco collection", ytitle="Fraction of events", drawStyle="hist", normalizeToUnitArea=True, xbinlabels=["Not reconstructed", "Reco and identified", "Reco, not identified"], xbinlabelsize=15, xbinlabeloption="h", xgrid=False, ylog=True, ymin=1e-3),
24  Plot("TruePVLocationIndex", xtitle="Index of signal PV in reco collection", ytitle="Fraction of events", drawStyle="hist", normalizeToUnitArea=True, ylog=True, ymin=1e-5),
25  Plot("MisTagRate_vs_PU", xtitle="PU", ytitle="Mistag rate vs. PU", title="", xmax=_maxPU, ymax=_maxFake),
26  Plot("MisTagRate_vs_sum-pt2", xtitle="#Sigmap_{T}^{2}", ytitle="Mistag rate vs. #Sigmap_{T}^{2}", title="", xlog=True, ymax=_maxFake),
27 ],
28  legendDy=-0.025
29 )
30 _effandfake = PlotGroup("effandfake", [
31  Plot("effic_vs_NumVertices", xtitle="Simulated interactions", ytitle="Efficiency vs. N sim vertices", xmin=_minVtx, xmax=_maxVtx, ymax=_maxEff),
32  Plot("fakerate_vs_PU", xtitle="Simulated interactions", ytitle="Fake rate vs. N sim vertices", xmin=_minPU, xmax=_maxPU, ymax=_maxFake),
33  Plot("effic_vs_NumTracks", xtitle="Tracks", ytitle="Efficiency vs. N tracks", title="", ymax=_maxEff),
34  Plot("fakerate_vs_NumTracks", xtitle="Tracks", ytitle="Fake rate vs. N tracks", title="", ymax=_maxFake),
35  Plot("effic_vs_Pt2", xtitle="Sum p_{T}^{2} ", ytitle="Efficiency vs. sum p_{T}^{2}", xlog=True, ymax=_maxEff),
36  Plot("fakerate_vs_Pt2", xtitle="Sum p_{T}^{2} ", ytitle="Fake rate vs. sum p_{T}^{2}", xlog=True, ymax=_maxFake),
37 ])
38 _common = {"title": "", "stat": True, "fit": True, "normalizeToUnitArea": True, "drawStyle": "hist", "drawCommand": "", "ylog": True, "ymin": [5e-7, 5e-6, 5e-5, 5e-4]}
39 _resolution = PlotGroup("resolution", [
40  Plot("RecoAllAssoc2GenMatched_ResolX", xtitle="Resolution in x (#mum)", **_common),
41  Plot("RecoAllAssoc2GenMatchedMerged_ResolX", xtitle="Resolution in x for merged vertices (#mum)", **_common),
42  Plot("RecoAllAssoc2GenMatched_ResolY", xtitle="Resolution in y (#mum)", **_common),
43  Plot("RecoAllAssoc2GenMatchedMerged_ResolY", xtitle="Resolution in y for merged vertices (#mum)", **_common),
44  Plot("RecoAllAssoc2GenMatched_ResolZ", xtitle="Resolution in z (#mum)", **_common),
45  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ", xtitle="Resolution in z for merged vertices (#mum)", **_common),
46 ])
47 _common = {"title": "", "xtitle": "Number of tracks", "scale": 1e4, "ylog": True, "ymin": 5, "ymax": 500}
48 _resolutionNumTracks = PlotGroup("resolutionNumTracks", [
49  Plot("RecoAllAssoc2GenMatched_ResolX_vs_NumTracks_Sigma", ytitle="Resolution in x (#mum)", **_common),
50  Plot("RecoAllAssoc2GenMatchedMerged_ResolX_vs_NumTracks_Sigma", ytitle="Resolution in x for merged vertices (#mum)", **_common),
51  Plot("RecoAllAssoc2GenMatched_ResolY_vs_NumTracks_Sigma", ytitle="Resolution in y (#mum)", **_common),
52  Plot("RecoAllAssoc2GenMatchedMerged_ResolY_vs_NumTracks_Sigma", ytitle="Resolution in y for merged vertices (#mum)", **_common),
53  Plot("RecoAllAssoc2GenMatched_ResolZ_vs_NumTracks_Sigma", ytitle="Resolution in z (#mum)", **_common),
54  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ_vs_NumTracks_Sigma", ytitle="Resolution in z for merged vertices (#mum)", **_common),
55 ])
56 _common = {"stat": True, "fit": True, "normalizeToUnitArea": True, "drawStyle": "hist", "drawCommand": "", "xmin": -6, "xmax": 6, "ylog": True, "ymin": 5e-5, "ymax": [0.01, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025]}
57 _pull = PlotGroup("pull", [
58  Plot("RecoAllAssoc2GenMatched_PullX", xtitle="x", ytitle="Pull vs. x", **_common),
59  Plot("RecoAllAssoc2GenMatched_PullY", xtitle="y", ytitle="Pull vs. y", **_common),
60  Plot("RecoAllAssoc2GenMatched_PullZ", xtitle="z", ytitle="Pull vs. z", **_common),
61 ],
62  legendDy=-0.025
63 )
64 _common={"drawStyle": "HIST", "normalizeToUnitArea": True}
65 _puritymissing = PlotGroup("puritymissing", [
66  Plot("RecoPVAssoc2GenPVMatched_Purity", xtitle="Purity", ytitle="Number of reco PVs matched to gen PVs", ylog=True, ymin=1e-4, **_common),
67  Plot("RecoPVAssoc2GenPVNotMatched_Purity", xtitle="Purity", ytitle="Number of reco PVs not matcched to gen PVs", ylog=True, ymin=1e-3, **_common),
68  Plot("RecoPVAssoc2GenPVMatched_Missing", xtitle="Fraction of reco p_{T} associated to gen PV \"missing\" from reco PV", ytitle="Number of reco PVs matched to gen PVs", ylog=True, ymin=1e-4, **_common),
69  Plot("RecoPVAssoc2GenPVNotMatched_Missing", xtitle="Fraction of reco p_{T} associated to gen PV \"missing\" from reco PV", ytitle="Number of reco PVs not matcched to gen PVs", ylog=True, ymin=1e-3, **_common),
70 # Plot("fakerate_vs_Purity", xtitle="Purity", ytitle="Fake rate", ymax=_maxFake),
71 ])
72 # "xgrid": False, "ygrid": False,
73 _common={"drawStyle": "HIST", "xlog": True, "ylog": True, "ymin": 0.5}
74 _sumpt2 = PlotGroup("sumpt2", [
75  Plot("RecoAssoc2GenPVMatched_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco vertices matched to gen PV", **_common),
76  Plot("RecoAssoc2GenPVMatchedNotHighest_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco non-PV-vertices matched to gen PV", **_common),
77  Plot("RecoAssoc2GenPVNotMatched_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco vertices not matched to gen PV", **_common),
78  Plot("RecoAssoc2GenPVNotMatched_GenPVTracksRemoved_Pt2", xtitle="#sum^{}p_{T}^{2}, gen PV tracks removed", ytitle="Reco vertices not matched to gen PV", **_common),
79 ],
80  legendDy=-0.025
81 )
82 
83 _common = {"drawStyle": "HIST"}
84 _genpos = PlotGroup("genpos", [
85  Plot("GenAllV_X", xtitle="Gen AllV pos x", ytitle="N", **_common),
86  Plot("GenPV_X", xtitle="Gen PV pos x", ytitle="N", **_common),
87  Plot("GenAllV_Y", xtitle="Gen AllV pos y", ytitle="N", **_common),
88  Plot("GenPV_Y", xtitle="Gen PV pos y", ytitle="N", **_common),
89  Plot("GenAllV_Z", xtitle="Gen AllV pos z", ytitle="N", **_common),
90  Plot("GenPV_Z", xtitle="Gen PV pos z", ytitle="N", **_common),
91 ])
92 
93 _k0_effandfake = PlotGroup("effandfake", [
94  Plot("K0sEffVsPt", xtitle="p_{T} (GeV)", ytitle="Efficiency vs. p_{T}"),
95  Plot("K0sFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
96  Plot("K0sEffVsEta", xtitle="#eta", ytitle="Efficiency vs. #eta"),
97  Plot("K0sFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
98  Plot("K0sEffVsR", xtitle="R (cm)", ytitle="Efficiency vs. R"),
99  Plot("K0sFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
100 ])
101 _k0_effandfakeTk = PlotGroup("effandfakeTk", [
102 # Plot("K0sTkEffVsPt"),
103  Plot("K0sTkFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
104 # Plot("K0sTkEffVsEta"),
105  Plot("K0sTkFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
106 # Plot("K0sTkEffVsR"),
107  Plot("K0sTkFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
108 ],
109  legendDy=-0.025
110 )
111 _common = {"normalizeToUnitArea": True, "drawStyle": "HIST"}
112 _k0_mass = PlotGroup("mass", [
113  Plot("ksMassAll", xtitle="mass of all (GeV)", **_common),
114  Plot("ksMassGood", xtitle="mass of good (GeV)", **_common),
115  Plot("ksMassFake", xtitle="mass of fake (GeV)", **_common),
116 ],
117  legendDy=-0.025
118 )
119 _lambda_effandfake = PlotGroup("effandfake", [
120  Plot("LamEffVsPt", xtitle="p_{T} (GeV)", ytitle="Efficiency vs. p_{T}"),
121  Plot("LamFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
122  Plot("LamEffVsEta", xtitle="#eta", ytitle="Efficiency vs. #eta"),
123  Plot("LamFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
124  Plot("LamEffVsR", xtitle="R (cm)", ytitle="Efficiency vs. R"),
125  Plot("LamFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
126 ])
127 _lambda_effandfakeTk = PlotGroup("effandfakeTk", [
128 # Plot("LamTkEffVsPt"),
129  Plot("LamTkFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
130 # Plot("LamTkEffVsEta"),
131  Plot("LamTkFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
132 # Plot("LamTkEffVsR"),
133  Plot("LamTkFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
134 ],
135  legendDy=-0.025
136 )
137 _lambda_mass = PlotGroup("mass", [
138  Plot("lamMassAll", xtitle="mass of all (GeV)", **_common),
139  Plot("lamMassGood", xtitle="mass of good (GeV)", **_common),
140  Plot("lamMassFake", xtitle="mass of fake (GeV)", **_common),
141 ],
142  legendDy=-0.025
143 )
144 
145 
147  def __init__(self, page="vertex"):
148  self._purpose = PlotPurpose.Vertexing
149  self._page = page
150 
151  def getPurpose(self):
152  return self._purpose
153 
154  def getPage(self):
155  return self._page
156 
157  def getSection(self, dqmSubFolder):
158  return dqmSubFolder
159 
160  def create(self, tdirectory):
161  def _formatOrNone(num, func):
162  if num is None:
163  return None
164  return func(num)
165 
166  ret = []
167  h = tdirectory.Get("TruePVLocationIndexCumulative")
168  if h:
169  n_events = h.GetEntries()
170  n_pvtagged = h.GetBinContent(2)
171  ret.extend([int(n_events), "%.4f"%(float(n_pvtagged)/float(n_events))])
172  else:
173  ret.extend([None, None])
174 
175  h = tdirectory.Get("globalEfficiencies")
176  if h:
177  d = {}
178  for i in xrange(1, h.GetNbinsX()+1):
179  d[h.GetXaxis().GetBinLabel(i)] = h.GetBinContent(i)
180  ret.extend([
181  _formatOrNone(d.get("effic_vs_Z", None), lambda n: "%.4f"%n),
182  _formatOrNone(d.get("fakerate_vs_Z", None), lambda n: "%.4f"%n),
183  _formatOrNone(d.get("merged_vs_Z", None), lambda n: "%.4f"%n),
184  _formatOrNone(d.get("duplicate_vs_Z", None), lambda n: "%.4f"%n),
185  ])
186  else:
187  ret.extend([None]*4)
188 
189  if ret.count(None) == len(ret):
190  return None
191 
192  return ret
193 
194  def headers(self):
195  return [
196  "Events",
197  "PV reco+tag efficiency",
198  "Efficiency",
199  "Fake rate",
200  "Merge rate",
201  "Duplicate rate",
202  ]
203 
204 _vertexFolders = [
205  "DQMData/Run 1/Vertexing/Run summary/PrimaryVertex",
206  "DQMData/Vertexing/PrimaryVertex",
207  "DQMData/Run 1/Vertexing/Run summary/PrimaryVertexV",
208  "DQMData/Vertexing/PrimaryVertexV",
209 ]
210 _v0Folders = [
211  "DQMData/Run 1/Vertexing/Run summary/V0",
212  "DQMData/Vertexing/V0",
213  "DQMData/Run 1/Vertexing/Run summary/V0V",
214  "DQMData/Vertexing/V0V",
215 ]
216 plotter = Plotter()
217 plotter.append("", _vertexFolders, PlotFolder(
218  _recovsgen,
219  _pvtagging,
220  _effandfake,
221  _resolution,
222  _resolutionNumTracks,
223  _pull,
224  _puritymissing,
225  _sumpt2,
226  purpose=PlotPurpose.Vertexing,
227  page="vertex",
228  onlyForPileup=True
229 ))
230 plotter.appendTable("", _vertexFolders, VertexSummaryTable())
231 plotter.append("K0", [x+"/K0" for x in _v0Folders], PlotFolder(
232  _k0_effandfake,
233  _k0_effandfakeTk,
234  _k0_mass,
235  loopSubFolders=False,
236  purpose=PlotPurpose.Vertexing,
237  page="v0", section="k0"
238 ))
239 plotter.append("Lambda", [x+"/Lambda" for x in _v0Folders], PlotFolder(
240  _lambda_effandfake,
241  _lambda_effandfakeTk,
242  _lambda_mass,
243  loopSubFolders=False,
244  purpose=PlotPurpose.Vertexing,
245  page="v0", section="lambda"
246 ))
247 #plotter.append("gen", _vertexFolders, PlotFolder(_genpos, loopSubFolders=False, purpose=PlotPurpose.Vertexing, page="vertex", section="Gen vertex"))
248 
250  def _init__(self, *args, **kwargs):
251  super(TrackingValidation, self).__init__(*args, **kwargs)
252 
253  def _getDirectoryName(self, quality, algo):
254  return algo
255 
256  def _getSelectionName(self, quality, algo):
257  if algo is None:
258  return ""
259  return "_"+algo