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  Plot("chi2mean_vs_pt", title="", xtitle="p_{T}", ytitle="< #chi^{2} / ndf >", ymin=[0, 0.5], ymax=[2, 2.5, 3, 5], xlog=True, fallback={"name": "chi2_vs_pt", "profileX": True}),
376  Plot("ptres_vs_pt_Mean", title="", xtitle="p_{T}", ytitle="< #delta p_{T}/p_{T} > (%)", scale=100, ymin=_minResidualPt, ymax=_maxResidualPt,xlog=True)
377 ])
378 _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}
379 _pulls = PlotGroup("pulls", [
380  Plot("pullPt", **_common),
381  Plot("pullQoverp", **_common),
382  Plot("pullPhi", **_common),
383  Plot("pullTheta", **_common),
384  Plot("pullDxy", **_common),
385  Plot("pullDz", **_common),
386 ],
387  legendDx=0.1, legendDw=-0.1, legendDh=-0.015
388 )
389 _common = {"title": "", "ylog": True, "xtitle": "TP #eta (PCA to beamline)", "ymin": _minMaxResol, "ymax": _minMaxResol}
390 _resolutionsEta = PlotGroup("resolutionsEta", [
391  Plot("phires_vs_eta_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
392  Plot("cotThetares_vs_eta_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
393  Plot("dxyres_vs_eta_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
394  Plot("dzres_vs_eta_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
395  Plot("ptres_vs_eta_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
396 ])
397 _common = {"title": "", "ylog": True, "xlog": True, "xtitle": "TP p_{T} (PCA to beamline)", "xmin": 0.1, "xmax": 1000, "ymin": _minMaxResol, "ymax": _minMaxResol}
398 _resolutionsPt = PlotGroup("resolutionsPt", [
399  Plot("phires_vs_pt_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
400  Plot("cotThetares_vs_pt_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
401  Plot("dxyres_vs_pt_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
402  Plot("dzres_vs_pt_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
403  Plot("ptres_vs_pt_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
404 ])
405 
406 ## Extended set of plots
407 _extDistPtEtaPhi = PlotGroup("distPtEtaPhi",
408  _makeDistPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
409  _makeDistPlots("eta", "#eta") +
410  _makeDistPlots("phi", "#phi"),
411  ncols=4)
412 _extDistDxyDzBS = PlotGroup("distDxyDzBS",
413  _makeDistPlots("dxy" , "dxy (cm)") +
414  _makeDistPlots("dz" , "dz (cm)"),
415  ncols=4, legendDy=_legendDy_2rows)
416 _extDistDxyDzPV = PlotGroup("distDxyDzPV",
417  _makeDistPlots("dxypv" , "dxy(PV) (cm)") +
418  _makeDistPlots("dxypv_zoomed", "dxy(PV) (cm)") +
419  _makeDistPlots("dzpv" , "dz(PV) (cm)") +
420  _makeDistPlots("dzpv_zoomed" , "dz(PV) (cm)"),
421  ncols=4, legendDy=_legendDy_4rows)
422 _extDistHitsLayers = PlotGroup("distHitsLayers",
423  _makeDistPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
424  _makeDistPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
425  _makeDistPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
426  _makeDistPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
427  ncols=4, legendDy=_legendDy_4rows,
428 )
429 _extDistPos = PlotGroup("distPos",
430  _makeDistPlots("vertpos", "ref. point r (cm)", common=dict(xlog=True)) +
431  _makeDistPlots("zpos" , "ref. point z (cm)") +
432  _makeDistPlots("simpvz" , "Sim. PV z (cm)", common=dict(xmin=_minZ, xmax=_maxZ)),
433  ncols=3,
434 )
435 _extDistDeltaR = PlotGroup("distDeltaR",
436  _makeDistPlots("dr" , "min #DeltaR", common=dict(xlog=True)) +
437  _makeDistPlots("drj" , "#DeltaR(track, jet)", common=dict(xlog=True)),
438  ncols=2, legendDy=_legendDy_2rows,
439 )
440 _extDistSeedingPlots = _makeDistPlots("seedingLayerSet", "seeding layers", common=dict(xtitle="", **_seedingLayerSet_common))
441 _extDistChi2Seeding = PlotGroup("distChi2Seeding",
442  _makeDistPlots("chi2", "#chi^{2}") +
443  _extDistSeedingPlots,
444  ncols=4, legendDy=_legendDy_2rows_3cols
445 )
446 _common = dict(title="", xtitle="TP #eta (PCA to beamline)")
447 _extResidualEta = PlotGroup("residualEta", [
448  Plot("phires_vs_eta_Mean", ytitle="< #delta #phi > (rad)", ymin=_minResidualPhi, ymax=_maxResidualPhi, **_common),
449  Plot("cotThetares_vs_eta_Mean", ytitle="< #delta cot(#theta) >", ymin=_minResidualCotTheta, ymax=_maxResidualCotTheta, **_common),
450  Plot("dxyres_vs_eta_Mean", ytitle="< #delta d_{xy} > (#mum)", scale=10000, ymin=_minResidualDxy, ymax=_maxResidualDxy, **_common),
451  Plot("dzres_vs_eta_Mean", ytitle="< #delta d_{z} > (#mum)", scale=10000, ymin=_minResidualDz, ymax=_maxResidualDz, **_common),
452  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
453 ])
454 _common = dict(title="", xlog=True, xtitle="TP p_{T} (PCA to beamline)", xmin=0.1, xmax=1000)
455 _extResidualPt = PlotGroup("residualPt", [
456  Plot("phires_vs_pt_Mean", ytitle="< #delta #phi > (rad)", ymin=_minResidualPhi, ymax=_maxResidualPhi, **_common),
457  Plot("cotThetares_vs_pt_Mean", ytitle="< #delta cot(#theta > )", ymin=_minResidualCotTheta, ymax=_maxResidualCotTheta, **_common),
458  Plot("dxyres_vs_pt_Mean", ytitle="< #delta d_{xy} > (#mum)", scale=10000, ymin=_minResidualDxy, ymax=_maxResidualDxy, **_common),
459  Plot("dzres_vs_pt_Mean", ytitle="< #delta d_{z} > (#mum)", scale=10000, ymin=_minResidualDz, ymax=_maxResidualDz, **_common),
460  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
461 ])
462 _common = dict(title="", ytitle="Selected tracks/TrackingParticles", ymax=_maxEff)
463 _extNrecVsNsim = PlotGroup("nrecVsNsim", [
464  Plot("nrec_vs_nsim", title="", xtitle="TrackingParticles", ytitle="Tracks", profileX=True, xmin=_minMaxTracks, xmax=_minMaxTracks, ymin=_minMaxTracks, ymax=_minMaxTracks),
465  Plot("nrecPerNsim_vs_pu", xtitle="Pileup", xmin=_minPU, xmax=_maxPU, **_common),
466  Plot("nrecPerNsimPt", xtitle="p_{T} (GeV)", xlog=True, **_common),
467  Plot("nrecPerNsim", xtitle="#eta", **_common)
468 ], legendDy=_legendDy_2rows)
469 _extHitsLayers = PlotGroup("hitsLayers", [
470  Plot("PXLhits_vs_eta", xtitle="#eta", ytitle="<pixel hits>"),
471  Plot("PXLlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<pixel layers>"),
472  Plot("STRIPhits_vs_eta", xtitle="#eta", ytitle="<strip hits>"),
473  Plot("STRIPlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<strip layers>"),
474 ], legendDy=_legendDy_2rows)
475 
476 
477 ## Extended set of plots also for simulation
478 _extDistSimPtEtaPhi = PlotGroup("distsimPtEtaPhi",
479  _makeDistSimPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
480  _makeDistSimPlots("eta", "#eta") +
481  _makeDistSimPlots("phi", "#phi"),
482  ncols=2)
483 _extDistSimDxyDzBS = PlotGroup("distsimDxyDzBS",
484  _makeDistSimPlots("dxy" , "dxy (cm)") +
485  _makeDistSimPlots("dz" , "dz (cm)"),
486  ncols=2, legendDy=_legendDy_2rows)
487 _extDistSimDxyDzPV = PlotGroup("distsimDxyDzPV",
488  _makeDistSimPlots("dxypv" , "dxy(PV) (cm)") +
489  _makeDistSimPlots("dxypv_zoomed", "dxy(PV) (cm)") +
490  _makeDistSimPlots("dzpv" , "dz(PV) (cm)") +
491  _makeDistSimPlots("dzpv_zoomed" , "dz(PV) (cm)"),
492  ncols=2, legendDy=_legendDy_4rows)
493 _extDistSimHitsLayers = PlotGroup("distsimHitsLayers",
494  _makeDistSimPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
495  _makeDistSimPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
496  _makeDistSimPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
497  _makeDistSimPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
498  ncols=2, legendDy=_legendDy_4rows,
499 )
500 _extDistSimPos = PlotGroup("distsimPos",
501  _makeDistSimPlots("vertpos", "vert r (cm)", common=dict(xlog=True)) +
502  _makeDistSimPlots("zpos" , "vert z (cm)") +
503  _makeDistSimPlots("simpvz" , "Sim. PV z (cm)", common=dict(xmin=_minZ, xmax=_maxZ)),
504  ncols=3,
505 )
506 _extDistSimDeltaR = PlotGroup("distsimDeltaR",
507  _makeDistSimPlots("dr" , "min #DeltaR", common=dict(xlog=True)) +
508  _makeDistSimPlots("drj" , "#DeltaR(TP, jet)", common=dict(xlog=True)),
509  ncols=2, legendDy=_legendDy_2rows,
510 )
511 
512 ########################################
513 #
514 # Summary plots
515 #
516 ########################################
517 
518 _possibleTrackingNonIterationColls = [
519  'ak4PFJets',
520  'btvLike',
521 ]
522 _possibleTrackingColls = [
523  'initialStepPreSplitting',
524  'initialStep',
525  'highPtTripletStep', # phase1
526  'detachedQuadStep', # phase1
527  'detachedTripletStep',
528  'lowPtQuadStep', # phase1
529  'lowPtTripletStep',
530  'pixelPairStepA', # seeds
531  'pixelPairStepB', # seeds
532  'pixelPairStepC', # seeds
533  'pixelPairStep',
534  'mixedTripletStepA', # seeds
535  'mixedTripletStepB', # seeds
536  'mixedTripletStep',
537  'pixelLessStep',
538  'tobTecStepPair', # seeds
539  'tobTecStepTripl', # seeds
540  'tobTecStep',
541  'jetCoreRegionalStep',
542  'muonSeededStepInOut',
543  'muonSeededStepOutIn',
544  'duplicateMerge',
545 ] + _possibleTrackingNonIterationColls
546 _possibleTrackingCollsOld = {
547  "Zero" : "iter0",
548  "First" : "iter1",
549  "Second": "iter2",
550  "Third" : "iter3",
551  "Fourth": "iter4",
552  "Fifth" : "iter5",
553  "Sixth" : "iter6",
554  "Seventh": "iter7",
555  "Ninth" : "iter9",
556  "Tenth" : "iter10",
557 }
558 
560  ret = subfolder.replace("trackingParticleRecoAsssociation", "AssociatorByHitsRecoDenom")
561  for (old, new) in [("InitialStep", "Zero"),
562  ("HighPtTripletStep", "First"),
563  ("LowPtQuadStep", "Second"),
564  ("LowPtTripletStep", "Third"),
565  ("DetachedQuadStep", "Fourth"),
566  ("PixelPairStep", "Fifth"),
567  ("MuonSeededStepInOut", "Ninth"),
568  ("MuonSeededStepOutIn", "Tenth")]:
569  ret = ret.replace(old, new)
570  if ret == subfolder:
571  return None
572  return ret
574  for (old, new) in [("initialStep", "iter0"),
575  ("highPtTripletStep", "iter1"),
576  ("lowPtQuadStep", "iter2"),
577  ("lowPtTripletStep", "iter3"),
578  ("detachedQuadStep", "iter4"),
579  ("pixelPairStep", "iter5"),
580  ("muonSeededStepInOut", "iter9"),
581  ("muonSeededStepOutIn", "iter10")]:
582  path = path.replace(old, new)
583  return path
584 
586  return subfolder.replace("trackingParticleRecoAsssociation", "trackingParticleRecoAsssociationSignal")
588  return subfolder.replace("quickAssociatorByHits", "quickAssociatorByHitsConversion")
590  return subfolder.replace("quickAssociatorByHits", "quickAssociatorByHitsPreSplitting")
591 
592 # Additional "quality" flags than highPurity. In a separate list to
593 # allow customization.
594 _additionalTrackQualities = [
595  "Pt09",
596  "ByOriginalAlgo",
597  "ByAlgoMask"
598 ]
600  if "Hp" in collName:
601  quality = "highPurity"
602  else:
603  quality = ""
604  collNameNoQuality = collName.replace("Hp", "")
605  for qual in _additionalTrackQualities:
606  if qual in collName:
607  quality += qual
608  collNameNoQuality = collNameNoQuality.replace(qual, "")
609 
610  collNameNoQuality = collNameNoQuality.replace("Tracks", "", 1) # make summary naming consistent with iteration folders
611  collNameLow = collNameNoQuality.lower().replace("frompv2", "").replace("frompv", "").replace("frompvalltp", "").replace("alltp", "")
612 
613  if collNameLow.find("seed") == 0:
614  collNameLow = collNameLow[4:]
615  if collNameLow == "initialstepseedspresplitting":
616  collNameLow = "initialsteppresplittingseeds"
617  elif collNameLow == "muonseededseedsinout":
618  collNameLow = "muonseededstepinoutseeds"
619  elif collNameLow == "muonseededseedsoutin":
620  collNameLow = "muonseededstepoutinseeds"
621 
622  i_seeds = collNameLow.index("seeds")
623  quality = collNameLow[i_seeds:]+quality
624 
625  collNameLow = collNameLow[:i_seeds]
626 
627  algo = None
628  prefixes = ["cutsreco", "cutsrecofrompv", "cutsrecofrompv2", "cutsrecofrompvalltp"]
629  if collNameLow in ["general", "generalfrompv"]+prefixes:
630  algo = "ootb"
631  else:
632  def testColl(coll):
633  for pfx in prefixes:
634  if coll == collNameLow.replace(pfx, ""):
635  return True
636  return False
637 
638  for coll in _possibleTrackingColls:
639  if testColl(coll.lower()):
640  algo = coll
641  break
642  # next try "old style"
643  if algo is None:
644  for coll, name in six.iteritems(_possibleTrackingCollsOld):
645  if testColl(coll.lower()):
646  algo = name
647  break
648 
649  # fallback
650  if algo is None:
651  algo = collNameNoQuality
652 
653  # fix for track collection naming convention
654  if algo == "muonSeededInOut":
655  algo = "muonSeededStepInOut"
656  if algo == "muonSeededOutIn":
657  algo = "muonSeededStepOutIn"
658 
659  return (algo, quality)
660 
661 def _collhelper(name):
662  return (name, [name])
663 _collLabelMap = collections.OrderedDict(map(_collhelper, ["generalTracks"]+_possibleTrackingColls))
664 _collLabelMapHp = collections.OrderedDict(map(_collhelper, ["generalTracks"]+[n for n in _possibleTrackingColls if "Step" in n]))
665 def _summaryBinRename(binLabel, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds):
666  (algo, quality) = _mapCollectionToAlgoQuality(binLabel)
667  if algo == "ootb":
668  algo = "generalTracks"
669  ret = None
670 
671  if byOriginalAlgo:
672  if algo != "generalTracks" and "ByOriginalAlgo" not in quality: # keep generalTracks bin as well
673  return None
674  quality = quality.replace("ByOriginalAlgo", "")
675  if byAlgoMask:
676  if algo != "generalTracks" and "ByAlgoMask" not in quality: # keep generalTracks bin as well
677  return None
678  quality = quality.replace("ByAlgoMask", "")
679  if ptCut:
680  if "Pt09" not in quality:
681  return None
682  quality = quality.replace("Pt09", "")
683 
684  if highPurity:
685  if quality == "highPurity":
686  ret = algo
687  elif seeds:
688  i_seeds = quality.find("seeds")
689  if i_seeds == 0:
690  ret = algo
691  seedSubColl = quality[i_seeds+5:]
692  if seedSubColl != "":
693  ret += seedSubColl[0].upper() + seedSubColl[1:]
694  else:
695  if quality == "":
696  ret = algo
697 
698  return ret
699 
700 def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False, midfix=""):
701  _common = {"drawStyle": "EP", "xbinlabelsize": 10, "xbinlabeloption": "d"}
702  _commonN = dict(ylog=True, ymin=_minMaxN, ymax=_minMaxN,
703  normalizeToNumberOfEvents=True,
704  )
705  _commonN.update(_common)
706  _commonAB = dict(mapping=mapping,
707  renameBin=lambda bl: _summaryBinRename(bl, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds),
708  ignoreMissingBins=True,
709  originalOrder=True,
710  )
711  if byOriginalAlgo or byAlgoMask:
712  _commonAB["minExistingBins"] = 2
713  prefix = "summary"+midfix
714 
715  h_eff = "effic_vs_coll"
716  h_fakerate = "fakerate_vs_coll"
717  h_duplicaterate = "duplicatesRate_coll"
718  h_pileuprate = "pileuprate_coll"
719 
720  h_reco = "num_reco_coll"
721  h_true = "num_assoc(recoToSim)_coll"
722  h_fake = Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll")
723  h_duplicate = "num_duplicate_coll"
724  h_pileup = "num_pileup_coll"
725  if mapping is not None:
726  h_eff = AggregateBins("efficiency", h_eff, **_commonAB)
727  h_fakerate = AggregateBins("fakerate", h_fakerate, **_commonAB)
728  h_duplicaterate = AggregateBins("duplicatesRate", h_duplicaterate, **_commonAB)
729  h_pileuprate = AggregateBins("pileuprate", h_pileuprate, **_commonAB)
730 
731  h_reco = AggregateBins("num_reco_coll", h_reco, **_commonAB)
732  h_true = AggregateBins("num_true_coll", h_true, **_commonAB)
733  h_fake = AggregateBins("num_fake_coll", h_fake, **_commonAB)
734  h_duplicate = AggregateBins("num_duplicate_coll", h_duplicate, **_commonAB)
735  h_pileup = AggregateBins("num_pileup_coll", h_pileup, **_commonAB)
736 
737  summary = PlotGroup(prefix, [
738  Plot(h_eff, title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
739  Plot(h_fakerate, title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
740  #
741  Plot(h_duplicaterate, title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
742  Plot(h_pileuprate, title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
743  ],
744  legendDy=_legendDy_2rows
745  )
746  summaryN = PlotGroup(prefix+"_ntracks", [
747  # FIXME
748  #Plot(h_reco, ytitle="Tracks/event", title="Number of tracks/event vs collection", **_commonN),
749  #Plot(h_true, ytitle="True tracks/event", title="Number of true tracks/event vs collection", **_commonN),
750  #Plot(h_fake, ytitle="Fake tracks/event", title="Number of fake tracks/event vs collection", **_commonN),
751  #Plot(h_duplicate, ytitle="Duplicate tracks/event", title="Number of duplicate tracks/event vs collection", **_commonN),
752  #Plot(h_pileup, ytitle="Pileup tracks/event", title="Number of pileup tracks/event vs collection", **_commonN),
753  Plot(h_reco, ytitle="Tracks", title="Number of tracks vs collection", **_commonN),
754  Plot(h_true, ytitle="True tracks", title="Number of true tracks vs collection", **_commonN),
755  Plot(h_fake, ytitle="Fake tracks", title="Number of fake tracks vs collection", **_commonN),
756  Plot(h_duplicate, ytitle="Duplicate tracks", title="Number of duplicate tracks vs collection", **_commonN),
757  Plot(h_pileup, ytitle="Pileup tracks", title="Number of pileup tracks vs collection", **_commonN),
758  ])
759 
760  return (summary, summaryN)
761 
762 (_summaryRaw, _summaryRawN) = _constructSummary(midfix="Raw")
763 (_summary, _summaryN) = _constructSummary(_collLabelMap)
764 (_summaryHp, _summaryNHp) = _constructSummary(_collLabelMapHp, highPurity=True)
765 (_summaryByOriginalAlgo, _summaryByOriginalAlgoN) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo")
766 (_summaryByOriginalAlgoHp, _summaryByOriginalAlgoNHp) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo", highPurity=True)
767 (_summaryByAlgoMask, _summaryByAlgoMaskN) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask")
768 (_summaryByAlgoMaskHp, _summaryByAlgoMaskNHp) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask", highPurity=True)
769 (_summaryPt09, _summaryPt09N) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09")
770 (_summaryPt09Hp, _summaryPt09NHp) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09", highPurity=True)
771 (_summarySeeds, _summarySeedsN) = _constructSummary(_collLabelMapHp, seeds=True)
772 
773 ########################################
774 #
775 # PackedCandidate plots
776 #
777 ########################################
778 
779 _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]}
780 _commonStatus = {}
781 _commonStatus.update(_common)
782 _commonStatus.update({"xbinlabelsize": 10, "xbinlabeloption": "d", "drawStyle": "hist", "adjustMarginRight": 0.08})
783 _commonLabelSize = {}
784 _commonLabelSize.update(_common)
785 _commonLabelSize.update({"xlabelsize": 17})
786 
787 _packedCandidateFlow = PlotGroup("flow", [
788  Plot("selectionFlow", xbinlabelsize=10, xbinlabeloption="d", adjustMarginRight=0.1, drawStyle="hist", ylog=True, ymin=[0.9, 9, 9e1, 9e2, 9e3, 9e4, 9e5, 9e6, 9e7]),
789  Plot("diffCharge", xtitle="Charge", **_common),
790  Plot("diffIsHighPurity", xtitle="High purity status", **_common),
791  Plot("diffNdof", xtitle="ndof", **_common),
792  Plot("diffNormalizedChi2", xtitle="#chi^{2}/ndof", **_common),
793 ])
794 
795 _packedCandidateHitsHitPattern = PlotGroup("hitsHitPattern", [
796  Plot("diffHitPatternNumberOfValidHits", xtitle="Valid hits (via HitPattern)", **_common),
797  Plot("diffHitPatternNumberOfValidPixelHits", xtitle="Valid pixel hits (via HitPattern)", **_common),
798  Plot("diffHitPatternHasValidHitInFirstPixelBarrel", xtitle="Has valid hit in BPix1 layer (via HitPattern)", **_common),
799  Plot("diffHitPatternNumberOfLostPixelHits", xtitle="Lost pixel hits (via HitPattern)", **_common),
800 ],
801  legendDy=_legendDy_2rows
802 )
803 _packedCandidateHits = PlotGroup("hits", [
804  Plot("diffNumberOfHits", xtitle="Hits", **_common),
805  Plot("diffNumberOfPixelHits", xtitle="Pixel hits", **_common),
806  Plot("diffLostInnerHits", xtitle="Lost inner hits", **_common),
807  Plot("numberHitsOverMax", xtitle="Number of overflown hits", **_common),
808  Plot("numberPixelHitsOverMax", xtitle="Number of overflown pixel hits", **_common),
809  Plot("numberStripHitsOverMax", xtitle="Number of overflown strip hits", **_common),
810 ],
811  ncols=3, legendDy=_legendDy_2rows_3cols
812 )
813 
814 _packedCandidateLayers = PlotGroup("layers", [
815  PlotEmpty(),
816  Plot("diffNumberOfPixelLayers", xtitle="Pixel layers", **_common),
817  Plot("diffNumberOfStripLayers", xtitle="Strip layers", **_common),
818  #
819  Plot("diffHitPatternTrackerLayersWithMeasurement", xtitle="Layers (via HitPattern)", **_common),
820  Plot("diffHitPatternPixelLayersWithMeasurement", xtitle="Pixel layers (via HitPattern)", **_common),
821  Plot("diffHitPatternStripLayersWithMeasurement", xtitle="Strip layers (via HitPattern)", **_common),
822  #
823  Plot("numberLayersOverMax", xtitle="Number of overflown layers", **_common),
824  Plot("numberPixelLayersOverMax", xtitle="Number of overflown pixel layers", **_common),
825  Plot("numberStripLayersOverMax", xtitle="Number of overflown strip layers", **_common),
826 ],
827  ncols=3
828 )
829 
830 
831 _packedCandidateImpactParameter1 = PlotGroup("impactParameter1", [
832  Plot("diffDxyAssocPV", xtitle="dxy(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
833  Plot("diffDxyAssocPVStatus", **_commonStatus),
834  Plot("diffDxyAssocPVUnderOverFlowSign", xtitle="dxy(assocPV)", **_common),
835  Plot("diffDzAssocPV", xtitle="dz(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
836  Plot("diffDzAssocPVStatus", **_commonStatus),
837  Plot("diffDzAssocPVUnderOverFlowSign", xtitle="dz(assocPV)", **_common),
838  Plot("diffDxyError", xtitle="dxyError()", adjustMarginRight=0.02, **_commonLabelSize),
839  Plot("diffDszError", xtitle="dszError()", adjustMarginRight=0.02, **_commonLabelSize),
840  Plot("diffDzError", xtitle="dzError()", adjustMarginRight=0.02, **_commonLabelSize),
841 
842 ],
843  ncols=3
844 )
845 
846 _packedCandidateImpactParameter2 = PlotGroup("impactParameter2", [
847  Plot("diffDxyPV", xtitle="dxy(PV) via PC", **_commonLabelSize),
848  Plot("diffDzPV", xtitle="dz(PV) via PC", **_commonLabelSize),
849  Plot("diffTrackDxyAssocPV", xtitle="dxy(PV) via PC::bestTrack()", **_commonLabelSize),
850  Plot("diffTrackDzAssocPV", xtitle="dz(PV) via PC::bestTrack()", **_commonLabelSize),
851  Plot("diffTrackDxyError", xtitle="dxyError() via PC::bestTrack()", adjustMarginRight=0.02, **_commonLabelSize),
852  Plot("diffTrackDzError", xtitle="dzError() via PC::bestTrack()", **_commonLabelSize),
853 ])
854 
855 _packedCandidateCovarianceMatrix1 = PlotGroup("covarianceMatrix1", [
856  Plot("diffCovQoverpQoverp", xtitle="cov(qoverp, qoverp)", **_commonLabelSize),
857  Plot("diffCovQoverpQoverpStatus", **_commonStatus),
858  Plot("diffCovQoverpQoverpUnderOverFlowSign", xtitle="cov(qoverp, qoverp)", **_common),
859  Plot("diffCovLambdaLambda", xtitle="cov(lambda, lambda)", **_commonLabelSize),
860  Plot("diffCovLambdaLambdaStatus", **_commonStatus),
861  Plot("diffCovLambdaLambdaUnderOverFlowSign", xtitle="cov(lambda, lambda)", **_common),
862  Plot("diffCovLambdaDsz", xtitle="cov(lambda, dsz)", **_commonLabelSize),
863  Plot("diffCovLambdaDszStatus", **_commonStatus),
864  Plot("diffCovLambdaDszUnderOverFlowSign", xtitle="cov(lambda, dsz)", **_common),
865  Plot("diffCovPhiPhi", xtitle="cov(phi, phi)", **_commonLabelSize),
866  Plot("diffCovPhiPhiStatus", **_commonStatus),
867  Plot("diffCovPhiPhiUnderOverFlowSign", xtitle="cov(phi, phi)", **_common),
868 ],
869  ncols=3, legendDy=_legendDy_4rows
870 )
871 _packedCandidateCovarianceMatrix2 = PlotGroup("covarianceMatrix2", [
872  Plot("diffCovPhiDxy", xtitle="cov(phi, dxy)", **_commonLabelSize),
873  Plot("diffCovPhiDxyStatus", **_commonStatus),
874  Plot("diffCovPhiDxyUnderOverFlowSign", xtitle="cov(phi, dxy)", **_common),
875  Plot("diffCovDxyDxy", xtitle="cov(dxy, dxy)", adjustMarginRight=0.02, **_commonLabelSize),
876  Plot("diffCovDxyDxyStatus", **_commonStatus),
877  Plot("diffCovDxyDxyUnderOverFlowSign", xtitle="cov(dxy, dxy)", **_common),
878  Plot("diffCovDxyDsz", xtitle="cov(dxy, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
879  Plot("diffCovDxyDszStatus", **_commonStatus),
880  Plot("diffCovDxyDszUnderOverFlowSign", xtitle="cov(dxy, dsz)", **_common),
881  Plot("diffCovDszDsz", xtitle="cov(dsz, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
882  Plot("diffCovDszDszStatus", **_commonStatus),
883  Plot("diffCovDszDszUnderOverFlowSign", xtitle="cov(dsz, dsz)", **_common),
884 ],
885  ncols=3, legendDy=_legendDy_4rows
886 )
887 
888 _common["xlabelsize"] = 16
889 _packedCandidateVertex = PlotGroup("vertex", [
890  Plot("diffVx", xtitle="Reference point x", **_common),
891  Plot("diffVy", xtitle="Reference point y", **_common),
892  Plot("diffVz", xtitle="Reference point z", **_common),
893 ],
894  legendDy=_legendDy_2rows
895 )
896 
897 _common["adjustMarginRight"] = 0.05
898 _packedCandidateKinematics = PlotGroup("kinematics", [
899  Plot("diffPt", xtitle="p_{T}", **_common),
900  Plot("diffPtError", xtitle="p_{T} error", **_common),
901  Plot("diffEta", xtitle="#eta", **_common),
902  Plot("diffEtaError", xtitle="#eta error", **_common),
903  Plot("diffPhi", xtitle="#phi", **_common),
904 ])
905 
907  def __init__(self, *args, **kwargs):
908  self._fallbackRefFiles = kwargs.pop("fallbackRefFiles", [])
909  PlotFolder.__init__(self, *args, **kwargs)
910 
911  def translateSubFolder(self, dqmSubFolderName):
912  spl = dqmSubFolderName.split("_")
913  if len(spl) != 2:
914  return None
915  collName = spl[0]
916  return _mapCollectionToAlgoQuality(collName)
917 
918  def iterSelectionName(self, plotFolderName, translatedDqmSubFolder):
919  (algoOrig, quality) = translatedDqmSubFolder
920 
921  for fallback in [lambda n: n]+self._fallbackRefFiles:
922  algo = fallback(algoOrig)
923 
924  ret = ""
925  if plotFolderName != "":
926  ret += "_"+plotFolderName
927  if quality != "":
928  ret += "_"+quality
929  if not (algo == "ootb" and quality != ""):
930  ret += "_"+algo
931  yield ret
932 
933  def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder):
934  """Return True if this subfolder should be processed
935 
936  Arguments:
937  limitOnlyTo -- Function '(algo, quality) -> bool'
938  translatedDqmSubFolder -- Return value of translateSubFolder
939  """
940  (algo, quality) = translatedDqmSubFolder
941  return limitOnlyTo(algo, quality)
942 
943  # track-specific hack
944  def isAlgoIterative(self, algo):
945  return algo not in _possibleTrackingNonIterationColls
946 
948  class GeneralTracks: pass
949  class GeneralTracksPt09: pass
950  class HighPurity: pass
951  class HighPurityPt09: pass
952  class BTVLike: pass
953  class AK4PFJets: pass
954  class Pixel: pass
955 
956  def __init__(self, section, collection=GeneralTracks):
957  self._collection = collection
959  self._page = "summary"
960  self._section = section
961 
962  def getPurpose(self):
963  return self._purpose
964 
965  def getPage(self):
966  return self._page
967 
968  def getSection(self, dqmSubFolder):
969  return self._section
970 
971  def create(self, tdirectory):
972  def _getAlgoQuality(data, algo, quality):
973  for label, value in six.iteritems(data):
974  (a, q) = _mapCollectionToAlgoQuality(label)
975  if a == algo and q == quality:
976  return value[0] # value is (value, uncertainty) tuple
977  return None
978  def _getN(hname):
979  h = tdirectory.Get(hname)
980  if not h:
981  return None
984  return _getAlgoQuality(data, "ootb", "")
986  return _getAlgoQuality(data, "ootb", "Pt09")
988  return _getAlgoQuality(data, "ootb", "highPurity")
990  return _getAlgoQuality(data, "ootb", "highPurityPt09")
992  return _getAlgoQuality(data, "btvLike", "")
994  return _getAlgoQuality(data, "ak4PFJets", "")
996  return _getAlgoQuality(data, "pixel", "")
997  else:
998  raise Exception("Collection not recognized, %s" % str(self._collection))
999  def _formatOrNone(num, func):
1000  if num is None:
1001  return None
1002  return func(num)
1003 
1004  n_tps = _formatOrNone(_getN("num_simul_coll"), int)
1005  n_m_tps = _formatOrNone(_getN("num_assoc(simToReco)_coll"), int)
1006 
1007  n_tracks = _formatOrNone(_getN("num_reco_coll"), int)
1008  n_true = _formatOrNone(_getN("num_assoc(recoToSim)_coll"), int)
1009  if n_tracks is not None and n_true is not None:
1010  n_fake = n_tracks-n_true
1011  else:
1012  n_fake = None
1013  n_pileup = _formatOrNone(_getN("num_pileup_coll"), int)
1014  n_duplicate = _formatOrNone(_getN("num_duplicate_coll"), int)
1015 
1016  eff = _formatOrNone(_getN("effic_vs_coll"), lambda n: "%.4f" % n)
1017  eff_nopt = _formatOrNone(_getN("effic_vs_coll_allPt"), lambda n: "%.4f" % n)
1018  fake = _formatOrNone(_getN("fakerate_vs_coll"), lambda n: "%.4f" % n)
1019  duplicate = _formatOrNone(_getN("duplicatesRate_coll"), lambda n: "%.4f" % n)
1020 
1021  ret = [eff, n_tps, n_m_tps,
1022  eff_nopt, fake, duplicate,
1023  n_tracks, n_true, n_fake, n_pileup, n_duplicate]
1024  if ret.count(None) == len(ret):
1025  return None
1026  return ret
1027 
1028  def headers(self):
1029  return [
1030  "Efficiency",
1031  "Number of TrackingParticles (after cuts)",
1032  "Number of matched TrackingParticles",
1033  "Efficiency (w/o pT cut)",
1034  "Fake rate",
1035  "Duplicate rate",
1036  "Number of tracks",
1037  "Number of true tracks",
1038  "Number of fake tracks",
1039  "Number of pileup tracks",
1040  "Number of duplicate tracks"
1041  ]
1042 
1043 # Provide a "PlotGroup" interface, but provide a html page
1045  def __init__(self, fileName, plots, titles, isRate, **kwargs):
1046  self._plots = plots
1047  self._titles = titles
1048  self._fileName = fileName
1049  self._format = "%.4g" if isRate else "%d"
1050 
1051  if len(plots) != len(titles):
1052  raise Exception("Number of plots (%d) has to be the same as number of titles (%d)" % (len(plots), len(titles)))
1053 
1054  def _set(attr, default):
1055  setattr(self, "_"+attr, kwargs.get(attr, default))
1056 
1057  _set("onlyForPileup", False)
1058 
1059  def onlyForPileup(self):
1060  """Return True if the PlotGroup is intended only for pileup samples"""
1061  return self._onlyForPileup
1062 
1063  def create(self, tdirectoryNEvents, requireAllHistograms=False):
1064  # [plot][histo]
1065  for plot in self._plots:
1066  plot.create(tdirectoryNEvents, requireAllHistograms)
1067 
1068  def draw(self, legendLabels, prefix=None, directory="", *args, **kwargs):
1069  # Do not make the table if it would be empty
1070  onlyEmptyPlots = True
1071  for plot in self._plots:
1072  if not plot.isEmpty():
1073  onlyEmptyPlots = False
1074  break
1075  if onlyEmptyPlots:
1076  return []
1077 
1078  haveShortLabels = False
1079  legendLabels = legendLabels[:]
1080  if max(map(len, legendLabels)) > 20:
1081  haveShortLabels = True
1082  labels_short = [str(chr(ord('A')+i)) for i in range(len(legendLabels))]
1083  for i, ls in enumerate(labels_short):
1084  legendLabels[i] = "%s: %s" % (ls, legendLabels[i])
1085  else:
1086  labels_short = legendLabels
1087 
1088  content = [
1089  '<html>',
1090  ' <body>',
1091  ' <table border="1">',
1092  ' <tr>',
1093  ]
1094 
1095 
1096  histos_linear = []
1097  histos_index = []
1098  labels = []
1099  for plot, title in zip(self._plots, self._titles):
1100  h_tmp = []
1101  l_tmp = []
1102  for h, l in zip(plot._histograms, labels_short):
1103  if h is not None:
1104  h_tmp.append(len(histos_linear))
1105  histos_linear.append(h)
1106  l_tmp.append(l)
1107 
1108  if len(h_tmp) > 0:
1109  histos_index.append(h_tmp)
1110  labels.append(l_tmp)
1111  content.extend([
1112  ' <td></td>',
1113  ' <td colspan="%d">%s</td>' % (len(h_tmp), title),
1114  ])
1115 
1116  if len(histos_linear) == 0:
1117  return []
1118 
1119  content.extend([
1120  ' </tr>',
1121  ' <tr>',
1122  ])
1123 
1124  xbinlabels = plotting._mergeBinLabelsX(histos_linear)
1125  histos_linear = plotting._th1IncludeOnlyBins(histos_linear, xbinlabels)
1126  if len(histos_linear) == 0:
1127  return []
1128  (histos_linear_new, xbinlabels) = plotting._th1RemoveEmptyBins(histos_linear, xbinlabels)
1129  # in practice either all histograms are returned, or none, but let's add a check anyway
1130  if len(histos_linear_new) > 0 and len(histos_linear_new) != len(histos_linear):
1131  raise Exception("This should never happen. len(histos_linear_new) %d != len(histos_linear) %d" % (len(histos_linear_new), len(histos_linear)))
1132  histos_linear = histos_linear_new
1133  if len(histos_linear) == 0:
1134  return []
1135 
1136  data = [ [h.GetBinContent(i) for i in range(1, h.GetNbinsX()+1)] for h in histos_linear]
1137  table = html.Table(["dummy"]*len(histos_linear), xbinlabels, data, None, None, None)
1138  data = table.tableAsRowColumn()
1139 
1140  for labs in labels:
1141  content.append(' <td></td>')
1142  content.extend([' <td>%s</td>' % lab for lab in labs])
1143  content.extend([
1144  ' </tr>',
1145  ])
1146 
1147  for irow, row in enumerate(data):
1148  content.extend([
1149  ' <tr>',
1150  ' <td>%s</td>' % table.rowHeaders()[irow]
1151  ])
1152 
1153  for hindices in histos_index:
1154  for hindex in hindices:
1155  item = row[hindex]
1156  formatted = self._format%item if item is not None else ""
1157  content.append(' <td align="right">%s</td>' % formatted)
1158  content.append(' <td></td>')
1159  del content[-1]
1160  content.append(' </tr>')
1161 
1162  content.append(' </table>')
1163  if haveShortLabels:
1164  for lab in legendLabels:
1165  content.append(' %s<br/>' % lab)
1166 
1167  content.extend([
1168  ' </body>',
1169  '<html>'
1170  ])
1171 
1172  name = self._fileName
1173  if prefix is not None:
1174  name = prefix+name
1175  name += ".html"
1176  name = os.path.join(directory, name)
1177 
1178  with open(name, "w") as f:
1179  for line in content:
1180  f.write(line)
1181  f.write("\n")
1182  return [name]
1183 
1184 _dupandfakeSeedingTable = TrackingSeedingLayerTable("dupandfakeSeeding", [p.clone() for p in _dupandfakeSeedingPlots],
1185  ["Fake rate", "Duplicate rate", "Pileup rate"], isRate=True)
1186 _extDistSeedingTable = TrackingSeedingLayerTable("distSeeding", [p.clone() for p in _extDistSeedingPlots],
1187  ["All tracks", "True tracks", "Fake tracks", "Duplicate tracks"], isRate=False)
1188 
1189 def _trackingFolders(lastDirName="Track"):
1190  return [
1191  "DQMData/Run 1/Tracking/Run summary/"+lastDirName,
1192  "DQMData/Tracking/"+lastDirName,
1193  "DQMData/Run 1/RecoTrackV/Run summary/"+lastDirName,
1194  "DQMData/RecoTrackV/"+lastDirName,
1195  ]
1196 
1197 _simBasedPlots = [
1198  _effandfakePtEtaPhi,
1199  _effandfakeDxyDzBS,
1200  _effandfakeDxyDzPV,
1201  _effandfakeHitsLayers,
1202  _effandfakePos,
1203  _effandfakeDeltaRPU,
1204  _duplicateAlgo,
1205 ]
1206 _recoBasedPlots = [
1207  _dupandfakePtEtaPhi,
1208  _dupandfakeDxyDzBS,
1209  _dupandfakeDxyDzPV,
1210  _dupandfakeHitsLayers,
1211  _dupandfakePos,
1212  _dupandfakeDeltaRPU,
1213  _dupandfakeChi2Seeding,
1214  _dupandfakeSeedingTable,
1215  _pvassociation1,
1216  _pvassociation2,
1217  _pvassociation3,
1218  _dedx,
1219 # _chargemisid,
1220  _hitsAndPt,
1221  _pulls,
1222  _resolutionsEta,
1223  _resolutionsPt,
1224  _tuning,
1225 ]
1226 _seedingBuildingPlots = _simBasedPlots + [
1227  _dupandfakePtEtaPhi,
1228  _dupandfakeDxyDzBS,
1229  _dupandfakeDxyDzPV,
1230  _dupandfakeHitsLayers,
1231  _dupandfakePos,
1232  _dupandfakeDeltaRPU,
1233  _dupandfakeChi2Seeding,
1234  _dupandfakeSeedingTable,
1235  _hitsAndPt,
1236 ] + _makeMVAPlots(1) \
1237  + _makeMVAPlots(2) \
1238  + _makeMVAPlots(2, hp=True) \
1239  + _makeMVAPlots(3) \
1240  + _makeMVAPlots(3, hp=True)
1241 # add more if needed
1242 _buildingExtendedPlots = [
1243  _pulls,
1244  _resolutionsEta,
1245  _resolutionsPt,
1246  _tuning,
1247 ]
1248 _extendedPlots = [
1249  _extDistPtEtaPhi,
1250  _extDistDxyDzBS,
1251  _extDistDxyDzPV,
1252  _extDistHitsLayers,
1253  _extDistPos,
1254  _extDistDeltaR,
1255  _extDistChi2Seeding,
1256  _extDistSeedingTable,
1257  _extResidualEta,
1258  _extResidualPt,
1259  _extNrecVsNsim,
1260  _extHitsLayers,
1261  _extDistSimPtEtaPhi,
1262  _extDistSimDxyDzBS,
1263  _extDistSimDxyDzPV,
1264  _extDistSimHitsLayers,
1265  _extDistSimPos,
1266  _extDistSimDeltaR,
1267 ]
1268 _summaryPlots = [
1269  _summary,
1270  _summaryN,
1271  _summaryByOriginalAlgo,
1272  _summaryByOriginalAlgoN,
1273  _summaryByAlgoMask,
1274  _summaryByAlgoMaskN,
1275  _summaryPt09,
1276  _summaryPt09N,
1277 ]
1278 _summaryPlotsHp = [
1279  _summaryHp,
1280  _summaryNHp,
1281  _summaryByOriginalAlgoHp,
1282  _summaryByOriginalAlgoNHp,
1283  _summaryByAlgoMaskHp,
1284  _summaryByAlgoMaskNHp,
1285  _summaryPt09Hp,
1286  _summaryPt09NHp,
1287 ]
1288 _summaryPlotsSeeds = [
1289  _summarySeeds,
1290  _summarySeedsN,
1291 ]
1292 _packedCandidatePlots = [
1293  _packedCandidateFlow,
1294  _packedCandidateKinematics,
1295  _packedCandidateVertex,
1296  _packedCandidateImpactParameter1,
1297  _packedCandidateImpactParameter2,
1298  _packedCandidateCovarianceMatrix1,
1299  _packedCandidateCovarianceMatrix2,
1300  _packedCandidateHits,
1301  _packedCandidateHitsHitPattern,
1302  _packedCandidateLayers,
1303 ]
1304 plotter = Plotter()
1305 plotterExt = Plotter()
1306 def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, onlyForElectron=False, onlyForConversion=False, onlyForBHadron=False, seeding=False, building=False, rawSummary=False, highPuritySummary=True):
1307  folders = _trackingFolders(lastDirName)
1308  # to keep backward compatibility, this set of plots has empty name
1309  limiters = dict(onlyForPileup=onlyForPileup, onlyForElectron=onlyForElectron, onlyForConversion=onlyForConversion, onlyForBHadron=onlyForBHadron)
1310  commonForTPF = dict(purpose=PlotPurpose.TrackingIteration, fallbackRefFiles=[
1311  _trackingRefFileFallbackSLHC_Phase1PU140
1312  ], **limiters)
1313  common = dict(fallbackDqmSubFolders=[
1314  _trackingSubFoldersFallbackSLHC_Phase1PU140,
1315  _trackingSubFoldersFallbackFromPV, _trackingSubFoldersFallbackConversion,
1316  _trackingSubFoldersFallbackPreSplitting])
1317  plotter.append(name, folders, TrackingPlotFolder(*algoPlots, **commonForTPF), **common)
1318  extendedPlots = []
1319  if building:
1320  extendedPlots.extend(_buildingExtendedPlots)
1321  extendedPlots.extend(_extendedPlots)
1322  plotterExt.append(name, folders, TrackingPlotFolder(*extendedPlots, **commonForTPF), **common)
1323 
1324  summaryName = ""
1325  if name != "":
1326  summaryName += name+"_"
1327  summaryName += "summary"
1328  summaryPlots = []
1329  if rawSummary:
1330  summaryPlots.extend([_summaryRaw, _summaryRawN])
1331  summaryPlots.extend(_summaryPlots)
1332 
1333  common = dict(loopSubFolders=False, purpose=PlotPurpose.TrackingSummary, page="summary",
1334  #numberOfEventsHistogram=_trackingNumberOfEventsHistogram, # FIXME
1335  **limiters)
1336  plotter.append(summaryName, folders,
1337  PlotFolder(*summaryPlots, section=name, **common))
1338  if highPuritySummary:
1339  plotter.append(summaryName+"_highPurity", folders,
1340  PlotFolder(*_summaryPlotsHp, section=name+"_highPurity" if name != "" else "highPurity", **common),
1341  fallbackNames=[summaryName]) # backward compatibility for release validation, the HP plots used to be in the same directory with all-track plots
1342  if seeding:
1343  plotter.append(summaryName+"_seeds", folders,
1344  PlotFolder(*_summaryPlotsSeeds, section=name+"_seeds", **common))
1345 
1346  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section=name))
1347  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section=name+"Pt09", collection=TrackingSummaryTable.GeneralTracksPt09))
1348  if highPuritySummary:
1349  sectionName = name+"_highPurity" if name != "" else "highPurity"
1350  plotter.appendTable(summaryName+"_highPurity", folders, TrackingSummaryTable(section=sectionName, collection=TrackingSummaryTable.HighPurity))
1351  plotter.appendTable(summaryName+"_highPurity", folders, TrackingSummaryTable(section=sectionName+"Pt09", collection=TrackingSummaryTable.HighPurityPt09))
1352  if name == "":
1353  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="btvLike", collection=TrackingSummaryTable.BTVLike))
1354  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="ak4PFJets", collection=TrackingSummaryTable.AK4PFJets))
1355 _appendTrackingPlots("Track", "", _simBasedPlots+_recoBasedPlots)
1356 _appendTrackingPlots("TrackTPPtLess09", "tpPtLess09", _simBasedPlots)
1357 _appendTrackingPlots("TrackAllTPEffic", "allTPEffic", _simBasedPlots, onlyForPileup=True)
1358 _appendTrackingPlots("TrackFromPV", "fromPV", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1359 _appendTrackingPlots("TrackFromPVAllTP", "fromPVAllTP", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1360 _appendTrackingPlots("TrackFromPVAllTP2", "fromPVAllTP2", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1361 _appendTrackingPlots("TrackSeeding", "seeding", _seedingBuildingPlots, seeding=True)
1362 _appendTrackingPlots("TrackBuilding", "building", _seedingBuildingPlots, building=True)
1363 _appendTrackingPlots("TrackConversion", "conversion", _simBasedPlots+_recoBasedPlots, onlyForConversion=True, rawSummary=True, highPuritySummary=False)
1364 _appendTrackingPlots("TrackGsf", "gsf", _simBasedPlots+_recoBasedPlots, onlyForElectron=True, rawSummary=True, highPuritySummary=False)
1365 _appendTrackingPlots("TrackBHadron", "bhadron", _simBasedPlots+_recoBasedPlots, onlyForBHadron=True)
1366 # Pixel tracks
1367 _common = dict(purpose=PlotPurpose.Pixel, page="pixel")
1368 plotter.append("pixelTrack", _trackingFolders("PixelTrack"), TrackingPlotFolder(*(_simBasedPlots+_recoBasedPlots), **_common))
1369 plotterExt.append("pixelTrack", _trackingFolders("PixelTrack"), TrackingPlotFolder(*_extendedPlots, **_common))
1370 plotter.append("pixelTrack_summary", _trackingFolders("PixelTrack"), PlotFolder(_summaryRaw, _summaryRawN, loopSubFolders=False, purpose=PlotPurpose.TrackingSummary, page="summary", section="pixel"))
1371 plotter.appendTable("pixelTrack_summary", _trackingFolders("PixelTrack"), TrackingSummaryTable(section="pixel", collection=TrackingSummaryTable.Pixel))
1372 
1373 
1374 # MiniAOD
1375 plotter.append("packedCandidate", _trackingFolders("PackedCandidate"),
1376  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1377  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate"))
1378 plotter.append("packedCandidateLostTracks", _trackingFolders("PackedCandidate/lostTracks"),
1379  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1380  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate (lostTracks)"))
1381 
1382 # HLT
1383 _hltFolder = [
1384  "DQMData/Run 1/HLT/Run summary/Tracking/ValidationWRTtp",
1385 ]
1386 plotterHLT = Plotter()
1387 plotterHLTExt = Plotter()
1388 _common = dict(purpose=PlotPurpose.HLT, page="hlt")
1389 plotterHLT.append("hlt", _hltFolder, TrackingPlotFolder(*(_simBasedPlots+_recoBasedPlots), **_common))
1390 plotterHLTExt.append("hlt", _hltFolder, TrackingPlotFolder(*_extendedPlots, **_common))
1391 
1392 # Timing
1394  def __init__(self, name, clusterMasking=None, seeding=None, building=None, fit=None, selection=None, other=[]):
1395  self._name = name
1396 
1397  def _set(param, name, modules):
1398  if param is not None:
1399  setattr(self, name, param)
1400  else:
1401  setattr(self, name, modules)
1402 
1403  _set(clusterMasking, "_clusterMasking", [self._name+"Clusters"])
1404  # it's fine to include e.g. quadruplets here also for pair
1405  # steps, as non-existing modules are just ignored
1406  _set(seeding, "_seeding", [self._name+"SeedingLayers", self._name+"TrackingRegions", self._name+"HitDoublets", self._name+"HitTriplets", self._name+"HitQuadruplets", self._name+"Seeds"])
1407  _set(building, "_building", [self._name+"TrackCandidates"])
1408  _set(fit, "_fit", [self._name+"Tracks"])
1409  _set(selection, "_selection", [self._name])
1410  self._other = other
1411 
1412  def name(self):
1413  return self._name
1414 
1415  def all(self):
1416  return self._clusterMasking+self._seeding+self._building+self._fit+self._selection+self._other
1417 
1418  def clusterMasking(self):
1419  return self._clusterMasking
1420 
1421  def seeding(self):
1422  return self._seeding
1423 
1424  def building(self):
1425  return self._building
1426 
1427  def fit(self):
1428  return self._fit
1429 
1430  def selection(self):
1431  return self._selection
1432 
1433  def other(self):
1434  return self._other
1435 
1436  def modules(self):
1437  return [("ClusterMask", self.clusterMasking()),
1438  ("Seeding", self.seeding()),
1439  ("Building", self.building()),
1440  ("Fit", self.fit()),
1441  ("Selection", self.selection()),
1442  ("Other", self.other())]
1443 
1444 
1445 _iterations = [
1446  Iteration("initialStepPreSplitting", clusterMasking=[],
1447  seeding=["initialStepSeedLayersPreSplitting",
1448  "initialStepTrackingRegionsPreSplitting",
1449  "initialStepHitDoubletsPreSplitting",
1450  "initialStepHitTripletsPreSplitting",
1451  "initialStepHitQuadrupletsPreSplitting",
1452  "initialStepSeedsPreSplitting"],
1453  building=["initialStepTrackCandidatesPreSplitting"],
1454  fit=["initialStepTracksPreSplitting"],
1455  other=["firstStepPrimaryVerticesPreSplitting",
1456  "initialStepTrackRefsForJetsPreSplitting",
1457  "caloTowerForTrkPreSplitting",
1458  "ak4CaloJetsForTrkPreSplitting",
1459  "jetsForCoreTrackingPreSplitting",
1460  "siPixelClusters",
1461  "siPixelRecHits",
1462  "MeasurementTrackerEvent",
1463  "siPixelClusterShapeCache"]),
1464  Iteration("initialStep", clusterMasking=[],
1465  selection=["initialStepClassifier1",
1466  "initialStepClassifier2",
1467  "initialStepClassifier3",
1468  "initialStep",
1469  "initialStepSelector"],
1470  building=["initialStepTrackCandidatesMkFitInput",
1471  "initialStepTrackCandidatesMkFit",
1472  "initialStepTrackCandidates"],
1473  other=["firstStepPrimaryVerticesUnsorted",
1474  "initialStepTrackRefsForJets",
1475  "caloTowerForTrk",
1476  "ak4CaloJetsForTrk",
1477  "firstStepPrimaryVertices"]),
1478  Iteration("highPtTripletStep",
1479  selection=["highPtTripletStepClassifier1",
1480  "highPtTripletStepClassifier2",
1481  "highPtTripletStepClassifier3",
1482  "highPtTripletStep",
1483  "highPtTripletStepSelector"]),
1484  Iteration("detachedQuadStep",
1485  selection=["detachedQuadStepClassifier1",
1486  "detachedQuadStepClassifier2",
1487  "detachedQuadStep",
1488  "detachedQuadStepSelector"]),
1489  Iteration("detachedTripletStep",
1490  selection=["detachedTripletStepClassifier1",
1491  "detachedTripletStepClassifier2",
1492  "detachedTripletStep",
1493  "detachedTripletStepSelector"]),
1494  Iteration("lowPtQuadStep",
1495  selection=["lowPtQuadStepClassifier1",
1496  "lowPtQuadStepClassifier2",
1497  "lowPtQuadStep",
1498  "lowPtQuadStepSelector"]),
1499  Iteration("lowPtTripletStep",
1500  selection=["lowPtTripletStepClassifier1",
1501  "lowPtTripletStepClassifier2",
1502  "lowPtTripletStep",
1503  "lowPtTripletStepSelector"]),
1504  Iteration("pixelPairStep",
1505  seeding=["pixelPairStepSeedLayers",
1506  "pixelPairStepSeedLayersB",
1507  "pixelPairStepSeedLayersC",
1508  "pixelPairStepTrackingRegions",
1509  "pixelPairStepTrackingRegionsB",
1510  "pixelPairStepTrackingRegionsC",
1511  "pixelPairStepTrackingRegionsSeedLayersB",
1512  "pixelPairStepHitDoublets",
1513  "pixelPairStepHitDoubletsB",
1514  "pixelPairStepHitDoubletsC",
1515  "pixelPairStepSeedsA",
1516  "pixelPairStepSeedsB",
1517  "pixelPairStepSeedsC",
1518  "pixelPairStepSeeds",],
1519  selection=["pixelPairStep",
1520  "pixelPairStepSelector"]),
1521  Iteration("mixedTripletStep",
1522  seeding=["mixedTripletStepSeedLayersA",
1523  "mixedTripletStepSeedLayersB",
1524  "mixedTripletStepTrackingRegionsA",
1525  "mixedTripletStepTrackingRegionsB",
1526  "mixedTripletStepHitDoubletsA",
1527  "mixedTripletStepHitDoubletsB",
1528  "mixedTripletStepHitTripletsA",
1529  "mixedTripletStepHitTripletsB",
1530  "mixedTripletStepSeedsA",
1531  "mixedTripletStepSeedsB",
1532  "mixedTripletStepSeeds"],
1533  selection=["mixedTripletStepClassifier1",
1534  "mixedTripletStepClassifier2",
1535  "mixedTripletStep",
1536  "mixedTripletStepSelector"]),
1537  Iteration("pixelLessStep",
1538  selection=["pixelLessStepClassifier1",
1539  "pixelLessStepClassifier2",
1540  "pixelLessStep",
1541  "pixelLessStepSelector"]),
1542  Iteration("tobTecStep",
1543  seeding=["tobTecStepSeedLayersTripl",
1544  "tobTecStepSeedLayersPair",
1545  "tobTecStepTrackingRegionsTripl",
1546  "tobTecStepTrackingRegionsPair",
1547  "tobTecStepHitDoubletsTripl",
1548  "tobTecStepHitDoubletsPair",
1549  "tobTecStepHitTripletsTripl",
1550  "tobTecStepSeedsTripl",
1551  "tobTecStepSeedsPair",
1552  "tobTecStepSeeds"],
1553  selection=["tobTecStepClassifier1",
1554  "tobTecStepClassifier2",
1555  "tobTecStep",
1556  "tobTecStepSelector"]),
1557  Iteration("jetCoreRegionalStep",
1558  clusterMasking=[],
1559  other=["jetsForCoreTracking",
1560  "firstStepGoodPrimaryVertices",
1561  ]),
1562  Iteration("muonSeededSteps",
1563  clusterMasking=[],
1564  seeding=["muonSeededSeedsInOut",
1565  "muonSeededSeedsOutIn"],
1566  building=["muonSeededTrackCandidatesInOut",
1567  "muonSeededTrackCandidatesOutIn"],
1568  fit=["muonSeededTracksInOut",
1569  "muonSeededTracksOutIn"],
1570  selection=["muonSeededTracksInOutClassifier",
1571  "muonSeededTracksInOutSelector",
1572  "muonSeededTracksOutIntClassifier",
1573  "muonSeededTracksOutIntSelector"],
1574 # other=["earlyMuons"]
1575  ),
1576  Iteration("duplicateMerge",
1577  clusterMasking=[], seeding=[],
1578  building=["duplicateTrackCandidates"],
1579  fit=["mergedDuplicateTracks"],
1580  selection=["duplicateTrackClassifier"]),
1581  Iteration("generalTracks",
1582  clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1583  other=["preDuplicateMergingGeneralTracks",
1584  "generalTracks"]),
1585  Iteration("ConvStep",
1586  clusterMasking=["convClusters"],
1587  seeding=["convLayerPairs",
1588  "photonConvTrajSeedFromSingleLeg"],
1589  building=["convTrackCandidates"],
1590  fit=["convStepTracks"],
1591  selection=["convStepSelector"]),
1592  Iteration("Other", clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1593  other=["trackerClusterCheckPreSplitting",
1594  "trackerClusterCheck"]),
1595 ]
1596 
1597 def _iterModuleMap(includeConvStep=True, onlyConvStep=False):
1598  iterations = _iterations
1599  if not includeConvStep:
1600  iterations = [i for i in iterations if i.name() != "ConvStep"]
1601  if onlyConvStep:
1602  iterations = [i for i in iterations if i.name() == "ConvStep"]
1603  return collections.OrderedDict([(i.name(), i.all()) for i in iterations])
1605  def getProp(prop):
1606  ret = []
1607  for i in _iterations:
1608  if i.name() == "ConvStep":
1609  continue
1610  ret.extend(getattr(i, prop)())
1611  return ret
1612 
1613  return collections.OrderedDict([
1614  ("ClusterMask", getProp("clusterMasking")),
1615  ("Seeding", getProp("seeding")),
1616  ("Building", getProp("building")),
1617  ("Fitting", getProp("fit")),
1618  ("Selection", getProp("selection")),
1619  ("Other", getProp("other"))
1620  ])
1621 
1623  def __init__(self, name, timeHisto):
1624  self._name = name
1625  self._timeHisto = timeHisto
1626  self._eventsHisto = "path time_real"
1627  self._cache = {}
1628 
1629  def __str__(self):
1630  return self._name
1631 
1632  def _create(self, tdirectory):
1633  timeTh1 = plotting._getOrCreateObject(tdirectory, self._timeHisto)
1634  if timeTh1 is None:
1635  return None
1636 
1637  eventsTh1 = plotting._getOrCreateObject(tdirectory, self._eventsHisto)
1638  if eventsTh1 is None:
1639  return None
1640  nevents = eventsTh1.GetEntries()
1641  if nevents == 0:
1642  return None
1643 
1644  ret = timeTh1.Clone(self._name)
1645  xaxis = ret.GetXaxis()
1646  for i in range(1, ret.GetNbinsX()+1):
1647  ret.SetBinContent(i, ret.GetBinContent(i)/nevents)
1648  ret.SetBinError(i, ret.GetBinError(i)/nevents)
1649  xaxis.SetBinLabel(i, xaxis.GetBinLabel(i).replace(" (unscheduled)", ""))
1650  return ret
1651 
1652  def create(self, tdirectory):
1653  path = tdirectory.GetPath()
1654  if path not in self._cache:
1655  self._cache[path] = self._create(tdirectory)
1656  return self._cache[path]
1657 
1659  def __init__(self, name, timeHisto, selectedTracks=False):
1660  self._name = name
1661  self._timeHisto = timeHisto
1662  self._selectedTracks = selectedTracks
1663 
1664  def __str__(self):
1665  return self._name
1666 
1667  def _getDirectory(self, tfile):
1668  for dirName in _trackingFolders():
1669  tdir = tfile.Get(dirName)
1670  if tdir != None:
1671  return tdir
1672  return None
1673 
1674  def create(self, tdirectory):
1675  timeTh1 = plotting._getOrCreateObject(tdirectory, self._timeHisto)
1676  if timeTh1 is None:
1677  return None
1678 
1679  # this is bit of a hack, but as long as it is needed only
1680  # here, I won't invest in better solution
1681  tfile = tdirectory.GetFile()
1682  trkDir = self._getDirectory(tfile)
1683  if trkDir is None:
1684  return None
1685 
1686  iterMap = copy.copy(_collLabelMapHp)
1687  del iterMap["generalTracks"]
1688  del iterMap["jetCoreRegionalStep"] # this is expensive per track on purpose
1689  if self._selectedTracks:
1690  renameBin = lambda bl: _summaryBinRename(bl, highPurity=True, byOriginalAlgo=False, byAlgoMask=True, ptCut=False, seeds=False)
1691  else:
1692  renameBin = lambda bl: _summaryBinRename(bl, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False)
1693  recoAB = AggregateBins("tmp", "num_reco_coll", mapping=iterMap,ignoreMissingBins=True, renameBin=renameBin)
1694  h_reco_per_iter = recoAB.create(trkDir)
1695  if h_reco_per_iter is None:
1696  return None
1697  values = {}
1698  for i in range(1, h_reco_per_iter.GetNbinsX()+1):
1699  values[h_reco_per_iter.GetXaxis().GetBinLabel(i)] = h_reco_per_iter.GetBinContent(i)
1700 
1701 
1702  result = []
1703  for i in range(1, timeTh1.GetNbinsX()+1):
1704  iterName = timeTh1.GetXaxis().GetBinLabel(i)
1705  if iterName in values:
1706  ntrk = values[iterName]
1707  result.append( (iterName,
1708  timeTh1.GetBinContent(i)/ntrk if ntrk > 0 else 0,
1709  timeTh1.GetBinError(i)/ntrk if ntrk > 0 else 0) )
1710 
1711  if len(result) == 0:
1712  return None
1713 
1714  res = ROOT.TH1F(self._name, self._name, len(result), 0, len(result))
1715  for i, (label, value, error) in enumerate(result):
1716  res.GetXaxis().SetBinLabel(i+1, label)
1717  res.SetBinContent(i+1, value)
1718  res.SetBinError(i+1, error)
1719 
1720  return res
1721 
1723  def __init__(self):
1724  self._cache = {}
1725 
1726  def _findOrder(self, f):
1727  h = f.Get(_trackingIterationOrderHistogram)
1728  if not h:
1729  return None
1730  xaxis = h.GetXaxis()
1731  def _edit(s):
1732  # remove "Tracks" from the track producer name to get the iteration name
1733  # muonSeeded iterations do not have "Step" in the producer name, so add it here
1734  return s.replace("Tracks", "").replace("muonSeeded", "muonSeededStep")
1735  return [_edit(xaxis.GetBinLabel(i)) for i in range(1, h.GetNbinsX()+1)]
1736 
1737  def __call__(self, tdirectory, labels):
1738  ret = list(range(0, len(labels)))
1739  f = tdirectory.GetFile()
1740  if not f:
1741  return ret
1742 
1743  if not f.GetName() in self._cache:
1744  r = self._findOrder(f)
1745  if r is None:
1746  return ret
1747  self._cache[f.GetName()] = r
1748  order = self._cache[f.GetName()]
1749 
1750  # O(N^2) I know, but we're talking about O(10) elements...
1751  orderIndices = []
1752  for l in order:
1753  try:
1754  orderIndices.append(labels.index(l))
1755  except ValueError:
1756  pass
1757  ret = []
1758  for i, l in enumerate(labels):
1759  if l in order:
1760  try:
1761  found = orderIndices.index(i)
1762  if found == 0:
1763  ret.append(i)
1764  else:
1765  ret.append(orderIndices[0])
1766  except ValueError:
1767  ret.append(orderIndices[0])
1768  orderIndices.pop(0)
1769  else:
1770  ret.append(i)
1771  return ret
1772 
1773 _time_per_event_cpu = TimePerEventPlot("timePerEvent", "module_time_thread_total")
1774 _time_per_event_real = TimePerEventPlot("timePerEvent", "module_time_real_total")
1775 
1777  def __init__(self):
1779  self._page = "timing"
1780  self._section = "timing"
1781 
1782  def getPurpose(self):
1783  return self._purpose
1784 
1785  def getPage(self):
1786  return self._page
1787 
1788  def getSection(self, dqmSubFolder):
1789  return self._section
1790 
1791  def _getValues(self, tdirectory, histo):
1792  h = tdirectory.Get(histo)
1793  totalReco = None
1794  if h:
1795  totalReco = "%.1f" % h.Integral()
1796 
1797  creator = AggregateBins("iteration", histo, _iterModuleMap(includeConvStep=False), ignoreMissingBins=True)
1798  h = creator.create(tdirectory)
1799  totalTracking = None
1800  if h:
1801  totalTracking = "%.1f" % h.Integral()
1802 
1803  creator = AggregateBins("iteration", histo, _iterModuleMap(onlyConvStep=True), ignoreMissingBins=True)
1804  h = creator.create(tdirectory)
1805  totalConvStep = None
1806  if h:
1807  totalConvStep = "%.1f" % h.Integral()
1808 
1809  return [
1810  totalReco,
1811  totalTracking,
1812  totalConvStep,
1813  ]
1814 
1815  def create(self, tdirectory):
1816  cpuValues = self._getValues(tdirectory, _time_per_event_cpu)
1817  realValues = self._getValues(tdirectory, _time_per_event_real)
1818 
1819  return cpuValues + realValues
1820 
1821  def headers(self):
1822  return [
1823  "Average reco CPU time / event (ms)",
1824  "Average tracking (w/o convStep) CPU time / event (ms)",
1825  "Average convStep CPU time / event (ms)",
1826  "Average reco real time / event (ms)",
1827  "Average tracking (w/o convStep) real time / event (ms)",
1828  "Average convStep real time / event (ms)",
1829  ]
1830 
1831 _common = {
1832  "drawStyle": "P",
1833  "xbinlabelsize": 10,
1834  "xbinlabeloption": "d"
1835 }
1836 
1837 _iteration_reorder = TrackingIterationOrder()
1838 _time_per_iter_cpu = AggregateBins("iteration", _time_per_event_cpu, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder)
1839 _time_per_iter_real = AggregateBins("iteration", _time_per_event_real, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder)
1840 
1841 _timing_summaryCPU = PlotGroup("summaryCPU", [
1842  Plot(_time_per_iter_cpu,
1843  ytitle="Average CPU time (ms)", title="Average CPU time / event", legendDx=-0.4, **_common),
1844  Plot(AggregateBins("iteration_fraction", _time_per_event_cpu, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder),
1845  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1846  #
1847  Plot(AggregateBins("step", _time_per_event_cpu, _stepModuleMap(), ignoreMissingBins=True),
1848  ytitle="Average CPU time (ms)", title="Average CPU time / event", **_common),
1849  Plot(AggregateBins("step_fraction", _time_per_event_cpu, _stepModuleMap(), ignoreMissingBins=True),
1850  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1851  #
1852  Plot(TimePerTrackPlot("iteration_track", _time_per_iter_cpu, selectedTracks=False),
1853  ytitle="Average CPU time / built track (ms)", title="Average CPU time / built track", **_common),
1854  Plot(TimePerTrackPlot("iteration_trackhp", _time_per_iter_cpu, selectedTracks=True),
1855  ytitle="Average CPU time / selected track (ms)", title="Average CPU time / selected HP track by algoMask", **_common),
1856  ],
1857 )
1858 _timing_summaryReal = PlotGroup("summaryReal", [
1859  Plot(_time_per_iter_real,
1860  ytitle="Average real time (ms)", title="Average real time / event", legendDx=-0.4, **_common),
1861  Plot(AggregateBins("iteration_fraction", _time_per_event_real, _iterModuleMap(), ignoreMissingBins=True, reorder=_iteration_reorder),
1862  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1863  #
1864  Plot(AggregateBins("step", _time_per_event_real, _stepModuleMap(), ignoreMissingBins=True),
1865  ytitle="Average real time (ms)", title="Average real time / event", **_common),
1866  Plot(AggregateBins("step_fraction", _time_per_event_real, _stepModuleMap(), ignoreMissingBins=True),
1867  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1868  #
1869  Plot(TimePerTrackPlot("iteration_track", _time_per_iter_real, selectedTracks=False),
1870  ytitle="Average real time / built track (ms)", title="Average real time / built track", **_common),
1871  Plot(TimePerTrackPlot("iteration_trackhp", _time_per_iter_real, selectedTracks=True),
1872  ytitle="Average real time / selected track (ms)", title="Average real time / selected HP track by algoMask", **_common),
1873  ],
1874 )
1875 
1876 _timing_iterationsCPU = PlotGroup("iterationsCPU", [
1877  Plot(AggregateBins(i.name(), _time_per_event_cpu, collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1878  ytitle="Average CPU time (ms)", title=i.name(), **_common)
1879  for i in _iterations
1880 ],
1881  ncols=4, legend=False
1882 )
1883 _timing_iterationsReal = PlotGroup("iterationsReal", [
1884  Plot(AggregateBins(i.name(), _time_per_event_real, collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1885  ytitle="Average real time (ms)", title=i.name(), **_common)
1886  for i in _iterations
1887 ],
1888  ncols=4, legend=False
1889 )
1890 
1891 # TODO: to be updated to new FastTimerService format later
1892 #_pixelTiming = PlotGroup("pixelTiming", [
1893 # Plot(AggregateBins("pixel", "reconstruction_step_module_average", {"pixelTracks": ["pixelTracks"]}), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST")
1894 #])
1895 
1896 _timeFolders = [
1897 # "DQMData/Run 1/DQM/Run summary/TimerService/process RECO paths/path reconstruction_step",
1898  "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?
1899 ]
1900 timePlotter = Plotter()
1901 timePlotter.append("timing", _timeFolders, PlotFolder(
1902  _timing_summaryCPU,
1903  _timing_iterationsCPU,
1904  _timing_summaryReal,
1905  _timing_iterationsReal,
1906  # _pixelTiming,
1907  loopSubFolders=False, purpose=PlotPurpose.Timing, page="timing"
1908 ))
1909 timePlotter.appendTable("timing", _timeFolders, TrackingTimingTable())
1910 
1911 _common = {"stat": True, "normalizeToUnitArea": True, "drawStyle": "hist"}
1912 _tplifetime = PlotGroup("tplifetime", [
1913  Plot("TPlip", xtitle="TP lip", **_common),
1914  Plot("TPtip", xtitle="TP tip", **_common),
1915 ])
1916 
1917 tpPlotter = Plotter()
1918 tpPlotter.append("tp", [
1919  "DQMData/Run 1/Tracking/Run summary/TrackingMCTruth/TrackingParticle",
1920  "DQMData/Tracking/TrackingMCTruth/TrackingParticle",
1921 ], PlotFolder(
1922  _tplifetime,
1923 ))
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)