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