CMS 3D CMS Logo

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