CMS 3D CMS Logo

trackingPlots.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 from builtins import range
3 import os
4 import copy
5 import collections
6 
7 import six
8 import ROOT
9 ROOT.gROOT.SetBatch(True)
10 ROOT.PyConfig.IgnoreCommandLineOptions = True
11 
12 from .plotting import Subtract, FakeDuplicate, CutEfficiency, Transform, AggregateBins, ROC, Plot, PlotEmpty, PlotGroup, PlotOnSideGroup, PlotFolder, Plotter
13 from .html import PlotPurpose
14 from . import plotting
15 from . import validation
16 from . import html
17 
18 ########################################
19 #
20 # Per track collection plots
21 #
22 ########################################
23 
24 _maxEff = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025, 1.2, 1.5, 2]
25 _maxFake = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025]
26 
27 #_minMaxResol = [1e-5, 2e-5, 5e-5, 1e-4, 2e-4, 5e-4, 1e-3, 2e-3, 5e-3, 1e-2, 2e-2, 5e-2, 0.1, 0.2, 0.5, 1]
28 _minMaxResol = [1e-5, 4e-5, 1e-4, 4e-4, 1e-3, 4e-3, 1e-2, 4e-2, 0.1, 0.4, 1]
29 _minMaxN = [5e-1, 5, 5e1, 5e2, 5e3, 5e4, 5e5, 5e6, 5e7, 5e8, 5e9]
30 
31 _minHits = [0, 5, 10]
32 _maxHits = [5, 10, 20, 40, 60, 80]
33 _minLayers = [0, 5, 10]
34 _maxLayers = [5, 10, 25]
35 _maxPixelLayers = 8
36 _min3DLayers = [0, 5, 10]
37 _max3DLayers = [5, 10, 20]
38 _minZ = [-60, -40, -20, -10, -5]
39 _maxZ = [5, 10, 20, 40, 60]
40 _minPU = [0, 10, 20, 50, 100, 150]
41 _maxPU = [20, 50, 65, 80, 100, 150, 200, 250]
42 _minMaxTracks = [0, 200, 500, 1000, 1500, 2000]
43 _minMaxMVA = [-1.025, -0.5, 0, 0.5, 1.025]
44 
46  return ([-x for x in ma], ma)
47 
48 (_minResidualPhi, _maxResidualPhi) = _minMaxResidual([1e-4, 2e-4]) # rad
49 (_minResidualCotTheta, _maxResidualCotTheta) = _minMaxResidual([1e-4, 2e-4])
50 (_minResidualDxy, _maxResidualDxy) = _minMaxResidual([10, 20, 50, 100]) # um
51 (_minResidualDz, _maxResidualDz) = (_minResidualDxy, _maxResidualDxy)
52 (_minResidualPt, _maxResidualPt) = _minMaxResidual([1, 1.5, 2, 5]) # %
53 
54 
55 _legendDy_1row = 0.46
56 _legendDy_2rows = -0.025
57 _legendDy_2rows_3cols = -0.17
58 _legendDy_4rows = 0.09
59 
60 # Ok, because of the way the "reference release" histograms are
61 # stored, this histogram is not accessible for the summary plots. To
62 # be fixed later with (large) reorganization of how things work.
63 #_trackingNumberOfEventsHistogram = "DQMData/Run 1/Tracking/Run summary/Track/general_trackingParticleRecoAsssociation/tracks"
64 
65 _trackingIterationOrderHistogram = "DQMData/Run 1/Tracking/Run summary/TrackBuilding/num_reco_coll"
66 
67 def _makeEffFakeDupPlots(postfix, quantity, unit="", common={}, effopts={}, fakeopts={}):
68  p = postfix
69  q = quantity
70  xq = q
71  if unit != "":
72  xq += " (" + unit + ")"
73 
74  effargs = dict(xtitle="TP "+xq , ytitle="efficiency vs "+q , ymax=_maxEff)
75  fakeargs = dict(xtitle="track "+xq, ytitle="fake+duplicates rate vs "+q, ymax=_maxFake)
76  effargs.update(common)
77  fakeargs.update(common)
78  effargs.update(effopts)
79  fakeargs.update(fakeopts)
80 
81  return [
82  Plot("effic_vs_"+p, **effargs),
83  Plot(FakeDuplicate("fakeduprate_vs_"+p, assoc="num_assoc(recoToSim)_"+p, dup="num_duplicate_"+p, reco="num_reco_"+p, title="fake+duplicates vs "+q), **fakeargs)
84  ]
85 
86 def _makeFakeDupPileupPlots(postfix, quantity, unit="", xquantity="", xtitle=None, common={}):
87  p = postfix
88  q = quantity
89  if xtitle is None:
90  if xquantity != "":
91  xq = xquantity
92  else:
93  xq = q
94  if unit != "":
95  xq += " (" + unit + ")"
96  xtitle="track "+xq
97 
98  return [
99  Plot("fakerate_vs_"+p , xtitle=xtitle, ytitle="fakerate vs "+q , ymax=_maxFake, **common),
100  Plot("duplicatesRate_"+p, xtitle=xtitle, ytitle="duplicates rate vs "+q, ymax=_maxFake, **common),
101  Plot("pileuprate_"+p , xtitle=xtitle, ytitle="pileup rate vs "+q , ymax=_maxFake, **common),
102  ]
103 
104 def _makeFakeDist(postfix):
105  return Subtract("num_fake_"+postfix, "num_reco_"+postfix, "num_assoc(recoToSim)_"+postfix)
106 
107 def _makeDistPlots(postfix, quantity, common={}):
108  p = postfix
109  q = quantity
110 
111  args = dict(xtitle="track "+q, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
112  args.update(common)
113 
114  return [
115  Plot("num_reco_"+p , ytitle="tracks", **args),
116  Plot("num_assoc(recoToSim)_"+p, ytitle="true tracks", **args),
117  Plot(_makeFakeDist(p), ytitle="fake tracks", **args),
118  Plot("num_duplicate_"+p , ytitle="duplicate tracks", **args),
119  ]
120 
121 def _makeDistSimPlots(postfix, quantity, common={}):
122  p = postfix
123  q = quantity
124 
125  args = dict(xtitle="TP "+q, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
126  args.update(common)
127 
128  return [
129  Plot("num_simul_"+p , ytitle="TrackingParticles", **args),
130  Plot("num_assoc(simToReco)_"+p, ytitle="Reconstructed TPs", **args),
131  ]
132 
133 def _makeMVAPlots(num, hp=False):
134  pfix = "_hp" if hp else ""
135  pfix2 = "Hp" if hp else ""
136 
137  xtitle = "MVA%d output"%num
138  xtitlecut = "Cut on MVA%d output"%num
139  args = dict(xtitle=xtitle, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
140 
141  argsroc = dict(
142  xtitle="Efficiency (excl. trk eff)", ytitle="Fake rate",
143  xmax=_maxEff, ymax=_maxFake,
144  drawStyle="EP",
145  )
146  argsroc2 = dict(
147  ztitle="Cut on MVA%d"%num,
148  xtitleoffset=5, ytitleoffset=6.5, ztitleoffset=4,
149  adjustMarginRight=0.12
150  )
151  argsroc2.update(argsroc)
152  argsroc2["drawStyle"] = "pcolz"
153 
154  argsprofile = dict(ymin=_minMaxMVA, ymax=_minMaxMVA)
155 
156  true_cuteff = CutEfficiency("trueeff_vs_mva%dcut%s"%(num,pfix), "num_assoc(recoToSim)_mva%dcut%s"%(num,pfix))
157  fake_cuteff = CutEfficiency("fakeeff_vs_mva%dcut%s"%(num,pfix), Subtract("num_fake_mva%dcut%s"%(num,pfix), "num_reco_mva%dcut%s"%(num,pfix), "num_assoc(recoToSim)_mva%dcut%s"%(num,pfix)))
158 
159  return [
160  PlotGroup("mva%d%s"%(num,pfix2), [
161  Plot("num_assoc(recoToSim)_mva%d%s"%(num,pfix), ytitle="true tracks", **args),
162  Plot(Subtract("num_fake_mva%d%s"%(num,pfix), "num_reco_mva%d%s"%(num,pfix), "num_assoc(recoToSim)_mva%d%s"%(num,pfix)), ytitle="fake tracks", **args),
163  Plot("effic_vs_mva%dcut%s"%(num,pfix), xtitle=xtitlecut, ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
164  #
165  Plot("fakerate_vs_mva%dcut%s"%(num,pfix), xtitle=xtitlecut, ytitle="Fake rate", ymax=_maxFake),
166  Plot(ROC("effic_vs_fake_mva%d%s"%(num,pfix), "effic_vs_mva%dcut%s"%(num,pfix), "fakerate_vs_mva%dcut%s"%(num,pfix)), **argsroc),
167  Plot(ROC("effic_vs_fake_mva%d%s"%(num,pfix), "effic_vs_mva%dcut%s"%(num,pfix), "fakerate_vs_mva%dcut%s"%(num,pfix), zaxis=True), **argsroc2),
168  # Same signal efficiency, background efficiency, and ROC definitions as in TMVA
169  Plot(true_cuteff, xtitle=xtitlecut, ytitle="True track selection efficiency", ymax=_maxEff),
170  Plot(fake_cuteff, xtitle=xtitlecut, ytitle="Fake track selection efficiency", ymax=_maxEff),
171  Plot(ROC("true_eff_vs_fake_rej_mva%d%s"%(num,pfix), true_cuteff, Transform("fake_rej_mva%d%s"%(num,pfix), fake_cuteff, lambda x: 1-x)), xtitle="True track selection efficiency", ytitle="Fake track rejection", xmax=_maxEff, ymax=_maxEff),
172  ], ncols=3, legendDy=_legendDy_1row),
173  PlotGroup("mva%d%sPtEta"%(num,pfix2), [
174  Plot("mva_assoc(recoToSim)_mva%d%s_pT"%(num,pfix), xtitle="Track p_{T} (GeV)", ytitle=xtitle+" for true tracks", xlog=True, **argsprofile),
175  Plot("mva_fake_mva%d%s_pT"%(num,pfix), xtitle="Track p_{T} (GeV)", ytitle=xtitle+" for fake tracks", xlog=True, **argsprofile),
176  Plot("mva_assoc(recoToSim)_mva%d%s_eta"%(num,pfix), xtitle="Track #eta", ytitle=xtitle+" for true tracks", **argsprofile),
177  Plot("mva_fake_mva%d%s_eta"%(num,pfix), xtitle="Track #eta", ytitle=xtitle+" for fake tracks", **argsprofile),
178  ], legendDy=_legendDy_2rows)
179  ]
180 
181 _effandfakePtEtaPhi = PlotGroup("effandfakePtEtaPhi", [
182  Plot("efficPt", title="Efficiency vs p_{T}", xtitle="TP p_{T} (GeV)", ytitle="efficiency vs p_{T}", xlog=True, ymax=_maxEff),
183  Plot(FakeDuplicate("fakeduprate_vs_pT", assoc="num_assoc(recoToSim)_pT", dup="num_duplicate_pT", reco="num_reco_pT", title="fake+duplicates vs p_{T}"),
184  xtitle="track p_{T} (GeV)", ytitle="fake+duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
185  Plot("effic", xtitle="TP #eta", ytitle="efficiency vs #eta", title="", ymax=_maxEff),
186  Plot(FakeDuplicate("fakeduprate_vs_eta", assoc="num_assoc(recoToSim)_eta", dup="num_duplicate_eta", reco="num_reco_eta", title=""),
187  xtitle="track #eta", ytitle="fake+duplicates rate vs #eta", ymax=_maxFake),
188 ] +
189  _makeEffFakeDupPlots("phi", "#phi")
190 )
191 
192 _effandfakeDxyDzBS = PlotGroup("effandfakeDxyDzBS",
193  _makeEffFakeDupPlots("dxy" , "dxy" , "cm") +
194  _makeEffFakeDupPlots("dz" , "dz" , "cm"),
195  legendDy=_legendDy_2rows
196 )
197 _effandfakeDxyDzPV = PlotGroup("effandfakeDxyDzPV",
198  _makeEffFakeDupPlots("dxypv" , "dxy(PV)", "cm") +
199  _makeEffFakeDupPlots("dxypv_zoomed", "dxy(PV)", "cm") +
200  _makeEffFakeDupPlots("dzpv" , "dz(PV)" , "cm") +
201  _makeEffFakeDupPlots("dzpv_zoomed" , "dz(PV)" , "cm"),
202  legendDy=_legendDy_4rows
203 )
204 _effandfakeHitsLayers = PlotGroup("effandfakeHitsLayers",
205  _makeEffFakeDupPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
206  _makeEffFakeDupPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
207  _makeEffFakeDupPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
208  _makeEffFakeDupPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
209  legendDy=_legendDy_4rows
210 )
211 _common = {"ymin": 0, "ymax": _maxEff}
212 _effandfakePos = PlotGroup("effandfakePos",
213  _makeEffFakeDupPlots("vertpos", "vert r", "cm", fakeopts=dict(xtitle="track ref. point r (cm)", ytitle="fake+duplicates vs. r"), common=dict(xlog=True)) +
214  _makeEffFakeDupPlots("zpos" , "vert z", "cm", fakeopts=dict(xtitle="track ref. point z (cm)", ytitle="fake+duplicates vs. z")) +
215  _makeEffFakeDupPlots("simpvz" , "Sim. PV z", "cm", common=dict(xtitle="Sim. PV z (cm)", xmin=_minZ, xmax=_maxZ))
216 )
217 _effandfakeDeltaRPU = PlotGroup("effandfakeDeltaRPU",
218  _makeEffFakeDupPlots("dr" , "#DeltaR", effopts=dict(xtitle="TP min #DeltaR"), fakeopts=dict(xtitle="track min #DeltaR"), common=dict(xlog=True)) +
219  _makeEffFakeDupPlots("drj" , "#DeltaR(track, jet)", effopts=dict(xtitle="#DeltaR(TP, jet)", ytitle="efficiency vs #DeltaR(TP, jet"), fakeopts=dict(xtitle="#DeltaR(track, jet)"), common=dict(xlog=True))+
220  _makeEffFakeDupPlots("pu" , "PU" , common=dict(xtitle="Pileup", xmin=_minPU, xmax=_maxPU)),
221  legendDy=_legendDy_4rows
222 )
223 
224 
225 _algos_common = dict(removeEmptyBins=True, xbinlabelsize=10, xbinlabeloption="d")
226 _duplicateAlgo = PlotOnSideGroup("duplicateAlgo", Plot("duplicates_oriAlgo_vs_oriAlgo", drawStyle="COLZ", adjustMarginLeft=0.1, adjustMarginRight=0.1, **_algos_common))
227 
228 _dupandfakePtEtaPhi = PlotGroup("dupandfakePtEtaPhi", [
229  Plot("fakeratePt", xtitle="track p_{T} (GeV)", ytitle="fakerate vs p_{T}", xlog=True, ymax=_maxFake),
230  Plot("duplicatesRate_Pt", xtitle="track p_{T} (GeV)", ytitle="duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
231  Plot("pileuprate_Pt", xtitle="track p_{T} (GeV)", ytitle="pileup rate vs p_{T}", ymax=_maxFake, xlog=True),
232  Plot("fakerate", xtitle="track #eta", ytitle="fakerate vs #eta", title="", ymax=_maxFake),
233  Plot("duplicatesRate", xtitle="track #eta", ytitle="duplicates rate vs #eta", title="", ymax=_maxFake),
234  Plot("pileuprate", xtitle="track #eta", ytitle="pileup rate vs #eta", title="", ymax=_maxFake),
235 ] + _makeFakeDupPileupPlots("phi", "#phi"),
236  ncols=3
237 )
238 _dupandfakeDxyDzBS = PlotGroup("dupandfakeDxyDzBS",
239  _makeFakeDupPileupPlots("dxy" , "dxy" , "cm") +
240  _makeFakeDupPileupPlots("dz" , "dz" , "cm"),
241  ncols=3, legendDy=_legendDy_2rows_3cols
242 )
243 _dupandfakeDxyDzPV = PlotGroup("dupandfakeDxyDzPV",
244  _makeFakeDupPileupPlots("dxypv" , "dxy(PV)", "cm") +
245  _makeFakeDupPileupPlots("dxypv_zoomed", "dxy(PV)", "cm") +
246  _makeFakeDupPileupPlots("dzpv" , "dz(PV)" , "cm") +
247  _makeFakeDupPileupPlots("dzpv_zoomed" , "dz(PV)" , "cm"),
248  ncols=3, legendDy=_legendDy_4rows
249 )
250 _dupandfakeHitsLayers = PlotGroup("dupandfakeHitsLayers",
251  _makeFakeDupPileupPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
252  _makeFakeDupPileupPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
253  _makeFakeDupPileupPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
254  _makeFakeDupPileupPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
255  ncols=3, legendDy=_legendDy_4rows
256 )
257 _dupandfakePos = PlotGroup("dupandfakePos",
258  _makeFakeDupPileupPlots("vertpos", "r", "cm", xquantity="ref. point r (cm)", common=dict(xlog=True)) +
259  _makeFakeDupPileupPlots("zpos" , "z", "cm", xquantity="ref. point z (cm)") +
260  _makeFakeDupPileupPlots("simpvz" , "Sim. PV z", xtitle="Sim. PV z (cm)", common=dict(xmin=_minZ, xmax=_maxZ)),
261  ncols=3,
262 )
263 _dupandfakeDeltaRPU = PlotGroup("dupandfakeDeltaRPU",
264  _makeFakeDupPileupPlots("dr" , "#DeltaR", xquantity="min #DeltaR", common=dict(xlog=True)) +
265  _makeFakeDupPileupPlots("drj" , "#DeltaR(track, jet)", xtitle="#DeltaR(track, jet)", common=dict(xlog=True)) +
266  _makeFakeDupPileupPlots("pu" , "PU" , xtitle="Pileup", common=dict(xmin=_minPU, xmax=_maxPU)),
267  ncols=3
268 )
269 _seedingLayerSet_common = dict(removeEmptyBins=True, xbinlabelsize=8, xbinlabeloption="d", adjustMarginRight=0.1)
270 _dupandfakeSeedingPlots = _makeFakeDupPileupPlots("seedingLayerSet", "seeding layers", xtitle="", common=_seedingLayerSet_common)
271 _dupandfakeChi2Seeding = PlotGroup("dupandfakeChi2Seeding",
272  _makeFakeDupPileupPlots("chi2", "#chi^{2}") +
273  _dupandfakeSeedingPlots,
274  ncols=3, legendDy=_legendDy_2rows_3cols
275 )
276 
277 _common = {
278  "ytitle": "Fake+pileup rate",
279  "ymax": _maxFake,
280  "drawStyle": "EP",
281 }
282 _common2 = {}
283 _common2.update(_common)
284 _common2["drawStyle"] = "pcolz"
285 _common2["ztitleoffset"] = 1.5
286 _common2["xtitleoffset"] = 7
287 _common2["ytitleoffset"] = 10
288 _common2["ztitleoffset"] = 6
289 _pvassociation1 = PlotGroup("pvassociation1", [
290  Plot(ROC("effic_vs_fakepileup_dzpvcut", "effic_vs_dzpvcut", FakeDuplicate("fakepileup_vs_dzpvcut", assoc="num_assoc(recoToSim)_dzpvcut", reco="num_reco_dzpvcut", dup="num_pileup_dzpvcut")),
291  xtitle="Efficiency vs. cut on dz(PV)", **_common),
292  Plot(ROC("effic_vs_fakepileup2_dzpvcut", "effic_vs_dzpvcut", FakeDuplicate("fakepileup_vs_dzpvcut", assoc="num_assoc(recoToSim)_dzpvcut", reco="num_reco_dzpvcut", dup="num_pileup_dzpvcut"), zaxis=True),
293  xtitle="Efficiency", ztitle="Cut on dz(PV)", **_common2),
294  #
295  Plot(ROC("effic_vs_fakepileup_dzpvsigcut", "effic_vs_dzpvsigcut", FakeDuplicate("fakepileup_vs_dzpvsigcut", assoc="num_assoc(recoToSim)_dzpvsigcut", reco="num_reco_dzpvsigcut", dup="num_pileup_dzpvsigcut")),
296  xtitle="Efficiency vs. cut on dz(PV)/dzError", **_common),
297  Plot(ROC("effic_vs_fakepileup2_dzpvsigcut", "effic_vs_dzpvsigcut", FakeDuplicate("fakepileup_vs_dzpvsigcut", assoc="num_assoc(recoToSim)_dzpvsigcut", reco="num_reco_dzpvsigcut", dup="num_pileup_dzpvsigcut"), zaxis=True),
298  xtitle="Efficiency", ztitle="Cut on dz(PV)/dzError", **_common2),
299 
300  Plot(ROC("effic_vs_fakepileup_dzpvcut_pt", "effic_vs_dzpvcut_pt", FakeDuplicate("fakepileup_vs_dzpvcut_pt", assoc="num_assoc(recoToSim)_dzpvcut_pt", reco="num_reco_dzpvcut_pt", dup="num_pileup_dzpvcut_pt")),
301  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)", **_common),
302  Plot(ROC("effic_vs_fakepileup2_dzpvcut_pt", "effic_vs_dzpvcut_pt", FakeDuplicate("fakepileup_vs_dzpvcut_pt", assoc="num_assoc(recoToSim)_dzpvcut_pt", reco="num_reco_dzpvcut_pt", dup="num_pileup_dzpvcut_pt"), zaxis=True),
303  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)", **_common2),
304  #
305  Plot(ROC("effic_vs_fakepileup_dzpvsigcut_pt", "effic_vs_dzpvsigcut_pt", FakeDuplicate("fakepileup_vs_dzpvsigcut_pt", assoc="num_assoc(recoToSim)_dzpvsigcut_pt", reco="num_reco_dzpvsigcut_pt", dup="num_pileup_dzpvsigcut_pt")),
306  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)/dzError", **_common),
307  Plot(ROC("effic_vs_fakepileup2_dzpvsigcut_pt", "effic_vs_dzpvsigcut_pt", FakeDuplicate("fakepileup_vs_dzpvsigcut_pt", assoc="num_assoc(recoToSim)_dzpvsigcut_pt", reco="num_reco_dzpvsigcut_pt", dup="num_pileup_dzpvsigcut_pt"), zaxis=True),
308  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)/dzError", **_common2),
309 ], onlyForPileup=True,
310  legendDy=_legendDy_4rows
311 )
312 _pvassociation2 = PlotGroup("pvassociation2", [
313  Plot("effic_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency vs. cut on dz(PV)", ymax=_maxEff),
314  Plot("effic_vs_dzpvcut2", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
315  Plot("fakerate_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate vs. cut on dz(PV)", ymax=_maxFake),
316  Plot("pileuprate_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate vs. cut on dz(PV)", ymax=_maxFake),
317  #
318  Plot("effic_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency vs. cut on dz(PV)/dzError", ymax=_maxEff),
319  Plot("effic_vs_dzpvsigcut2", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
320  Plot("fakerate_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
321  Plot("pileuprate_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
322 ], onlyForPileup=True,
323  legendDy=_legendDy_4rows
324 )
325 _pvassociation3 = PlotGroup("pvassociation3", [
326  Plot("effic_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
327  Plot("effic_vs_dzpvcut2_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
328  Plot("fakerate_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
329  Plot("pileuprate_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
330  #
331  Plot("effic_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
332  Plot("effic_vs_dzpvsigcut2_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
333  Plot("fakerate_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
334  Plot("pileuprate_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
335 ], onlyForPileup=True,
336  legendDy=_legendDy_4rows
337 )
338 
339 
340 # These don't exist in FastSim
341 _common = {"normalizeToUnitArea": True, "stat": True, "drawStyle": "hist"}
342 _dedx = PlotGroup("dedx", [
343  Plot("h_dedx_estim1", xtitle="dE/dx, harm2", **_common),
344  Plot("h_dedx_estim2", xtitle="dE/dx, trunc40", **_common),
345  Plot("h_dedx_nom1", xtitle="dE/dx number of measurements", title="", **_common),
346  Plot("h_dedx_sat1", xtitle="dE/dx number of measurements with saturation", title="", **_common),
347  ],
348  legendDy=_legendDy_2rows
349 )
350 
351 _chargemisid = PlotGroup("chargemisid", [
352  Plot("chargeMisIdRate", xtitle="#eta", ytitle="charge mis-id rate vs #eta", ymax=0.05),
353  Plot("chargeMisIdRate_Pt", xtitle="p_{T}", ytitle="charge mis-id rate vs p_{T}", xmax=300, ymax=0.1, xlog=True),
354  Plot("chargeMisIdRate_hit", xtitle="hits", ytitle="charge mis-id rate vs hits", title=""),
355  Plot("chargeMisIdRate_phi", xtitle="#phi", ytitle="charge mis-id rate vs #phi", title="", ymax=0.01),
356  Plot("chargeMisIdRate_dxy", xtitle="dxy", ytitle="charge mis-id rate vs dxy", ymax=0.1),
357  Plot("chargeMisIdRate_dz", xtitle="dz", ytitle="charge mis-id rate vs dz", ymax=0.1)
358 ])
359 _common = {"stat": True, "normalizeToUnitArea": True, "ylog": True, "ymin": 1e-6, "drawStyle": "hist"}
360 _hitsAndPt = PlotGroup("hitsAndPt", [
361  Plot("missing_inner_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
362  Plot("missing_outer_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
363  Plot("hits_eta", xtitle="track #eta", ytitle="<hits> vs #eta", ymin=_minHits, ymax=_maxHits, statyadjust=[0,0,-0.15],
364  fallback={"name": "nhits_vs_eta", "profileX": True}),
365  Plot("hits", stat=True, xtitle="track hits", xmin=_minHits, xmax=_maxHits, ylog=True, ymin=[5e-1, 5, 5e1, 5e2, 5e3], drawStyle="hist"),
366  Plot("num_simul_pT", xtitle="TP p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common),
367  Plot("num_reco_pT", xtitle="track p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common)
368 ])
369 _tuning = PlotGroup("tuning", [
370  Plot("chi2", stat=True, normalizeToUnitArea=True, ylog=True, ymin=1e-6, ymax=[0.1, 0.2, 0.5, 1.0001], drawStyle="hist", xtitle="#chi^{2}", ratioUncertainty=False),
371  Plot("chi2_prob", stat=True, normalizeToUnitArea=True, drawStyle="hist", xtitle="Prob(#chi^{2})"),
372  Plot("chi2mean", title="", xtitle="#eta", ytitle="< #chi^{2} / ndf >", ymin=[0, 0.5], ymax=[2, 2.5, 3, 5],
373  fallback={"name": "chi2_vs_eta", "profileX": True}),
374  Plot("ptres_vs_eta_Mean", scale=100, title="", xtitle="TP #eta (PCA to beamline)", ytitle="< #delta p_{T} / p_{T} > (%)", ymin=_minResidualPt, ymax=_maxResidualPt)
375 ])
376 _common = {"stat": True, "fit": True, "normalizeToUnitArea": True, "drawStyle": "hist", "drawCommand": "", "xmin": -10, "xmax": 10, "ylog": True, "ymin": 5e-5, "ymax": [0.01, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025], "ratioUncertainty": False}
377 _pulls = PlotGroup("pulls", [
378  Plot("pullPt", **_common),
379  Plot("pullQoverp", **_common),
380  Plot("pullPhi", **_common),
381  Plot("pullTheta", **_common),
382  Plot("pullDxy", **_common),
383  Plot("pullDz", **_common),
384 ],
385  legendDx=0.1, legendDw=-0.1, legendDh=-0.015
386 )
387 _common = {"title": "", "ylog": True, "xtitle": "TP #eta (PCA to beamline)", "ymin": _minMaxResol, "ymax": _minMaxResol}
388 _resolutionsEta = PlotGroup("resolutionsEta", [
389  Plot("phires_vs_eta_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
390  Plot("cotThetares_vs_eta_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
391  Plot("dxyres_vs_eta_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
392  Plot("dzres_vs_eta_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
393  Plot("ptres_vs_eta_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
394 ])
395 _common = {"title": "", "ylog": True, "xlog": True, "xtitle": "TP p_{T} (PCA to beamline)", "xmin": 0.1, "xmax": 1000, "ymin": _minMaxResol, "ymax": _minMaxResol}
396 _resolutionsPt = PlotGroup("resolutionsPt", [
397  Plot("phires_vs_pt_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
398  Plot("cotThetares_vs_pt_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
399  Plot("dxyres_vs_pt_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
400  Plot("dzres_vs_pt_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
401  Plot("ptres_vs_pt_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
402 ])
403 
404 ## Extended set of plots
405 _extDistPtEtaPhi = PlotGroup("distPtEtaPhi",
406  _makeDistPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
407  _makeDistPlots("eta", "#eta") +
408  _makeDistPlots("phi", "#phi"),
409  ncols=4)
410 _extDistDxyDzBS = PlotGroup("distDxyDzBS",
411  _makeDistPlots("dxy" , "dxy (cm)") +
412  _makeDistPlots("dz" , "dz (cm)"),
413  ncols=4, legendDy=_legendDy_2rows)
414 _extDistDxyDzPV = PlotGroup("distDxyDzPV",
415  _makeDistPlots("dxypv" , "dxy(PV) (cm)") +
416  _makeDistPlots("dxypv_zoomed", "dxy(PV) (cm)") +
417  _makeDistPlots("dzpv" , "dz(PV) (cm)") +
418  _makeDistPlots("dzpv_zoomed" , "dz(PV) (cm)"),
419  ncols=4, legendDy=_legendDy_4rows)
420 _extDistHitsLayers = PlotGroup("distHitsLayers",
421  _makeDistPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
422  _makeDistPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
423  _makeDistPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
424  _makeDistPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
425  ncols=4, legendDy=_legendDy_4rows,
426 )
427 _extDistPos = PlotGroup("distPos",
428  _makeDistPlots("vertpos", "ref. point r (cm)", common=dict(xlog=True)) +
429  _makeDistPlots("zpos" , "ref. point z (cm)") +
430  _makeDistPlots("simpvz" , "Sim. PV z (cm)", common=dict(xmin=_minZ, xmax=_maxZ)),
431  ncols=3,
432 )
433 _extDistDeltaR = PlotGroup("distDeltaR",
434  _makeDistPlots("dr" , "min #DeltaR", common=dict(xlog=True)) +
435  _makeDistPlots("drj" , "#DeltaR(track, jet)", common=dict(xlog=True)),
436  ncols=2, legendDy=_legendDy_2rows,
437 )
438 _extDistSeedingPlots = _makeDistPlots("seedingLayerSet", "seeding layers", common=dict(xtitle="", **_seedingLayerSet_common))
439 _extDistChi2Seeding = PlotGroup("distChi2Seeding",
440  _makeDistPlots("chi2", "#chi^{2}") +
441  _extDistSeedingPlots,
442  ncols=4, legendDy=_legendDy_2rows_3cols
443 )
444 _common = dict(title="", xtitle="TP #eta (PCA to beamline)")
445 _extResidualEta = PlotGroup("residualEta", [
446  Plot("phires_vs_eta_Mean", ytitle="< #delta #phi > (rad)", ymin=_minResidualPhi, ymax=_maxResidualPhi, **_common),
447  Plot("cotThetares_vs_eta_Mean", ytitle="< #delta cot(#theta) >", ymin=_minResidualCotTheta, ymax=_maxResidualCotTheta, **_common),
448  Plot("dxyres_vs_eta_Mean", ytitle="< #delta d_{xy} > (#mum)", scale=10000, ymin=_minResidualDxy, ymax=_maxResidualDxy, **_common),
449  Plot("dzres_vs_eta_Mean", ytitle="< #delta d_{z} > (#mum)", scale=10000, ymin=_minResidualDz, ymax=_maxResidualDz, **_common),
450  Plot("ptres_vs_eta_Mean", ytitle="< #delta p_{T}/p_{T} > (%)", scale=100, ymin=_minResidualPt, ymax=_maxResidualPt, **_common), # same as in tuning, but to be complete
451 ])
452 _common = dict(title="", xlog=True, xtitle="TP p_{T} (PCA to beamline)", xmin=0.1, xmax=1000)
453 _extResidualPt = PlotGroup("residualPt", [
454  Plot("phires_vs_pt_Mean", ytitle="< #delta #phi > (rad)", ymin=_minResidualPhi, ymax=_maxResidualPhi, **_common),
455  Plot("cotThetares_vs_pt_Mean", ytitle="< #delta cot(#theta > )", ymin=_minResidualCotTheta, ymax=_maxResidualCotTheta, **_common),
456  Plot("dxyres_vs_pt_Mean", ytitle="< #delta d_{xy} > (#mum)", scale=10000, ymin=_minResidualDxy, ymax=_maxResidualDxy, **_common),
457  Plot("dzres_vs_pt_Mean", ytitle="< #delta d_{z} > (#mum)", scale=10000, ymin=_minResidualDz, ymax=_maxResidualDz, **_common),
458  Plot("ptres_vs_pt_Mean", ytitle="< #delta p_{T}/p_{T} > (%)", scale=100, ymin=_minResidualPt, ymax=_maxResidualPt, **_common), # same as in tuning, but to be complete
459 ])
460 _common = dict(title="", ytitle="Selected tracks/TrackingParticles", ymax=_maxEff)
461 _extNrecVsNsim = PlotGroup("nrecVsNsim", [
462  Plot("nrec_vs_nsim", title="", xtitle="TrackingParticles", ytitle="Tracks", profileX=True, xmin=_minMaxTracks, xmax=_minMaxTracks, ymin=_minMaxTracks, ymax=_minMaxTracks),
463  Plot("nrecPerNsim_vs_pu", xtitle="Pileup", xmin=_minPU, xmax=_maxPU, **_common),
464  Plot("nrecPerNsimPt", xtitle="p_{T} (GeV)", xlog=True, **_common),
465  Plot("nrecPerNsim", xtitle="#eta", **_common)
466 ], legendDy=_legendDy_2rows)
467 _extHitsLayers = PlotGroup("hitsLayers", [
468  Plot("PXLhits_vs_eta", xtitle="#eta", ytitle="<pixel hits>"),
469  Plot("PXLlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<pixel layers>"),
470  Plot("STRIPhits_vs_eta", xtitle="#eta", ytitle="<strip hits>"),
471  Plot("STRIPlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<strip layers>"),
472 ], legendDy=_legendDy_2rows)
473 
474 
475 ## Extended set of plots also for simulation
476 _extDistSimPtEtaPhi = PlotGroup("distsimPtEtaPhi",
477  _makeDistSimPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
478  _makeDistSimPlots("eta", "#eta") +
479  _makeDistSimPlots("phi", "#phi"),
480  ncols=2)
481 _extDistSimDxyDzBS = PlotGroup("distsimDxyDzBS",
482  _makeDistSimPlots("dxy" , "dxy (cm)") +
483  _makeDistSimPlots("dz" , "dz (cm)"),
484  ncols=2, legendDy=_legendDy_2rows)
485 _extDistSimDxyDzPV = PlotGroup("distsimDxyDzPV",
486  _makeDistSimPlots("dxypv" , "dxy(PV) (cm)") +
487  _makeDistSimPlots("dxypv_zoomed", "dxy(PV) (cm)") +
488  _makeDistSimPlots("dzpv" , "dz(PV) (cm)") +
489  _makeDistSimPlots("dzpv_zoomed" , "dz(PV) (cm)"),
490  ncols=2, legendDy=_legendDy_4rows)
491 _extDistSimHitsLayers = PlotGroup("distsimHitsLayers",
492  _makeDistSimPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
493  _makeDistSimPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
494  _makeDistSimPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
495  _makeDistSimPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
496  ncols=2, legendDy=_legendDy_4rows,
497 )
498 _extDistSimPos = PlotGroup("distsimPos",
499  _makeDistSimPlots("vertpos", "vert r (cm)", common=dict(xlog=True)) +
500  _makeDistSimPlots("zpos" , "vert z (cm)") +
501  _makeDistSimPlots("simpvz" , "Sim. PV z (cm)", common=dict(xmin=_minZ, xmax=_maxZ)),
502  ncols=3,
503 )
504 _extDistSimDeltaR = PlotGroup("distsimDeltaR",
505  _makeDistSimPlots("dr" , "min #DeltaR", common=dict(xlog=True)) +
506  _makeDistSimPlots("drj" , "#DeltaR(TP, jet)", common=dict(xlog=True)),
507  ncols=2, legendDy=_legendDy_2rows,
508 )
509 
510 ########################################
511 #
512 # Summary plots
513 #
514 ########################################
515 
516 _possibleTrackingNonIterationColls = [
517  'ak4PFJets',
518  'btvLike',
519 ]
520 _possibleTrackingColls = [
521  'initialStepPreSplitting',
522  'initialStep',
523  'highPtTripletStep', # phase1
524  'detachedQuadStep', # phase1
525  'detachedTripletStep',
526  'lowPtQuadStep', # phase1
527  'lowPtTripletStep',
528  'pixelPairStepA', # seeds
529  'pixelPairStepB', # seeds
530  'pixelPairStepC', # seeds
531  'pixelPairStep',
532  'mixedTripletStepA', # seeds
533  'mixedTripletStepB', # seeds
534  'mixedTripletStep',
535  'pixelLessStep',
536  'tobTecStepPair', # seeds
537  'tobTecStepTripl', # seeds
538  'tobTecStep',
539  'jetCoreRegionalStep',
540  'muonSeededStepInOut',
541  'muonSeededStepOutIn',
542  'duplicateMerge',
543 ] + _possibleTrackingNonIterationColls
544 _possibleTrackingCollsOld = {
545  "Zero" : "iter0",
546  "First" : "iter1",
547  "Second": "iter2",
548  "Third" : "iter3",
549  "Fourth": "iter4",
550  "Fifth" : "iter5",
551  "Sixth" : "iter6",
552  "Seventh": "iter7",
553  "Ninth" : "iter9",
554  "Tenth" : "iter10",
555 }
556 
558  ret = subfolder.replace("trackingParticleRecoAsssociation", "AssociatorByHitsRecoDenom")
559  for (old, new) in [("InitialStep", "Zero"),
560  ("HighPtTripletStep", "First"),
561  ("LowPtQuadStep", "Second"),
562  ("LowPtTripletStep", "Third"),
563  ("DetachedQuadStep", "Fourth"),
564  ("PixelPairStep", "Fifth"),
565  ("MuonSeededStepInOut", "Ninth"),
566  ("MuonSeededStepOutIn", "Tenth")]:
567  ret = ret.replace(old, new)
568  if ret == subfolder:
569  return None
570  return ret
572  for (old, new) in [("initialStep", "iter0"),
573  ("highPtTripletStep", "iter1"),
574  ("lowPtQuadStep", "iter2"),
575  ("lowPtTripletStep", "iter3"),
576  ("detachedQuadStep", "iter4"),
577  ("pixelPairStep", "iter5"),
578  ("muonSeededStepInOut", "iter9"),
579  ("muonSeededStepOutIn", "iter10")]:
580  path = path.replace(old, new)
581  return path
582 
584  return subfolder.replace("trackingParticleRecoAsssociation", "trackingParticleRecoAsssociationSignal")
586  return subfolder.replace("quickAssociatorByHits", "quickAssociatorByHitsConversion")
588  return subfolder.replace("quickAssociatorByHits", "quickAssociatorByHitsPreSplitting")
589 
590 # Additional "quality" flags than highPurity. In a separate list to
591 # allow customization.
592 _additionalTrackQualities = [
593  "Pt09",
594  "ByOriginalAlgo",
595  "ByAlgoMask"
596 ]
598  if "Hp" in collName:
599  quality = "highPurity"
600  else:
601  quality = ""
602  collNameNoQuality = collName.replace("Hp", "")
603  for qual in _additionalTrackQualities:
604  if qual in collName:
605  quality += qual
606  collNameNoQuality = collNameNoQuality.replace(qual, "")
607 
608  collNameNoQuality = collNameNoQuality.replace("Tracks", "", 1) # make summary naming consistent with iteration folders
609  collNameLow = collNameNoQuality.lower().replace("frompv2", "").replace("frompv", "").replace("frompvalltp", "").replace("alltp", "")
610 
611  if collNameLow.find("seed") == 0:
612  collNameLow = collNameLow[4:]
613  if collNameLow == "initialstepseedspresplitting":
614  collNameLow = "initialsteppresplittingseeds"
615  elif collNameLow == "muonseededseedsinout":
616  collNameLow = "muonseededstepinoutseeds"
617  elif collNameLow == "muonseededseedsoutin":
618  collNameLow = "muonseededstepoutinseeds"
619 
620  i_seeds = collNameLow.index("seeds")
621  quality = collNameLow[i_seeds:]+quality
622 
623  collNameLow = collNameLow[:i_seeds]
624 
625  algo = None
626  prefixes = ["cutsreco", "cutsrecofrompv", "cutsrecofrompv2", "cutsrecofrompvalltp"]
627  if collNameLow in ["general", "generalfrompv"]+prefixes:
628  algo = "ootb"
629  else:
630  def testColl(coll):
631  for pfx in prefixes:
632  if coll == collNameLow.replace(pfx, ""):
633  return True
634  return False
635 
636  for coll in _possibleTrackingColls:
637  if testColl(coll.lower()):
638  algo = coll
639  break
640  # next try "old style"
641  if algo is None:
642  for coll, name in six.iteritems(_possibleTrackingCollsOld):
643  if testColl(coll.lower()):
644  algo = name
645  break
646 
647  # fallback
648  if algo is None:
649  algo = collNameNoQuality
650 
651  # fix for track collection naming convention
652  if algo == "muonSeededInOut":
653  algo = "muonSeededStepInOut"
654  if algo == "muonSeededOutIn":
655  algo = "muonSeededStepOutIn"
656 
657  return (algo, quality)
658 
659 def _collhelper(name):
660  return (name, [name])
661 _collLabelMap = collections.OrderedDict(map(_collhelper, ["generalTracks"]+_possibleTrackingColls))
662 _collLabelMapHp = collections.OrderedDict(map(_collhelper, ["generalTracks"]+[n for n in _possibleTrackingColls if "Step" in n]))
663 def _summaryBinRename(binLabel, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds):
664  (algo, quality) = _mapCollectionToAlgoQuality(binLabel)
665  if algo == "ootb":
666  algo = "generalTracks"
667  ret = None
668 
669  if byOriginalAlgo:
670  if algo != "generalTracks" and "ByOriginalAlgo" not in quality: # keep generalTracks bin as well
671  return None
672  quality = quality.replace("ByOriginalAlgo", "")
673  if byAlgoMask:
674  if algo != "generalTracks" and "ByAlgoMask" not in quality: # keep generalTracks bin as well
675  return None
676  quality = quality.replace("ByAlgoMask", "")
677  if ptCut:
678  if "Pt09" not in quality:
679  return None
680  quality = quality.replace("Pt09", "")
681 
682  if highPurity:
683  if quality == "highPurity":
684  ret = algo
685  elif seeds:
686  i_seeds = quality.find("seeds")
687  if i_seeds == 0:
688  ret = algo
689  seedSubColl = quality[i_seeds+5:]
690  if seedSubColl != "":
691  ret += seedSubColl[0].upper() + seedSubColl[1:]
692  else:
693  if quality == "":
694  ret = algo
695 
696  return ret
697 
698 def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False, midfix=""):
699  _common = {"drawStyle": "EP", "xbinlabelsize": 10, "xbinlabeloption": "d"}
700  _commonN = dict(ylog=True, ymin=_minMaxN, ymax=_minMaxN,
701  normalizeToNumberOfEvents=True,
702  )
703  _commonN.update(_common)
704  _commonAB = dict(mapping=mapping,
705  renameBin=lambda bl: _summaryBinRename(bl, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds),
706  ignoreMissingBins=True,
707  originalOrder=True,
708  )
709  if byOriginalAlgo or byAlgoMask:
710  _commonAB["minExistingBins"] = 2
711  prefix = "summary"+midfix
712 
713  h_eff = "effic_vs_coll"
714  h_fakerate = "fakerate_vs_coll"
715  h_duplicaterate = "duplicatesRate_coll"
716  h_pileuprate = "pileuprate_coll"
717 
718  h_reco = "num_reco_coll"
719  h_true = "num_assoc(recoToSim)_coll"
720  h_fake = Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll")
721  h_duplicate = "num_duplicate_coll"
722  h_pileup = "num_pileup_coll"
723  if mapping is not None:
724  h_eff = AggregateBins("efficiency", h_eff, **_commonAB)
725  h_fakerate = AggregateBins("fakerate", h_fakerate, **_commonAB)
726  h_duplicaterate = AggregateBins("duplicatesRate", h_duplicaterate, **_commonAB)
727  h_pileuprate = AggregateBins("pileuprate", h_pileuprate, **_commonAB)
728 
729  h_reco = AggregateBins("num_reco_coll", h_reco, **_commonAB)
730  h_true = AggregateBins("num_true_coll", h_true, **_commonAB)
731  h_fake = AggregateBins("num_fake_coll", h_fake, **_commonAB)
732  h_duplicate = AggregateBins("num_duplicate_coll", h_duplicate, **_commonAB)
733  h_pileup = AggregateBins("num_pileup_coll", h_pileup, **_commonAB)
734 
735  summary = PlotGroup(prefix, [
736  Plot(h_eff, title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
737  Plot(h_fakerate, title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
738  #
739  Plot(h_duplicaterate, title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
740  Plot(h_pileuprate, title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
741  ],
742  legendDy=_legendDy_2rows
743  )
744  summaryN = PlotGroup(prefix+"_ntracks", [
745  # FIXME
746  #Plot(h_reco, ytitle="Tracks/event", title="Number of tracks/event vs collection", **_commonN),
747  #Plot(h_true, ytitle="True tracks/event", title="Number of true tracks/event vs collection", **_commonN),
748  #Plot(h_fake, ytitle="Fake tracks/event", title="Number of fake tracks/event vs collection", **_commonN),
749  #Plot(h_duplicate, ytitle="Duplicate tracks/event", title="Number of duplicate tracks/event vs collection", **_commonN),
750  #Plot(h_pileup, ytitle="Pileup tracks/event", title="Number of pileup tracks/event vs collection", **_commonN),
751  Plot(h_reco, ytitle="Tracks", title="Number of tracks vs collection", **_commonN),
752  Plot(h_true, ytitle="True tracks", title="Number of true tracks vs collection", **_commonN),
753  Plot(h_fake, ytitle="Fake tracks", title="Number of fake tracks vs collection", **_commonN),
754  Plot(h_duplicate, ytitle="Duplicate tracks", title="Number of duplicate tracks vs collection", **_commonN),
755  Plot(h_pileup, ytitle="Pileup tracks", title="Number of pileup tracks vs collection", **_commonN),
756  ])
757 
758  return (summary, summaryN)
759 
760 (_summaryRaw, _summaryRawN) = _constructSummary(midfix="Raw")
761 (_summary, _summaryN) = _constructSummary(_collLabelMap)
762 (_summaryHp, _summaryNHp) = _constructSummary(_collLabelMapHp, highPurity=True)
763 (_summaryByOriginalAlgo, _summaryByOriginalAlgoN) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo")
764 (_summaryByOriginalAlgoHp, _summaryByOriginalAlgoNHp) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo", highPurity=True)
765 (_summaryByAlgoMask, _summaryByAlgoMaskN) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask")
766 (_summaryByAlgoMaskHp, _summaryByAlgoMaskNHp) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask", highPurity=True)
767 (_summaryPt09, _summaryPt09N) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09")
768 (_summaryPt09Hp, _summaryPt09NHp) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09", highPurity=True)
769 (_summarySeeds, _summarySeedsN) = _constructSummary(_collLabelMapHp, seeds=True)
770 
771 ########################################
772 #
773 # PackedCandidate plots
774 #
775 ########################################
776 
777 _common = {"normalizeToUnitArea": True, "ylog": True, "ymin": [1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2], "ymax": [1e-2, 1e-1, 1.1]}
778 _commonStatus = {}
779 _commonStatus.update(_common)
780 _commonStatus.update({"xbinlabelsize": 10, "xbinlabeloption": "d", "drawStyle": "hist", "adjustMarginRight": 0.08})
781 _commonLabelSize = {}
782 _commonLabelSize.update(_common)
783 _commonLabelSize.update({"xlabelsize": 17})
784 
785 _packedCandidateFlow = PlotGroup("flow", [
786  Plot("selectionFlow", xbinlabelsize=10, xbinlabeloption="d", adjustMarginRight=0.1, drawStyle="hist", ylog=True, ymin=[0.9, 9, 9e1, 9e2, 9e3, 9e4, 9e5, 9e6, 9e7]),
787  Plot("diffCharge", xtitle="Charge", **_common),
788  Plot("diffIsHighPurity", xtitle="High purity status", **_common),
789  Plot("diffNdof", xtitle="ndof", **_common),
790  Plot("diffNormalizedChi2", xtitle="#chi^{2}/ndof", **_common),
791 ])
792 
793 _packedCandidateHitsHitPattern = PlotGroup("hitsHitPattern", [
794  Plot("diffHitPatternNumberOfValidHits", xtitle="Valid hits (via HitPattern)", **_common),
795  Plot("diffHitPatternNumberOfValidPixelHits", xtitle="Valid pixel hits (via HitPattern)", **_common),
796  Plot("diffHitPatternHasValidHitInFirstPixelBarrel", xtitle="Has valid hit in BPix1 layer (via HitPattern)", **_common),
797  Plot("diffHitPatternNumberOfLostPixelHits", xtitle="Lost pixel hits (via HitPattern)", **_common),
798 ],
799  legendDy=_legendDy_2rows
800 )
801 _packedCandidateHits = PlotGroup("hits", [
802  Plot("diffNumberOfHits", xtitle="Hits", **_common),
803  Plot("diffNumberOfPixelHits", xtitle="Pixel hits", **_common),
804  Plot("diffLostInnerHits", xtitle="Lost inner hits", **_common),
805  Plot("numberHitsOverMax", xtitle="Number of overflown hits", **_common),
806  Plot("numberPixelHitsOverMax", xtitle="Number of overflown pixel hits", **_common),
807  Plot("numberStripHitsOverMax", xtitle="Number of overflown strip hits", **_common),
808 ],
809  ncols=3, legendDy=_legendDy_2rows_3cols
810 )
811 
812 _packedCandidateLayers = PlotGroup("layers", [
813  PlotEmpty(),
814  Plot("diffNumberOfPixelLayers", xtitle="Pixel layers", **_common),
815  Plot("diffNumberOfStripLayers", xtitle="Strip layers", **_common),
816  #
817  Plot("diffHitPatternTrackerLayersWithMeasurement", xtitle="Layers (via HitPattern)", **_common),
818  Plot("diffHitPatternPixelLayersWithMeasurement", xtitle="Pixel layers (via HitPattern)", **_common),
819  Plot("diffHitPatternStripLayersWithMeasurement", xtitle="Strip layers (via HitPattern)", **_common),
820  #
821  Plot("numberLayersOverMax", xtitle="Number of overflown layers", **_common),
822  Plot("numberPixelLayersOverMax", xtitle="Number of overflown pixel layers", **_common),
823  Plot("numberStripLayersOverMax", xtitle="Number of overflown strip layers", **_common),
824 ],
825  ncols=3
826 )
827 
828 
829 _packedCandidateImpactParameter1 = PlotGroup("impactParameter1", [
830  Plot("diffDxyAssocPV", xtitle="dxy(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
831  Plot("diffDxyAssocPVStatus", **_commonStatus),
832  Plot("diffDxyAssocPVUnderOverFlowSign", xtitle="dxy(assocPV)", **_common),
833  Plot("diffDzAssocPV", xtitle="dz(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
834  Plot("diffDzAssocPVStatus", **_commonStatus),
835  Plot("diffDzAssocPVUnderOverFlowSign", xtitle="dz(assocPV)", **_common),
836  Plot("diffDxyError", xtitle="dxyError()", adjustMarginRight=0.02, **_commonLabelSize),
837  Plot("diffDszError", xtitle="dszError()", adjustMarginRight=0.02, **_commonLabelSize),
838  Plot("diffDzError", xtitle="dzError()", adjustMarginRight=0.02, **_commonLabelSize),
839 
840 ],
841  ncols=3
842 )
843 
844 _packedCandidateImpactParameter2 = PlotGroup("impactParameter2", [
845  Plot("diffDxyPV", xtitle="dxy(PV) via PC", **_commonLabelSize),
846  Plot("diffDzPV", xtitle="dz(PV) via PC", **_commonLabelSize),
847  Plot("diffTrackDxyAssocPV", xtitle="dxy(PV) via PC::bestTrack()", **_commonLabelSize),
848  Plot("diffTrackDzAssocPV", xtitle="dz(PV) via PC::bestTrack()", **_commonLabelSize),
849  Plot("diffTrackDxyError", xtitle="dxyError() via PC::bestTrack()", adjustMarginRight=0.02, **_commonLabelSize),
850  Plot("diffTrackDzError", xtitle="dzError() via PC::bestTrack()", **_commonLabelSize),
851 ])
852 
853 _packedCandidateCovarianceMatrix1 = PlotGroup("covarianceMatrix1", [
854  Plot("diffCovQoverpQoverp", xtitle="cov(qoverp, qoverp)", **_commonLabelSize),
855  Plot("diffCovQoverpQoverpStatus", **_commonStatus),
856  Plot("diffCovQoverpQoverpUnderOverFlowSign", xtitle="cov(qoverp, qoverp)", **_common),
857  Plot("diffCovLambdaLambda", xtitle="cov(lambda, lambda)", **_commonLabelSize),
858  Plot("diffCovLambdaLambdaStatus", **_commonStatus),
859  Plot("diffCovLambdaLambdaUnderOverFlowSign", xtitle="cov(lambda, lambda)", **_common),
860  Plot("diffCovLambdaDsz", xtitle="cov(lambda, dsz)", **_commonLabelSize),
861  Plot("diffCovLambdaDszStatus", **_commonStatus),
862  Plot("diffCovLambdaDszUnderOverFlowSign", xtitle="cov(lambda, dsz)", **_common),
863  Plot("diffCovPhiPhi", xtitle="cov(phi, phi)", **_commonLabelSize),
864  Plot("diffCovPhiPhiStatus", **_commonStatus),
865  Plot("diffCovPhiPhiUnderOverFlowSign", xtitle="cov(phi, phi)", **_common),
866 ],
867  ncols=3, legendDy=_legendDy_4rows
868 )
869 _packedCandidateCovarianceMatrix2 = PlotGroup("covarianceMatrix2", [
870  Plot("diffCovPhiDxy", xtitle="cov(phi, dxy)", **_commonLabelSize),
871  Plot("diffCovPhiDxyStatus", **_commonStatus),
872  Plot("diffCovPhiDxyUnderOverFlowSign", xtitle="cov(phi, dxy)", **_common),
873  Plot("diffCovDxyDxy", xtitle="cov(dxy, dxy)", adjustMarginRight=0.02, **_commonLabelSize),
874  Plot("diffCovDxyDxyStatus", **_commonStatus),
875  Plot("diffCovDxyDxyUnderOverFlowSign", xtitle="cov(dxy, dxy)", **_common),
876  Plot("diffCovDxyDsz", xtitle="cov(dxy, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
877  Plot("diffCovDxyDszStatus", **_commonStatus),
878  Plot("diffCovDxyDszUnderOverFlowSign", xtitle="cov(dxy, dsz)", **_common),
879  Plot("diffCovDszDsz", xtitle="cov(dsz, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
880  Plot("diffCovDszDszStatus", **_commonStatus),
881  Plot("diffCovDszDszUnderOverFlowSign", xtitle="cov(dsz, dsz)", **_common),
882 ],
883  ncols=3, legendDy=_legendDy_4rows
884 )
885 
886 _common["xlabelsize"] = 16
887 _packedCandidateVertex = PlotGroup("vertex", [
888  Plot("diffVx", xtitle="Reference point x", **_common),
889  Plot("diffVy", xtitle="Reference point y", **_common),
890  Plot("diffVz", xtitle="Reference point z", **_common),
891 ],
892  legendDy=_legendDy_2rows
893 )
894 
895 _common["adjustMarginRight"] = 0.05
896 _packedCandidateKinematics = PlotGroup("kinematics", [
897  Plot("diffPt", xtitle="p_{T}", **_common),
898  Plot("diffPtError", xtitle="p_{T} error", **_common),
899  Plot("diffEta", xtitle="#eta", **_common),
900  Plot("diffEtaError", xtitle="#eta error", **_common),
901  Plot("diffPhi", xtitle="#phi", **_common),
902 ])
903 
905  def __init__(self, *args, **kwargs):
906  self._fallbackRefFiles = kwargs.pop("fallbackRefFiles", [])
907  PlotFolder.__init__(self, *args, **kwargs)
908 
909  def translateSubFolder(self, dqmSubFolderName):
910  spl = dqmSubFolderName.split("_")
911  if len(spl) != 2:
912  return None
913  collName = spl[0]
914  return _mapCollectionToAlgoQuality(collName)
915 
916  def iterSelectionName(self, plotFolderName, translatedDqmSubFolder):
917  (algoOrig, quality) = translatedDqmSubFolder
918 
919  for fallback in [lambda n: n]+self._fallbackRefFiles:
920  algo = fallback(algoOrig)
921 
922  ret = ""
923  if plotFolderName != "":
924  ret += "_"+plotFolderName
925  if quality != "":
926  ret += "_"+quality
927  if not (algo == "ootb" and quality != ""):
928  ret += "_"+algo
929  yield ret
930 
931  def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder):
932  """Return True if this subfolder should be processed
933 
934  Arguments:
935  limitOnlyTo -- Function '(algo, quality) -> bool'
936  translatedDqmSubFolder -- Return value of translateSubFolder
937  """
938  (algo, quality) = translatedDqmSubFolder
939  return limitOnlyTo(algo, quality)
940 
941  # track-specific hack
942  def isAlgoIterative(self, algo):
943  return algo not in _possibleTrackingNonIterationColls
944 
946  class GeneralTracks: pass
947  class GeneralTracksPt09: pass
948  class HighPurity: pass
949  class HighPurityPt09: pass
950  class BTVLike: pass
951  class AK4PFJets: pass
952  class Pixel: pass
953 
954  def __init__(self, section, collection=GeneralTracks):
955  self._collection = collection
957  self._page = "summary"
958  self._section = section
959 
960  def getPurpose(self):
961  return self._purpose
962 
963  def getPage(self):
964  return self._page
965 
966  def getSection(self, dqmSubFolder):
967  return self._section
968 
969  def create(self, tdirectory):
970  def _getAlgoQuality(data, algo, quality):
971  for label, value in six.iteritems(data):
972  (a, q) = _mapCollectionToAlgoQuality(label)
973  if a == algo and q == quality:
974  return value[0] # value is (value, uncertainty) tuple
975  return None
976  def _getN(hname):
977  h = tdirectory.Get(hname)
978  if not h:
979  return None
982  return _getAlgoQuality(data, "ootb", "")
984  return _getAlgoQuality(data, "ootb", "Pt09")
986  return _getAlgoQuality(data, "ootb", "highPurity")
988  return _getAlgoQuality(data, "ootb", "highPurityPt09")
990  return _getAlgoQuality(data, "btvLike", "")
992  return _getAlgoQuality(data, "ak4PFJets", "")
994  return _getAlgoQuality(data, "pixel", "")
995  else:
996  raise Exception("Collection not recognized, %s" % str(self._collection))
997  def _formatOrNone(num, func):
998  if num is None:
999  return None
1000  return func(num)
1001 
1002  n_tps = _formatOrNone(_getN("num_simul_coll"), int)
1003  n_m_tps = _formatOrNone(_getN("num_assoc(simToReco)_coll"), int)
1004 
1005  n_tracks = _formatOrNone(_getN("num_reco_coll"), int)
1006  n_true = _formatOrNone(_getN("num_assoc(recoToSim)_coll"), int)
1007  if n_tracks is not None and n_true is not None:
1008  n_fake = n_tracks-n_true
1009  else:
1010  n_fake = None
1011  n_pileup = _formatOrNone(_getN("num_pileup_coll"), int)
1012  n_duplicate = _formatOrNone(_getN("num_duplicate_coll"), int)
1013 
1014  eff = _formatOrNone(_getN("effic_vs_coll"), lambda n: "%.4f" % n)
1015  eff_nopt = _formatOrNone(_getN("effic_vs_coll_allPt"), lambda n: "%.4f" % n)
1016  fake = _formatOrNone(_getN("fakerate_vs_coll"), lambda n: "%.4f" % n)
1017  duplicate = _formatOrNone(_getN("duplicatesRate_coll"), lambda n: "%.4f" % n)
1018 
1019  ret = [eff, n_tps, n_m_tps,
1020  eff_nopt, fake, duplicate,
1021  n_tracks, n_true, n_fake, n_pileup, n_duplicate]
1022  if ret.count(None) == len(ret):
1023  return None
1024  return ret
1025 
1026  def headers(self):
1027  return [
1028  "Efficiency",
1029  "Number of TrackingParticles (after cuts)",
1030  "Number of matched TrackingParticles",
1031  "Efficiency (w/o pT cut)",
1032  "Fake rate",
1033  "Duplicate rate",
1034  "Number of tracks",
1035  "Number of true tracks",
1036  "Number of fake tracks",
1037  "Number of pileup tracks",
1038  "Number of duplicate tracks"
1039  ]
1040 
1041 # Provide a "PlotGroup" interface, but provide a html page
1043  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1044  self._plots = plots
1045  self._titles = titles
1046  self._fileName = fileName
1047  self._format = "%.4g" if isRate else "%d"
1048 
1049  if len(plots) != len(titles):
1050  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1051 
1052  def _set(attr, default):
1053  setattr(self, "_"+attr, kwargs.get(attr, default))
1054 
1055  _set("onlyForPileup", False)
1056 
1057  def onlyForPileup(self):
1058  """Return True if the PlotGroup is intended only for pileup samples"""
1059  return self._onlyForPileup
1060 
1061  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1062  # [plot][histo]
1063  for plot in self._plots:
1064  plot.create(tdirectoryNEvents, requireAllHistograms)
1065 
1066  def draw(self, legendLabels, prefix=None, directory="", *args, **kwargs):
1067  # Do not make the table if it would be empty
1068  onlyEmptyPlots = True
1069  for plot in self._plots:
1070  if not plot.isEmpty():
1071  onlyEmptyPlots = False
1072  break
1073  if onlyEmptyPlots:
1074  return []
1075 
1076  haveShortLabels = False
1077  legendLabels = legendLabels[:]
1078  if max(map(len, legendLabels)) > 20:
1079  haveShortLabels = True
1080  labels_short = [str(chr(ord('A')+i)) for i in range(len(legendLabels))]
1081  for i, ls in enumerate(labels_short):
1082  legendLabels[i] = "%s: %s" % (ls, legendLabels[i])
1083  else:
1084  labels_short = legendLabels
1085 
1086  content = [
1087  '<html>',
1088  ' <body>',
1089  ' <table border="1">',
1090  ' <tr>',
1091  ]
1092 
1093 
1094  histos_linear = []
1095  histos_index = []
1096  labels = []
1097  for plot, title in zip(self._plots, self._titles):
1098  h_tmp = []
1099  l_tmp = []
1100  for h, l in zip(plot._histograms, labels_short):
1101  if h is not None:
1102  h_tmp.append(len(histos_linear))
1103  histos_linear.append(h)
1104  l_tmp.append(l)
1105 
1106  if len(h_tmp) > 0:
1107  histos_index.append(h_tmp)
1108  labels.append(l_tmp)
1109  content.extend([
1110  ' <td></td>',
1111  ' <td colspan="%d">%s</td>' % (len(h_tmp), title),
1112  ])
1113 
1114  if len(histos_linear) == 0:
1115  return []
1116 
1117  content.extend([
1118  ' </tr>',
1119  ' <tr>',
1120  ])
1121 
1122  xbinlabels = plotting._mergeBinLabelsX(histos_linear)
1123  histos_linear = plotting._th1IncludeOnlyBins(histos_linear, xbinlabels)
1124  if len(histos_linear) == 0:
1125  return []
1126  (histos_linear_new, xbinlabels) = plotting._th1RemoveEmptyBins(histos_linear, xbinlabels)
1127  # in practice either all histograms are returned, or none, but let's add a check anyway
1128  if len(histos_linear_new) > 0 and len(histos_linear_new) != len(histos_linear):
1129  raise Exception("This should never happen. len(histos_linear_new) %d != len(histos_linear) %d" % (len(histos_linear_new), len(histos_linear)))
1130  histos_linear = histos_linear_new
1131  if len(histos_linear) == 0:
1132  return []
1133 
1134  data = [ [h.GetBinContent(i) for i in range(1, h.GetNbinsX()+1)] for h in histos_linear]
1135  table = html.Table(["dummy"]*len(histos_linear), xbinlabels, data, None, None, None)
1136  data = table.tableAsRowColumn()
1137 
1138  for labs in labels:
1139  content.append(' <td></td>')
1140  content.extend([' <td>%s</td>' % lab for lab in labs])
1141  content.extend([
1142  ' </tr>',
1143  ])
1144 
1145  for irow, row in enumerate(data):
1146  content.extend([
1147  ' <tr>',
1148  ' <td>%s</td>' % table.rowHeaders()[irow]
1149  ])
1150 
1151  for hindices in histos_index:
1152  for hindex in hindices:
1153  item = row[hindex]
1154  formatted = self._format%item if item is not None else ""
1155  content.append(' <td align="right">%s</td>' % formatted)
1156  content.append(' <td></td>')
1157  del content[-1]
1158  content.append(' </tr>')
1159 
1160  content.append(' </table>')
1161  if haveShortLabels:
1162  for lab in legendLabels:
1163  content.append(' %s<br/>' % lab)
1164 
1165  content.extend([
1166  ' </body>',
1167  '<html>'
1168  ])
1169 
1170  name = self._fileName
1171  if prefix is not None:
1172  name = prefix+name
1173  name += ".html"
1174  name = os.path.join(directory, name)
1175 
1176  with open(name, "w") as f:
1177  for line in content:
1178  f.write(line)
1179  f.write("\n")
1180  return [name]
1181 
1182 _dupandfakeSeedingTable = TrackingSeedingLayerTable("dupandfakeSeeding", [p.clone() for p in _dupandfakeSeedingPlots],
1183  ["Fake rate", "Duplicate rate", "Pileup rate"], isRate=True)
1184 _extDistSeedingTable = TrackingSeedingLayerTable("distSeeding", [p.clone() for p in _extDistSeedingPlots],
1185  ["All tracks", "True tracks", "Fake tracks", "Duplicate tracks"], isRate=False)
1186 
1187 def _trackingFolders(lastDirName="Track"):
1188  return [
1189  "DQMData/Run 1/Tracking/Run summary/"+lastDirName,
1190  "DQMData/Tracking/"+lastDirName,
1191  "DQMData/Run 1/RecoTrackV/Run summary/"+lastDirName,
1192  "DQMData/RecoTrackV/"+lastDirName,
1193  ]
1194 
1195 _simBasedPlots = [
1196  _effandfakePtEtaPhi,
1197  _effandfakeDxyDzBS,
1198  _effandfakeDxyDzPV,
1199  _effandfakeHitsLayers,
1200  _effandfakePos,
1201  _effandfakeDeltaRPU,
1202  _duplicateAlgo,
1203 ]
1204 _recoBasedPlots = [
1205  _dupandfakePtEtaPhi,
1206  _dupandfakeDxyDzBS,
1207  _dupandfakeDxyDzPV,
1208  _dupandfakeHitsLayers,
1209  _dupandfakePos,
1210  _dupandfakeDeltaRPU,
1211  _dupandfakeChi2Seeding,
1212  _dupandfakeSeedingTable,
1213  _pvassociation1,
1214  _pvassociation2,
1215  _pvassociation3,
1216  _dedx,
1217 # _chargemisid,
1218  _hitsAndPt,
1219  _pulls,
1220  _resolutionsEta,
1221  _resolutionsPt,
1222  _tuning,
1223 ]
1224 _seedingBuildingPlots = _simBasedPlots + [
1225  _dupandfakePtEtaPhi,
1226  _dupandfakeDxyDzBS,
1227  _dupandfakeDxyDzPV,
1228  _dupandfakeHitsLayers,
1229  _dupandfakePos,
1230  _dupandfakeDeltaRPU,
1231  _dupandfakeChi2Seeding,
1232  _dupandfakeSeedingTable,
1233  _hitsAndPt,
1234 ] + _makeMVAPlots(1) \
1235  + _makeMVAPlots(2) \
1236  + _makeMVAPlots(2, hp=True) \
1237  + _makeMVAPlots(3) \
1238  + _makeMVAPlots(3, hp=True)
1239 # add more if needed
1240 _buildingExtendedPlots = [
1241  _pulls,
1242  _resolutionsEta,
1243  _resolutionsPt,
1244  _tuning,
1245 ]
1246 _extendedPlots = [
1247  _extDistPtEtaPhi,
1248  _extDistDxyDzBS,
1249  _extDistDxyDzPV,
1250  _extDistHitsLayers,
1251  _extDistPos,
1252  _extDistDeltaR,
1253  _extDistChi2Seeding,
1254  _extDistSeedingTable,
1255  _extResidualEta,
1256  _extResidualPt,
1257  _extNrecVsNsim,
1258  _extHitsLayers,
1259  _extDistSimPtEtaPhi,
1260  _extDistSimDxyDzBS,
1261  _extDistSimDxyDzPV,
1262  _extDistSimHitsLayers,
1263  _extDistSimPos,
1264  _extDistSimDeltaR,
1265 ]
1266 _summaryPlots = [
1267  _summary,
1268  _summaryN,
1269  _summaryByOriginalAlgo,
1270  _summaryByOriginalAlgoN,
1271  _summaryByAlgoMask,
1272  _summaryByAlgoMaskN,
1273  _summaryPt09,
1274  _summaryPt09N,
1275 ]
1276 _summaryPlotsHp = [
1277  _summaryHp,
1278  _summaryNHp,
1279  _summaryByOriginalAlgoHp,
1280  _summaryByOriginalAlgoNHp,
1281  _summaryByAlgoMaskHp,
1282  _summaryByAlgoMaskNHp,
1283  _summaryPt09Hp,
1284  _summaryPt09NHp,
1285 ]
1286 _summaryPlotsSeeds = [
1287  _summarySeeds,
1288  _summarySeedsN,
1289 ]
1290 _packedCandidatePlots = [
1291  _packedCandidateFlow,
1292  _packedCandidateKinematics,
1293  _packedCandidateVertex,
1294  _packedCandidateImpactParameter1,
1295  _packedCandidateImpactParameter2,
1296  _packedCandidateCovarianceMatrix1,
1297  _packedCandidateCovarianceMatrix2,
1298  _packedCandidateHits,
1299  _packedCandidateHitsHitPattern,
1300  _packedCandidateLayers,
1301 ]
1302 plotter = Plotter()
1303 plotterExt = Plotter()
1304 def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, onlyForElectron=False, onlyForConversion=False, onlyForBHadron=False, seeding=False, building=False, rawSummary=False, highPuritySummary=True):
1305  folders = _trackingFolders(lastDirName)
1306  # to keep backward compatibility, this set of plots has empty name
1307  limiters = dict(onlyForPileup=onlyForPileup, onlyForElectron=onlyForElectron, onlyForConversion=onlyForConversion, onlyForBHadron=onlyForBHadron)
1308  commonForTPF = dict(purpose=PlotPurpose.TrackingIteration, fallbackRefFiles=[
1309  _trackingRefFileFallbackSLHC_Phase1PU140
1310  ], **limiters)
1311  common = dict(fallbackDqmSubFolders=[
1312  _trackingSubFoldersFallbackSLHC_Phase1PU140,
1313  _trackingSubFoldersFallbackFromPV, _trackingSubFoldersFallbackConversion,
1314  _trackingSubFoldersFallbackPreSplitting])
1315  plotter.append(name, folders, TrackingPlotFolder(*algoPlots, **commonForTPF), **common)
1316  extendedPlots = []
1317  if building:
1318  extendedPlots.extend(_buildingExtendedPlots)
1319  extendedPlots.extend(_extendedPlots)
1320  plotterExt.append(name, folders, TrackingPlotFolder(*extendedPlots, **commonForTPF), **common)
1321 
1322  summaryName = ""
1323  if name != "":
1324  summaryName += name+"_"
1325  summaryName += "summary"
1326  summaryPlots = []
1327  if rawSummary:
1328  summaryPlots.extend([_summaryRaw, _summaryRawN])
1329  summaryPlots.extend(_summaryPlots)
1330 
1331  common = dict(loopSubFolders=False, purpose=PlotPurpose.TrackingSummary, page="summary",
1332  #numberOfEventsHistogram=_trackingNumberOfEventsHistogram, # FIXME
1333  **limiters)
1334  plotter.append(summaryName, folders,
1335  PlotFolder(*summaryPlots, section=name, **common))
1336  if highPuritySummary:
1337  plotter.append(summaryName+"_highPurity", folders,
1338  PlotFolder(*_summaryPlotsHp, section=name+"_highPurity" if name != "" else "highPurity", **common),
1339  fallbackNames=[summaryName]) # backward compatibility for release validation, the HP plots used to be in the same directory with all-track plots
1340  if seeding:
1341  plotter.append(summaryName+"_seeds", folders,
1342  PlotFolder(*_summaryPlotsSeeds, section=name+"_seeds", **common))
1343 
1344  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section=name))
1345  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section=name+"Pt09", collection=TrackingSummaryTable.GeneralTracksPt09))
1346  if highPuritySummary:
1347  sectionName = name+"_highPurity" if name != "" else "highPurity"
1348  plotter.appendTable(summaryName+"_highPurity", folders, TrackingSummaryTable(section=sectionName, collection=TrackingSummaryTable.HighPurity))
1349  plotter.appendTable(summaryName+"_highPurity", folders, TrackingSummaryTable(section=sectionName+"Pt09", collection=TrackingSummaryTable.HighPurityPt09))
1350  if name == "":
1351  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="btvLike", collection=TrackingSummaryTable.BTVLike))
1352  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="ak4PFJets", collection=TrackingSummaryTable.AK4PFJets))
1353 _appendTrackingPlots("Track", "", _simBasedPlots+_recoBasedPlots)
1354 _appendTrackingPlots("TrackTPPtLess09", "tpPtLess09", _simBasedPlots)
1355 _appendTrackingPlots("TrackAllTPEffic", "allTPEffic", _simBasedPlots, onlyForPileup=True)
1356 _appendTrackingPlots("TrackFromPV", "fromPV", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1357 _appendTrackingPlots("TrackFromPVAllTP", "fromPVAllTP", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1358 _appendTrackingPlots("TrackFromPVAllTP2", "fromPVAllTP2", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1359 _appendTrackingPlots("TrackSeeding", "seeding", _seedingBuildingPlots, seeding=True)
1360 _appendTrackingPlots("TrackBuilding", "building", _seedingBuildingPlots, building=True)
1361 _appendTrackingPlots("TrackConversion", "conversion", _simBasedPlots+_recoBasedPlots, onlyForConversion=True, rawSummary=True, highPuritySummary=False)
1362 _appendTrackingPlots("TrackGsf", "gsf", _simBasedPlots+_recoBasedPlots, onlyForElectron=True, rawSummary=True, highPuritySummary=False)
1363 _appendTrackingPlots("TrackBHadron", "bhadron", _simBasedPlots+_recoBasedPlots, onlyForBHadron=True)
1364 # Pixel tracks
1365 _common = dict(purpose=PlotPurpose.Pixel, page="pixel")
1366 plotter.append("pixelTrack", _trackingFolders("PixelTrack"), TrackingPlotFolder(*(_simBasedPlots+_recoBasedPlots), **_common))
1367 plotterExt.append("pixelTrack", _trackingFolders("PixelTrack"), TrackingPlotFolder(*_extendedPlots, **_common))
1368 plotter.append("pixelTrack_summary", _trackingFolders("PixelTrack"), PlotFolder(_summaryRaw, _summaryRawN, loopSubFolders=False, purpose=PlotPurpose.TrackingSummary, page="summary", section="pixel"))
1369 plotter.appendTable("pixelTrack_summary", _trackingFolders("PixelTrack"), TrackingSummaryTable(section="pixel", collection=TrackingSummaryTable.Pixel))
1370 
1371 
1372 # MiniAOD
1373 plotter.append("packedCandidate", _trackingFolders("PackedCandidate"),
1374  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1375  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate"))
1376 plotter.append("packedCandidateLostTracks", _trackingFolders("PackedCandidate/lostTracks"),
1377  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1378  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate (lostTracks)"))
1379 
1380 # HLT
1381 _hltFolder = [
1382  "DQMData/Run 1/HLT/Run summary/Tracking/ValidationWRTtp",
1383 ]
1384 plotterHLT = Plotter()
1385 plotterHLTExt = Plotter()
1386 _common = dict(purpose=PlotPurpose.HLT, page="hlt")
1387 plotterHLT.append("hlt", _hltFolder, TrackingPlotFolder(*(_simBasedPlots+_recoBasedPlots), **_common))
1388 plotterHLTExt.append("hlt", _hltFolder, TrackingPlotFolder(*_extendedPlots, **_common))
1389 
1390 # Timing
1392  def __init__(self, name, clusterMasking=None, seeding=None, building=None, fit=None, selection=None, other=[]):
1393  self._name = name
1394 
1395  def _set(param, name, modules):
1396  if param is not None:
1397  setattr(self, name, param)
1398  else:
1399  setattr(self, name, modules)
1400 
1401  _set(clusterMasking, "_clusterMasking", [self._name+"Clusters"])
1402  # it's fine to include e.g. quadruplets here also for pair
1403  # steps, as non-existing modules are just ignored
1404  _set(seeding, "_seeding", [self._name+"SeedingLayers", self._name+"TrackingRegions", self._name+"HitDoublets", self._name+"HitTriplets", self._name+"HitQuadruplets", self._name+"Seeds"])
1405  _set(building, "_building", [self._name+"TrackCandidates"])
1406  _set(fit, "_fit", [self._name+"Tracks"])
1407  _set(selection, "_selection", [self._name])
1408  self._other = other
1409 
1410  def name(self):
1411  return self._name
1412 
1413  def all(self):
1414  return self._clusterMasking+self._seeding+self._building+self._fit+self._selection+self._other
1415 
1416  def clusterMasking(self):
1417  return self._clusterMasking
1418 
1419  def seeding(self):
1420  return self._seeding
1421 
1422  def building(self):
1423  return self._building
1424 
1425  def fit(self):
1426  return self._fit
1427 
1428  def selection(self):
1429  return self._selection
1430 
1431  def other(self):
1432  return self._other
1433 
1434  def modules(self):
1435  return [("ClusterMask", self.clusterMasking()),
1436  ("Seeding", self.seeding()),
1437  ("Building", self.building()),
1438  ("Fit", self.fit()),
1439  ("Selection", self.selection()),
1440  ("Other", self.other())]
1441 
1442 
1443 _iterations = [
1444  Iteration("initialStepPreSplitting", clusterMasking=[],
1445  seeding=["initialStepSeedLayersPreSplitting",
1446  "initialStepTrackingRegionsPreSplitting",
1447  "initialStepHitDoubletsPreSplitting",
1448  "initialStepHitTripletsPreSplitting",
1449  "initialStepHitQuadrupletsPreSplitting",
1450  "initialStepSeedsPreSplitting"],
1451  building=["initialStepTrackCandidatesPreSplitting"],
1452  fit=["initialStepTracksPreSplitting"],
1453  other=["firstStepPrimaryVerticesPreSplitting",
1454  "initialStepTrackRefsForJetsPreSplitting",
1455  "caloTowerForTrkPreSplitting",
1456  "ak4CaloJetsForTrkPreSplitting",
1457  "jetsForCoreTrackingPreSplitting",
1458  "siPixelClusters",
1459  "siPixelRecHits",
1460  "MeasurementTrackerEvent",
1461  "siPixelClusterShapeCache"]),
1462  Iteration("initialStep", clusterMasking=[],
1463  selection=["initialStepClassifier1",
1464  "initialStepClassifier2",
1465  "initialStepClassifier3",
1466  "initialStep",
1467  "initialStepSelector"],
1468  other=["firstStepPrimaryVerticesUnsorted",
1469  "initialStepTrackRefsForJets",
1470  "caloTowerForTrk",
1471  "ak4CaloJetsForTrk",
1472  "firstStepPrimaryVertices"]),
1473  Iteration("highPtTripletStep",
1474  selection=["highPtTripletStepClassifier1",
1475  "highPtTripletStepClassifier2",
1476  "highPtTripletStepClassifier3",
1477  "highPtTripletStep",
1478  "highPtTripletStepSelector"]),
1479  Iteration("detachedQuadStep",
1480  selection=["detachedQuadStepClassifier1",
1481  "detachedQuadStepClassifier2",
1482  "detachedQuadStep",
1483  "detachedQuadStepSelector"]),
1484  Iteration("detachedTripletStep",
1485  selection=["detachedTripletStepClassifier1",
1486  "detachedTripletStepClassifier2",
1487  "detachedTripletStep",
1488  "detachedTripletStepSelector"]),
1489  Iteration("lowPtQuadStep",
1490  selection=["lowPtQuadStepClassifier1",
1491  "lowPtQuadStepClassifier2",
1492  "lowPtQuadStep",
1493  "lowPtQuadStepSelector"]),
1494  Iteration("lowPtTripletStep",
1495  selection=["lowPtTripletStepClassifier1",
1496  "lowPtTripletStepClassifier2",
1497  "lowPtTripletStep",
1498  "lowPtTripletStepSelector"]),
1499  Iteration("pixelPairStep",
1500  seeding=["pixelPairStepSeedLayers",
1501  "pixelPairStepSeedLayersB",
1502  "pixelPairStepSeedLayersC",
1503  "pixelPairStepTrackingRegions",
1504  "pixelPairStepTrackingRegionsB",
1505  "pixelPairStepTrackingRegionsC",
1506  "pixelPairStepTrackingRegionsSeedLayersB",
1507  "pixelPairStepHitDoublets",
1508  "pixelPairStepHitDoubletsB",
1509  "pixelPairStepHitDoubletsC",
1510  "pixelPairStepSeedsA",
1511  "pixelPairStepSeedsB",
1512  "pixelPairStepSeedsC",
1513  "pixelPairStepSeeds",],
1514  selection=["pixelPairStep",
1515  "pixelPairStepSelector"]),
1516  Iteration("mixedTripletStep",
1517  seeding=["mixedTripletStepSeedLayersA",
1518  "mixedTripletStepSeedLayersB",
1519  "mixedTripletStepTrackingRegionsA",
1520  "mixedTripletStepTrackingRegionsB",
1521  "mixedTripletStepHitDoubletsA",
1522  "mixedTripletStepHitDoubletsB",
1523  "mixedTripletStepHitTripletsA",
1524  "mixedTripletStepHitTripletsB",
1525  "mixedTripletStepSeedsA",
1526  "mixedTripletStepSeedsB",
1527  "mixedTripletStepSeeds"],
1528  selection=["mixedTripletStepClassifier1",
1529  "mixedTripletStepClassifier2",
1530  "mixedTripletStep",
1531  "mixedTripletStepSelector"]),
1532  Iteration("pixelLessStep",
1533  selection=["pixelLessStepClassifier1",
1534  "pixelLessStepClassifier2",
1535  "pixelLessStep",
1536  "pixelLessStepSelector"]),
1537  Iteration("tobTecStep",
1538  seeding=["tobTecStepSeedLayersTripl",
1539  "tobTecStepSeedLayersPair",
1540  "tobTecStepTrackingRegionsTripl",
1541  "tobTecStepTrackingRegionsPair",
1542  "tobTecStepHitDoubletsTripl",
1543  "tobTecStepHitDoubletsPair",
1544  "tobTecStepHitTripletsTripl",
1545  "tobTecStepSeedsTripl",
1546  "tobTecStepSeedsPair",
1547  "tobTecStepSeeds"],
1548  selection=["tobTecStepClassifier1",
1549  "tobTecStepClassifier2",
1550  "tobTecStep",
1551  "tobTecStepSelector"]),
1552  Iteration("jetCoreRegionalStep",
1553  clusterMasking=[],
1554  other=["jetsForCoreTracking",
1555  "firstStepGoodPrimaryVertices",
1556  ]),
1557  Iteration("muonSeededSteps",
1558  clusterMasking=[],
1559  seeding=["muonSeededSeedsInOut",
1560  "muonSeededSeedsOutIn"],
1561  building=["muonSeededTrackCandidatesInOut",
1562  "muonSeededTrackCandidatesOutIn"],
1563  fit=["muonSeededTracksInOut",
1564  "muonSeededTracksOutIn"],
1565  selection=["muonSeededTracksInOutClassifier",
1566  "muonSeededTracksInOutSelector",
1567  "muonSeededTracksOutIntClassifier",
1568  "muonSeededTracksOutIntSelector"],
1569 # other=["earlyMuons"]
1570  ),
1571  Iteration("duplicateMerge",
1572  clusterMasking=[], seeding=[],
1573  building=["duplicateTrackCandidates"],
1574  fit=["mergedDuplicateTracks"],
1575  selection=["duplicateTrackClassifier"]),
1576  Iteration("generalTracks",
1577  clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1578  other=["preDuplicateMergingGeneralTracks",
1579  "generalTracks"]),
1580  Iteration("ConvStep",
1581  clusterMasking=["convClusters"],
1582  seeding=["convLayerPairs",
1583  "photonConvTrajSeedFromSingleLeg"],
1584  building=["convTrackCandidates"],
1585  fit=["convStepTracks"],
1586  selection=["convStepSelector"]),
1587  Iteration("Other", clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1588  other=["trackerClusterCheckPreSplitting",
1589  "trackerClusterCheck"]),
1590 ]
1591 
1592 def _iterModuleMap(includeConvStep=True, onlyConvStep=False):
1593  iterations = _iterations
1594  if not includeConvStep:
1595  iterations = [i for i in iterations if i.name() != "ConvStep"]
1596  if onlyConvStep:
1597  iterations = [i for i in iterations if i.name() == "ConvStep"]
1598  return collections.OrderedDict([(i.name(), i.all()) for i in iterations])
1600  def getProp(prop):
1601  ret = []
1602  for i in _iterations:
1603  if i.name() == "ConvStep":
1604  continue
1605  ret.extend(getattr(i, prop)())
1606  return ret
1607 
1608  return collections.OrderedDict([
1609  ("ClusterMask", getProp("clusterMasking")),
1610  ("Seeding", getProp("seeding")),
1611  ("Building", getProp("building")),
1612  ("Fitting", getProp("fit")),
1613  ("Selection", getProp("selection")),
1614  ("Other", getProp("other"))
1615  ])
1616 
1618  def __init__(self, name, timeHisto):
1619  self._name = name
1620  self._timeHisto = timeHisto
1621  self._eventsHisto = "path time_real"
1622  self._cache = {}
1623 
1624  def __str__(self):
1625  return self._name
1626 
1627  def _create(self, tdirectory):
1628  timeTh1 = plotting._getOrCreateObject(tdirectory, self._timeHisto)
1629  if timeTh1 is None:
1630  return None
1631 
1632  eventsTh1 = plotting._getOrCreateObject(tdirectory, self._eventsHisto)
1633  if eventsTh1 is None:
1634  return None
1635  nevents = eventsTh1.GetEntries()
1636  if nevents == 0:
1637  return None
1638 
1639  ret = timeTh1.Clone(self._name)
1640  xaxis = ret.GetXaxis()
1641  for i in range(1, ret.GetNbinsX()+1):
1642  ret.SetBinContent(i, ret.GetBinContent(i)/nevents)
1643  ret.SetBinError(i, ret.GetBinError(i)/nevents)
1644  xaxis.SetBinLabel(i, xaxis.GetBinLabel(i).replace(" (unscheduled)", ""))
1645  return ret
1646 
1647  def create(self, tdirectory):
1648  path = tdirectory.GetPath()
1649  if path not in self._cache:
1650  self._cache[path] = self._create(tdirectory)
1651  return self._cache[path]
1652 
1654  def __init__(self, name, timeHisto, selectedTracks=False):
1655  self._name = name
1656  self._timeHisto = timeHisto
1657  self._selectedTracks = selectedTracks
1658 
1659  def __str__(self):
1660  return self._name
1661 
1662  def _getDirectory(self, tfile):
1663  for dirName in _trackingFolders():
1664  tdir = tfile.Get(dirName)
1665  if tdir != None:
1666  return tdir
1667  return None
1668 
1669  def create(self, tdirectory):
1670  timeTh1 = plotting._getOrCreateObject(tdirectory, self._timeHisto)
1671  if timeTh1 is None:
1672  return None
1673 
1674  # this is bit of a hack, but as long as it is needed only
1675  # here, I won't invest in better solution
1676  tfile = tdirectory.GetFile()
1677  trkDir = self._getDirectory(tfile)
1678  if trkDir is None:
1679  return None
1680 
1681  iterMap = copy.copy(_collLabelMapHp)
1682  del iterMap["generalTracks"]
1683  del iterMap["jetCoreRegionalStep"] # this is expensive per track on purpose
1684  if self._selectedTracks:
1685  renameBin = lambda bl: _summaryBinRename(bl, highPurity=True, byOriginalAlgo=False, byAlgoMask=True, ptCut=False, seeds=False)
1686  else:
1687  renameBin = lambda bl: _summaryBinRename(bl, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False)
1688  recoAB = AggregateBins("tmp", "num_reco_coll", mapping=iterMap,ignoreMissingBins=True, renameBin=renameBin)
1689  h_reco_per_iter = recoAB.create(trkDir)
1690  if h_reco_per_iter is None:
1691  return None
1692  values = {}
1693  for i in range(1, h_reco_per_iter.GetNbinsX()+1):
1694  values[h_reco_per_iter.GetXaxis().GetBinLabel(i)] = h_reco_per_iter.GetBinContent(i)
1695 
1696 
1697  result = []
1698  for i in range(1, timeTh1.GetNbinsX()+1):
1699  iterName = timeTh1.GetXaxis().GetBinLabel(i)
1700  if iterName in values:
1701  ntrk = values[iterName]
1702  result.append( (iterName,
1703  timeTh1.GetBinContent(i)/ntrk if ntrk > 0 else 0,
1704  timeTh1.GetBinError(i)/ntrk if ntrk > 0 else 0) )
1705 
1706  if len(result) == 0:
1707  return None
1708 
1709  res = ROOT.TH1F(self._name, self._name, len(result), 0, len(result))
1710  for i, (label, value, error) in enumerate(result):
1711  res.GetXaxis().SetBinLabel(i+1, label)
1712  res.SetBinContent(i+1, value)
1713  res.SetBinError(i+1, error)
1714 
1715  return res
1716 
1718  def __init__(self):
1719  self._cache = {}
1720 
1721  def _findOrder(self, f):
1722  h = f.Get(_trackingIterationOrderHistogram)
1723  if not h:
1724  return None
1725  xaxis = h.GetXaxis()
1726  def _edit(s):
1727  # remove "Tracks" from the track producer name to get the iteration name
1728  # muonSeeded iterations do not have "Step" in the producer name, so add it here
1729  return s.replace("Tracks", "").replace("muonSeeded", "muonSeededStep")
1730  return [_edit(xaxis.GetBinLabel(i)) for i in range(1, h.GetNbinsX()+1)]
1731 
1732  def __call__(self, tdirectory, labels):
1733  ret = list(range(0, len(labels)))
1734  f = tdirectory.GetFile()
1735  if not f:
1736  return ret
1737 
1738  if not f.GetName() in self._cache:
1739  r = self._findOrder(f)
1740  if r is None:
1741  return ret
1742  self._cache[f.GetName()] = r
1743  order = self._cache[f.GetName()]
1744 
1745  # O(N^2) I know, but we're talking about O(10) elements...
1746  orderIndices = []
1747  for l in order:
1748  try:
1749  orderIndices.append(labels.index(l))
1750  except ValueError:
1751  pass
1752  ret = []
1753  for i, l in enumerate(labels):
1754  if l in order:
1755  try:
1756  found = orderIndices.index(i)
1757  if found == 0:
1758  ret.append(i)
1759  else:
1760  ret.append(orderIndices[0])
1761  except ValueError:
1762  ret.append(orderIndices[0])
1763  orderIndices.pop(0)
1764  else:
1765  ret.append(i)
1766  return ret
1767 
1768 _time_per_event_cpu = TimePerEventPlot("timePerEvent", "module_time_thread_total")
1769 _time_per_event_real = TimePerEventPlot("timePerEvent", "module_time_real_total")
1770 
1772  def __init__(self):
1774  self._page = "timing"
1775  self._section = "timing"
1776 
1777  def getPurpose(self):
1778  return self._purpose
1779 
1780  def getPage(self):
1781  return self._page
1782 
1783  def getSection(self, dqmSubFolder):
1784  return self._section
1785 
1786  def _getValues(self, tdirectory, histo):
1787  h = tdirectory.Get(histo)
1788  totalReco = None
1789  if h:
1790  totalReco = "%.1f" % h.Integral()
1791 
1792  creator = AggregateBins("iteration", histo, _iterModuleMap(includeConvStep=False), ignoreMissingBins=True)
1793  h = creator.create(tdirectory)
1794  totalTracking = None
1795  if h:
1796  totalTracking = "%.1f" % h.Integral()
1797 
1798  creator = AggregateBins("iteration", histo, _iterModuleMap(onlyConvStep=True), ignoreMissingBins=True)
1799  h = creator.create(tdirectory)
1800  totalConvStep = None
1801  if h:
1802  totalConvStep = "%.1f" % h.Integral()
1803 
1804  return [
1805  totalReco,
1806  totalTracking,
1807  totalConvStep,
1808  ]
1809 
1810  def create(self, tdirectory):
1811  cpuValues = self._getValues(tdirectory, _time_per_event_cpu)
1812  realValues = self._getValues(tdirectory, _time_per_event_real)
1813 
1814  return cpuValues + realValues
1815 
1816  def headers(self):
1817  return [
1818  "Average reco CPU time / event (ms)",
1819  "Average tracking (w/o convStep) CPU time / event (ms)",
1820  "Average convStep CPU time / event (ms)",
1821  "Average reco real time / event (ms)",
1822  "Average tracking (w/o convStep) real time / event (ms)",
1823  "Average convStep real time / event (ms)",
1824  ]
1825 
1826 _common = {
1827  "drawStyle": "P",
1828  "xbinlabelsize": 10,
1829  "xbinlabeloption": "d"
1830 }
1831 
1832 _iteration_reorder = TrackingIterationOrder()
1833 _time_per_iter_cpu = AggregateBins("iteration", _time_per_event_cpu, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder)
1834 _time_per_iter_real = AggregateBins("iteration", _time_per_event_real, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder)
1835 
1836 _timing_summaryCPU = PlotGroup("summaryCPU", [
1837  Plot(_time_per_iter_cpu,
1838  ytitle="Average CPU time (ms)", title="Average CPU time / event", legendDx=-0.4, **_common),
1839  Plot(AggregateBins("iteration_fraction", _time_per_event_cpu, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder),
1840  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1841  #
1842  Plot(AggregateBins("step", _time_per_event_cpu, _stepModuleMap(), ignoreMissingBins=True),
1843  ytitle="Average CPU time (ms)", title="Average CPU time / event", **_common),
1844  Plot(AggregateBins("step_fraction", _time_per_event_cpu, _stepModuleMap(), ignoreMissingBins=True),
1845  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1846  #
1847  Plot(TimePerTrackPlot("iteration_track", _time_per_iter_cpu, selectedTracks=False),
1848  ytitle="Average CPU time / built track (ms)", title="Average CPU time / built track", **_common),
1849  Plot(TimePerTrackPlot("iteration_trackhp", _time_per_iter_cpu, selectedTracks=True),
1850  ytitle="Average CPU time / selected track (ms)", title="Average CPU time / selected HP track by algoMask", **_common),
1851  ],
1852 )
1853 _timing_summaryReal = PlotGroup("summaryReal", [
1854  Plot(_time_per_iter_real,
1855  ytitle="Average real time (ms)", title="Average real time / event", legendDx=-0.4, **_common),
1856  Plot(AggregateBins("iteration_fraction", _time_per_event_real, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder),
1857  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1858  #
1859  Plot(AggregateBins("step", _time_per_event_real, _stepModuleMap(), ignoreMissingBins=True),
1860  ytitle="Average real time (ms)", title="Average real time / event", **_common),
1861  Plot(AggregateBins("step_fraction", _time_per_event_real, _stepModuleMap(), ignoreMissingBins=True),
1862  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1863  #
1864  Plot(TimePerTrackPlot("iteration_track", _time_per_iter_real, selectedTracks=False),
1865  ytitle="Average real time / built track (ms)", title="Average real time / built track", **_common),
1866  Plot(TimePerTrackPlot("iteration_trackhp", _time_per_iter_real, selectedTracks=True),
1867  ytitle="Average real time / selected track (ms)", title="Average real time / selected HP track by algoMask", **_common),
1868  ],
1869 )
1870 
1871 _timing_iterationsCPU = PlotGroup("iterationsCPU", [
1872  Plot(AggregateBins(i.name(), _time_per_event_cpu, collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1873  ytitle="Average CPU time (ms)", title=i.name(), **_common)
1874  for i in _iterations
1875 ],
1876  ncols=4, legend=False
1877 )
1878 _timing_iterationsReal = PlotGroup("iterationsReal", [
1879  Plot(AggregateBins(i.name(), _time_per_event_real, collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1880  ytitle="Average real time (ms)", title=i.name(), **_common)
1881  for i in _iterations
1882 ],
1883  ncols=4, legend=False
1884 )
1885 
1886 # TODO: to be updated to new FastTimerService format later
1887 #_pixelTiming = PlotGroup("pixelTiming", [
1888 # Plot(AggregateBins("pixel", "reconstruction_step_module_average", {"pixelTracks": ["pixelTracks"]}), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST")
1889 #])
1890 
1891 _timeFolders = [
1892 # "DQMData/Run 1/DQM/Run summary/TimerService/process RECO paths/path reconstruction_step",
1893  "DQMData/Run 1/DQM/Run summary/TimerService/process RECO paths/path prevalidation_step", # because of unscheduled, it's actually prevalidation_step that has all the tracking modules?
1894 ]
1895 timePlotter = Plotter()
1896 timePlotter.append("timing", _timeFolders, PlotFolder(
1897  _timing_summaryCPU,
1898  _timing_iterationsCPU,
1899  _timing_summaryReal,
1900  _timing_iterationsReal,
1901  # _pixelTiming,
1902  loopSubFolders=False, purpose=PlotPurpose.Timing, page="timing"
1903 ))
1904 timePlotter.appendTable("timing", _timeFolders, TrackingTimingTable())
1905 
1906 _common = {"stat": True, "normalizeToUnitArea": True, "drawStyle": "hist"}
1907 _tplifetime = PlotGroup("tplifetime", [
1908  Plot("TPlip", xtitle="TP lip", **_common),
1909  Plot("TPtip", xtitle="TP tip", **_common),
1910 ])
1911 
1912 tpPlotter = Plotter()
1913 tpPlotter.append("tp", [
1914  "DQMData/Run 1/Tracking/Run summary/TrackingMCTruth/TrackingParticle",
1915  "DQMData/Tracking/TrackingMCTruth/TrackingParticle",
1916 ], PlotFolder(
1917  _tplifetime,
1918 ))
def iterSelectionName(self, plotFolderName, translatedDqmSubFolder)
def getSection(self, dqmSubFolder)
def _makeFakeDist(postfix)
def _makeFakeDupPileupPlots(postfix, quantity, unit="", xquantity="", xtitle=None, common={})
def __init__(self, name, timeHisto)
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:58
def _iterModuleMap(includeConvStep=True, onlyConvStep=False)
def replace(string, replacements)
def _makeDistSimPlots(postfix, quantity, common={})
def getSection(self, dqmSubFolder)
def create(self, tdirectory)
def _summaryBinRename(binLabel, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds)
def _trackingSubFoldersFallbackPreSplitting(subfolder)
def translateSubFolder(self, dqmSubFolderName)
def _collhelper(name)
def _mapCollectionToAlgoQuality(collName)
def __init__(self, section, collection=GeneralTracks)
def __init__(self, args, kwargs)
def _minMaxResidual(ma)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def create(self, tdirectoryNEvents, requireAllHistograms=False)
def _trackingSubFoldersFallbackConversion(subfolder)
def __call__(self, tdirectory, labels)
def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, onlyForElectron=False, onlyForConversion=False, onlyForBHadron=False, seeding=False, building=False, rawSummary=False, highPuritySummary=True)
def _trackingSubFoldersFallbackSLHC_Phase1PU140(subfolder)
def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder)
def __init__(self, name, timeHisto, selectedTracks=False)
def _makeMVAPlots(num, hp=False)
def _trackingRefFileFallbackSLHC_Phase1PU140(path)
def _th1RemoveEmptyBins(histos, xbinlabels)
Definition: plotting.py:606
def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False, midfix="")
def _trackingSubFoldersFallbackFromPV(subfolder)
def _makeDistPlots(postfix, quantity, common={})
def __init__(self, fileName, plots, titles, isRate, kwargs)
def _create(self, tdirectory)
def create(self, tdirectory)
def _trackingFolders(lastDirName="Track")
def __init__(self, name, clusterMasking=None, seeding=None, building=None, fit=None, selection=None, other=[])
#define str(s)
def _makeEffFakeDupPlots(postfix, quantity, unit="", common={}, effopts={}, fakeopts={})
def _th1ToOrderedDict(th1, renameBin=None)
Definition: plotting.py:101
def draw(self, legendLabels, prefix=None, directory="", args, kwargs)
def _mergeBinLabelsX(histos)
Definition: plotting.py:706
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def _th1IncludeOnlyBins(histos, xbinlabels)
Definition: plotting.py:743
def _getValues(self, tdirectory, histo)