CMS 3D CMS Logo

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, 10, 20, 40, 80, 120]
7 _maxPU = [60, 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 _minMaxRes = [5, 10, 50, 100, 200, 500, 1000, 2000, 5000]
13 _minMaxPt = [5e-1, 1, 5, 1e1, 5e1, 1e2, 5e2, 1e3, 5e3, 1e4]
14 
15 _vertexNumberOfEventsHistogram = "DQMData/Run 1/Vertexing/Run summary/PrimaryVertexV/GenPV_Z"
16 
17 _common = {"xtitle": "Simulated interactions", "xmin": _minPU, "xmax": _maxPU, "ymin": _minVtx, "ymax": _maxVtx}
18 _recovsgen = PlotGroup("recovsgen", [
19  Plot("RecoVtx_vs_GenVtx", ytitle="Reco vertices", **_common),
20  Plot("MatchedRecoVtx_vs_GenVtx", ytitle="Matched reco vertices", **_common),
21  Plot("merged_vs_ClosestVertexInZ", xtitle="Closest distance in Z (cm)", ytitle="Merge rate", xlog=True, ymax=_maxFake),
22  Plot("merged_vs_Z", xtitle="Z (cm)", ytitle="Merge rate", xmin=-20, xmax=20, ymax=_maxFake),
23 ],
24  legendDy=-0.025
25 )
26 _pvtagging = PlotGroup("pvtagging", [
27  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, ratioCoverageXrange=[-0.5, 0.5]),
28  Plot("TruePVLocationIndex", xtitle="Index of signal PV in reco collection", ytitle="Fraction of events", drawStyle="hist", normalizeToUnitArea=True, ylog=True, ymin=1e-5),
29  Plot("MisTagRate_vs_PU", xtitle="PU", ytitle="Mistag rate vs. PU", title="", xmax=_maxPU, ymax=_maxFake),
30  Plot("MisTagRate_vs_sum-pt2", xtitle="#Sigmap_{T}^{2}", ytitle="Mistag rate vs. #Sigmap_{T}^{2}", title="", xlog=True, ymax=_maxFake),
31 ],
32  legendDy=-0.025
33 )
34 _effandfake = PlotGroup("effandfake", [
35  Plot("effic_vs_NumVertices", xtitle="Simulated interactions", ytitle="Efficiency vs. N sim vertices", xmin=_minPU, xmax=_maxPU, ymax=_maxEff),
36  Plot("fakerate_vs_PU", xtitle="Simulated interactions", ytitle="Fake rate vs. N sim vertices", xmin=_minPU, xmax=_maxPU, ymax=_maxFake),
37  Plot("effic_vs_NumTracks", xtitle="Tracks", ytitle="Efficiency vs. N tracks", title="", ymax=_maxEff),
38  Plot("fakerate_vs_NumTracks", xtitle="Tracks", ytitle="Fake rate vs. N tracks", title="", ymax=_maxFake),
39  Plot("effic_vs_Pt2", xtitle="Sum p_{T}^{2} ", ytitle="Efficiency vs. sum p_{T}^{2}", xlog=True, ymax=_maxEff),
40  Plot("fakerate_vs_Pt2", xtitle="Sum p_{T}^{2} ", ytitle="Fake rate vs. sum p_{T}^{2}", xlog=True, ymax=_maxFake),
41 ])
42 _common = {"title": "", "stat": True, "fit": True, "normalizeToUnitArea": True, "drawStyle": "hist", "drawCommand": "", "ylog": True, "ymin": [5e-7, 5e-6, 5e-5, 5e-4]}
43 _resolution = PlotGroup("resolution", [
44  Plot("RecoAllAssoc2GenMatched_ResolX", xtitle="Resolution in x (#mum)", **_common),
45  Plot("RecoAllAssoc2GenMatchedMerged_ResolX", xtitle="Resolution in x for merged vertices (#mum)", **_common),
46  Plot("RecoAllAssoc2GenMatched_ResolY", xtitle="Resolution in y (#mum)", **_common),
47  Plot("RecoAllAssoc2GenMatchedMerged_ResolY", xtitle="Resolution in y for merged vertices (#mum)", **_common),
48  Plot("RecoAllAssoc2GenMatched_ResolZ", xtitle="Resolution in z (#mum)", **_common),
49  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ", xtitle="Resolution in z for merged vertices (#mum)", **_common),
50 ])
51 _common = dict(title="", xtitle="Number of tracks", scale=1e4, ylog=True, ymin=_minMaxRes , ymax=_minMaxRes)
52 _resolutionNumTracks = PlotGroup("resolutionNumTracks", [
53  Plot("RecoAllAssoc2GenMatched_ResolX_vs_NumTracks_Sigma", ytitle="Resolution in x (#mum)", **_common),
54  Plot("RecoAllAssoc2GenMatchedMerged_ResolX_vs_NumTracks_Sigma", ytitle="Resolution in x for merged vertices (#mum)", **_common),
55  Plot("RecoAllAssoc2GenMatched_ResolY_vs_NumTracks_Sigma", ytitle="Resolution in y (#mum)", **_common),
56  Plot("RecoAllAssoc2GenMatchedMerged_ResolY_vs_NumTracks_Sigma", ytitle="Resolution in y for merged vertices (#mum)", **_common),
57  Plot("RecoAllAssoc2GenMatched_ResolZ_vs_NumTracks_Sigma", ytitle="Resolution in z (#mum)", **_common),
58  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ_vs_NumTracks_Sigma", ytitle="Resolution in z for merged vertices (#mum)", **_common),
59 ])
60 _common.update(dict(xtitle= "Sum of track p_{T} (GeV)", xlog=True, xmin=_minMaxPt, xmax=_minMaxPt))
61 _resolutionPt = PlotGroup("resolutionPt", [
62  Plot("RecoAllAssoc2GenMatched_ResolX_vs_Pt_Sigma", ytitle="Resolution in x (#mum)", **_common),
63  Plot("RecoAllAssoc2GenMatchedMerged_ResolX_vs_Pt_Sigma", ytitle="Resolution in x for merged vertices (#mum)", **_common),
64  Plot("RecoAllAssoc2GenMatched_ResolY_vs_Pt_Sigma", ytitle="Resolution in y (#mum)", **_common),
65  Plot("RecoAllAssoc2GenMatchedMerged_ResolY_vs_Pt_Sigma", ytitle="Resolution in y for merged vertices (#mum)", **_common),
66  Plot("RecoAllAssoc2GenMatched_ResolZ_vs_Pt_Sigma", ytitle="Resolution in z (#mum)", **_common),
67  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ_vs_Pt_Sigma", ytitle="Resolution in z for merged vertices (#mum)", **_common),
68 ])
69 _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]}
70 _pull = PlotGroup("pull", [
71  Plot("RecoAllAssoc2GenMatched_PullX", xtitle="x", ytitle="Pull vs. x", **_common),
72  Plot("RecoAllAssoc2GenMatched_PullY", xtitle="y", ytitle="Pull vs. y", **_common),
73  Plot("RecoAllAssoc2GenMatched_PullZ", xtitle="z", ytitle="Pull vs. z", **_common),
74 ],
75  legendDy=-0.025
76 )
77 _common={"drawStyle": "HIST", "normalizeToUnitArea": True}
78 _puritymissing = PlotGroup("puritymissing", [
79  Plot("RecoPVAssoc2GenPVMatched_Purity", xtitle="Purity", ytitle="Number of reco PVs matched to gen PVs", ylog=True, ymin=1e-4, **_common),
80  Plot("RecoPVAssoc2GenPVNotMatched_Purity", xtitle="Purity", ytitle="Number of reco PVs not matcched to gen PVs", ylog=True, ymin=1e-3, **_common),
81  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),
82  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),
83 # Plot("fakerate_vs_Purity", xtitle="Purity", ytitle="Fake rate", ymax=_maxFake),
84 ])
85 # "xgrid": False, "ygrid": False,
86 _common={"drawStyle": "HIST", "xlog": True, "ylog": True, "ymin": 0.5}
87 _sumpt2 = PlotGroup("sumpt2", [
88  Plot("RecoAssoc2GenPVMatched_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco vertices matched to gen PV", **_common),
89  Plot("RecoAssoc2GenPVMatchedNotHighest_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco non-PV-vertices matched to gen PV", **_common),
90  Plot("RecoAssoc2GenPVNotMatched_Pt2", xtitle="#sum^{}p_{T}^{2}", ytitle="Reco vertices not matched to gen PV", **_common),
91  Plot("RecoAssoc2GenPVNotMatched_GenPVTracksRemoved_Pt2", xtitle="#sum^{}p_{T}^{2}, gen PV tracks removed", ytitle="Reco vertices not matched to gen PV", **_common),
92 ],
93  legendDy=-0.025
94 )
95 
96 _k0_effandfake = PlotGroup("effandfake", [
97  Plot("K0sEffVsPt", xtitle="p_{T} (GeV)", ytitle="Efficiency vs. p_{T}"),
98  Plot("K0sFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
99  Plot("K0sEffVsEta", xtitle="#eta", ytitle="Efficiency vs. #eta"),
100  Plot("K0sFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
101  Plot("K0sEffVsR", xtitle="R (cm)", ytitle="Efficiency vs. R"),
102  Plot("K0sFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
103 ])
104 _k0_effandfakeTk = PlotGroup("effandfakeTk", [
105 # Plot("K0sTkEffVsPt"),
106  Plot("K0sTkFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
107 # Plot("K0sTkEffVsEta"),
108  Plot("K0sTkFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
109 # Plot("K0sTkEffVsR"),
110  Plot("K0sTkFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
111 ],
112  legendDy=-0.025
113 )
114 _common = dict(normalizeToUnitArea=True, drawStyle="HIST", stat=True)
115 _k0_mass = PlotGroup("mass", [
116  Plot("ksMassAll", xtitle="mass of all (GeV)", **_common),
117  Plot("ksMassGood", xtitle="mass of good (GeV)", **_common),
118  Plot("ksMassFake", xtitle="mass of fake (GeV)", **_common),
119 ],
120  legendDy=-0.025
121 )
122 _lambda_effandfake = PlotGroup("effandfake", [
123  Plot("LamEffVsPt", xtitle="p_{T} (GeV)", ytitle="Efficiency vs. p_{T}"),
124  Plot("LamFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
125  Plot("LamEffVsEta", xtitle="#eta", ytitle="Efficiency vs. #eta"),
126  Plot("LamFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
127  Plot("LamEffVsR", xtitle="R (cm)", ytitle="Efficiency vs. R"),
128  Plot("LamFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
129 ])
130 _lambda_effandfakeTk = PlotGroup("effandfakeTk", [
131 # Plot("LamTkEffVsPt"),
132  Plot("LamTkFakeVsPt", xtitle="p_{T} (GeV)", ytitle="Fake rate vs. p_{T}"),
133 # Plot("LamTkEffVsEta"),
134  Plot("LamTkFakeVsEta", xtitle="#eta", ytitle="Fake rate vs. #eta"),
135 # Plot("LamTkEffVsR"),
136  Plot("LamTkFakeVsR", xtitle="R (cm)", ytitle="Fake rate vs. R"),
137 ],
138  legendDy=-0.025
139 )
140 _lambda_mass = PlotGroup("mass", [
141  Plot("lamMassAll", xtitle="mass of all (GeV)", **_common),
142  Plot("lamMassGood", xtitle="mass of good (GeV)", **_common),
143  Plot("lamMassFake", xtitle="mass of fake (GeV)", **_common),
144 ],
145  legendDy=-0.025
146 )
147 
148 ## Extended set of plots
149 _common = dict(drawStyle = "HIST", stat=True)
150 _commonXY = dict(xmin=[x*0.1 for x in xrange(-6, 6, 1)], xmax=[x*0.1 for x in xrange(-5, 7, 1)])
151 _commonZ = dict(xmin=[-60,-30], xmax=[30,60])
152 _commonXY.update(_common)
153 _commonZ.update(_common)
154 _extGenpos = PlotGroup("genpos", [
155  Plot("GenAllV_X", xtitle="Gen AllV pos x (cm)", ytitle="N", **_commonXY),
156  Plot("GenPV_X", xtitle="Gen PV pos x (cm)", ytitle="N", **_commonXY),
157  Plot("GenAllV_Y", xtitle="Gen AllV pos y (cm)", ytitle="N", **_commonXY),
158  Plot("GenPV_Y", xtitle="Gen PV pos y (cm)", ytitle="N", **_commonXY),
159  Plot("GenAllV_Z", xtitle="Gen AllV pos z (cm)", ytitle="N", **_commonZ),
160  Plot("GenPV_Z", xtitle="Gen PV pos z (cm)", ytitle="N", **_commonZ),
161 ])
162 _extDist = PlotGroup("dist", [
163  Plot("RecoAllAssoc2Gen_X", xtitle="Reco vertex pos x (cm)", ytitle="N", **_commonXY),
164  Plot("RecoAllAssoc2Gen_Y", xtitle="Reco vertex pos y (cm)", ytitle="N", **_commonXY),
165  Plot("RecoAllAssoc2Gen_R", xtitle="Reco vertex pos r (cm)", ytitle="N", **_commonXY),
166  Plot("RecoAllAssoc2Gen_Z", xtitle="Reco vertex pos z (cm)", ytitle="N", **_commonZ),
167  Plot("RecoAllAssoc2Gen_NumVertices", xtitle="Number of reco vertices", ytitle="A.u.", normalizeToUnitArea=True, stat=True, drawStyle="hist", min=_minVtx, xmax=_maxVtx),
168  Plot("RecoAllAssoc2Gen_NumTracks", xtitle="Number of tracks in vertex fit", ytitle="N", stat=True, drawStyle="hist"),
169 ])
170 _common = dict(title="", xtitle="Vertex z (cm)", scale=1e4, ylog=True, ymin=_minMaxRes , ymax=_minMaxRes, xmin=range(-60,-10,10), xmax=range(20,70,10))
171 _extResolutionZ = PlotGroup("resolutionZ", [
172  Plot("RecoAllAssoc2GenMatched_ResolX_vs_Z_Sigma", ytitle="Resolution in x (#mum)", **_common),
173  Plot("RecoAllAssoc2GenMatchedMerged_ResolX_vs_Z_Sigma", ytitle="Resolution in x for merged vertices (#mum)", **_common),
174  Plot("RecoAllAssoc2GenMatched_ResolY_vs_Z_Sigma", ytitle="Resolution in y (#mum)", **_common),
175  Plot("RecoAllAssoc2GenMatchedMerged_ResolY_vs_Z_Sigma", ytitle="Resolution in y for merged vertices (#mum)", **_common),
176  Plot("RecoAllAssoc2GenMatched_ResolZ_vs_Z_Sigma", ytitle="Resolution in z (#mum)", **_common),
177  Plot("RecoAllAssoc2GenMatchedMerged_ResolZ_vs_Z_Sigma", ytitle="Resolution in z for merged vertices (#mum)", **_common),
178 ])
179 _extDqm = PlotGroup("dqm", [
180  Plot("tagVtxTrksVsZ", xtitle="z_{vertex} - z_{beamspot} (cm)", ytitle="Tracks / selected PV"),
181  Plot("otherVtxTrksVsZ", xtitle="z_{vertex} - z_{beamspot} (cm)", ytitle="Tracks / pileup vertex"),
182  Plot("vtxNbr", xtitle="Reconstructed vertices", ytitle="Events", stat=True, drawStyle="hist", xmin=_minVtx, xmax=_maxVtx),
183 ])
184 
186  def __init__(self, page="vertex"):
187  self._purpose = PlotPurpose.Vertexing
188  self._page = page
189 
190  def getPurpose(self):
191  return self._purpose
192 
193  def getPage(self):
194  return self._page
195 
196  def getSection(self, dqmSubFolder):
197  return dqmSubFolder
198 
199  def create(self, tdirectory):
200  def _formatOrNone(num, func):
201  if num is None:
202  return None
203  return func(num)
204 
205  ret = []
206  h = tdirectory.Get("TruePVLocationIndexCumulative")
207  if h:
208  n_events = h.GetEntries()
209  n_pvtagged = h.GetBinContent(2)
210  ret.extend([int(n_events), "%.4f"%(float(n_pvtagged)/float(n_events))])
211  else:
212  ret.extend([None, None])
213 
214  h = tdirectory.Get("globalEfficiencies")
215  if h:
216  d = {}
217  for i in xrange(1, h.GetNbinsX()+1):
218  d[h.GetXaxis().GetBinLabel(i)] = h.GetBinContent(i)
219  ret.extend([
220  _formatOrNone(d.get("effic_vs_Z", None), lambda n: "%.4f"%n),
221  _formatOrNone(d.get("fakerate_vs_Z", None), lambda n: "%.4f"%n),
222  _formatOrNone(d.get("merged_vs_Z", None), lambda n: "%.4f"%n),
223  _formatOrNone(d.get("duplicate_vs_Z", None), lambda n: "%.4f"%n),
224  ])
225  else:
226  ret.extend([None]*4)
227 
228  if ret.count(None) == len(ret):
229  return None
230 
231  return ret
232 
233  def headers(self):
234  return [
235  "Events",
236  "PV reco+tag efficiency",
237  "Efficiency",
238  "Fake rate",
239  "Merge rate",
240  "Duplicate rate",
241  ]
242 
243 _vertexFolders = [
244  "DQMData/Run 1/Vertexing/Run summary/PrimaryVertex",
245  "DQMData/Vertexing/PrimaryVertex",
246  "DQMData/Run 1/Vertexing/Run summary/PrimaryVertexV",
247  "DQMData/Vertexing/PrimaryVertexV",
248 ]
249 _vertexDqmFolders = [
250  "DQMData/Run 1/OfflinePV/Run summary/offlinePrimaryVertices",
251  "DQMData/OffinePV/offlinePrimaryVertices",
252 ]
253 _v0Folders = [
254  "DQMData/Run 1/Vertexing/Run summary/V0",
255  "DQMData/Vertexing/V0",
256  "DQMData/Run 1/Vertexing/Run summary/V0V",
257  "DQMData/Vertexing/V0V",
258 ]
259 plotter = Plotter()
260 plotterExt = Plotter()
261 plotter.append("", _vertexFolders, PlotFolder(
262  _recovsgen,
263  _pvtagging,
264  _effandfake,
265  _resolution,
266  _resolutionNumTracks,
267  _resolutionPt,
268  _pull,
269  _puritymissing,
270  _sumpt2,
271  purpose=PlotPurpose.Vertexing,
272  page="vertex",
273  onlyForPileup=True
274 ))
275 plotter.appendTable("", _vertexFolders, VertexSummaryTable())
276 plotter.append("K0", [x+"/K0" for x in _v0Folders], PlotFolder(
277  _k0_effandfake,
278  _k0_effandfakeTk,
279  _k0_mass,
280  loopSubFolders=False,
281  purpose=PlotPurpose.Vertexing,
282  page="v0", section="k0"
283 ))
284 plotter.append("Lambda", [x+"/Lambda" for x in _v0Folders], PlotFolder(
285  _lambda_effandfake,
286  _lambda_effandfakeTk,
287  _lambda_mass,
288  loopSubFolders=False,
289  purpose=PlotPurpose.Vertexing,
290  page="v0", section="lambda"
291 ))
292 plotterExt.append("", _vertexFolders, PlotFolder(
293  _extDist,
294  _extResolutionZ,
295  purpose=PlotPurpose.Vertexing,
296  page="vertex",
297  onlyForPileup=True,
298  numberOfEventsHistogram=_vertexNumberOfEventsHistogram
299 ))
300 plotterExt.append("dqm", _vertexDqmFolders, PlotFolder(
301  _extDqm,
302  loopSubFolders=False,
303  purpose=PlotPurpose.Vertexing,
304  page="vertex",
305  section="offlinePrimaryVertices",
306  onlyForPileup=True
307 ))
308 plotterExt.append("gen", _vertexFolders, PlotFolder(
309  _extGenpos,
310  loopSubFolders=False,
311  purpose=PlotPurpose.Vertexing,
312  page="vertex",
313  section="genvertex",
314  onlyForPileup=True
315 ))
316 
318  def _init__(self, *args, **kwargs):
319  super(TrackingValidation, self).__init__(*args, **kwargs)
320 
321  def _getDirectoryName(self, quality, algo):
322  return algo
323 
324  def _getSelectionName(self, quality, algo):
325  if algo is None:
326  return ""
327  return "_"+algo
def getSection(self, dqmSubFolder)
Definition: vertexPlots.py:196
def __init__(self, fullsimSamples, fastsimSamples, refRelease, refRepository, newRelease, newRepository, newFileModifier=None, selectionName="")
Definition: validation.py:477
def _getSelectionName(self, quality, algo)
Definition: vertexPlots.py:324
def _getDirectoryName(self, quality, algo)
Definition: vertexPlots.py:321
def __init__(self, page="vertex")
Definition: vertexPlots.py:186
def _init__(self, args, kwargs)
Definition: vertexPlots.py:318
def create(self, tdirectory)
Definition: vertexPlots.py:199