CMS 3D CMS Logo

trackingPlots.py
Go to the documentation of this file.
1 import copy
2 import collections
3 
4 import ROOT
5 ROOT.gROOT.SetBatch(True)
6 ROOT.PyConfig.IgnoreCommandLineOptions = True
7 
8 from plotting import Subtract, FakeDuplicate, CutEfficiency, Transform, AggregateBins, ROC, Plot, PlotGroup, PlotFolder, Plotter
9 import plotting
10 import validation
11 from html import PlotPurpose
12 
13 ########################################
14 #
15 # Per track collection plots
16 #
17 ########################################
18 
19 _maxEff = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025, 1.2, 1.5, 2]
20 _maxFake = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025]
21 
22 #_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]
23 _minMaxResol = [1e-5, 4e-5, 1e-4, 4e-4, 1e-3, 4e-3, 1e-2, 4e-2, 0.1, 0.4, 1]
24 _minMaxN = [5e-1, 5, 5e1, 5e2, 5e3, 5e4, 5e5, 5e6, 5e7, 5e8, 5e9]
25 
26 _minHits = [0, 5, 10]
27 _maxHits = [5, 10, 20, 40, 60, 80]
28 _minLayers = [0, 5, 10]
29 _maxLayers = [5, 10, 25]
30 _maxPixelLayers = 8
31 _min3DLayers = [0, 5, 10]
32 _max3DLayers = [5, 10, 20]
33 _minPU = [0, 10, 20, 50, 100, 150]
34 _maxPU = [20, 50, 65, 80, 100, 150, 200, 250]
35 _minMaxTracks = [0, 200, 500, 1000, 1500, 2000]
36 
37 _legendDy_1row = 0.46
38 _legendDy_2rows = -0.025
39 _legendDy_2rows_3cols = -0.17
40 _legendDy_4rows = 0.09
41 
42 _trackingNumberOfEventsHistogram = "DQMData/Run 1/Tracking/Run summary/Track/general_trackingParticleRecoAsssociation/tracks"
43 
44 def _makeEffFakeDupPlots(postfix, quantity, unit="", common={}, effopts={}, fakeopts={}):
45  p = postfix
46  q = quantity
47  xq = q
48  if unit != "":
49  xq += " (" + unit + ")"
50 
51  effargs = dict(xtitle="TP "+xq , ytitle="efficiency vs "+q , ymax=_maxEff)
52  fakeargs = dict(xtitle="track "+xq, ytitle="fake+duplicates rate vs "+q, ymax=_maxFake)
53  effargs.update(common)
54  fakeargs.update(common)
55  effargs.update(effopts)
56  fakeargs.update(fakeopts)
57 
58  return [
59  Plot("effic_vs_"+p, **effargs),
60  Plot(FakeDuplicate("fakeduprate_vs_"+p, assoc="num_assoc(recoToSim)_"+p, dup="num_duplicate_"+p, reco="num_reco_"+p, title="fake+duplicates vs "+q), **fakeargs)
61  ]
62 
63 def _makeFakeDupPileupPlots(postfix, quantity, unit="", xquantity="", xtitle=None, common={}):
64  p = postfix
65  q = quantity
66  if xtitle is None:
67  if xquantity != "":
68  xq = xquantity
69  else:
70  xq = q
71  if unit != "":
72  xq += " (" + unit + ")"
73  xtitle="track "+xq
74 
75  return [
76  Plot("fakerate_vs_"+p , xtitle=xtitle, ytitle="fakerate vs "+q , ymax=_maxFake, **common),
77  Plot("duplicatesRate_"+p, xtitle=xtitle, ytitle="duplicates rate vs "+q, ymax=_maxFake, **common),
78  Plot("pileuprate_"+p , xtitle=xtitle, ytitle="pileup rate vs "+q , ymax=_maxFake, **common),
79  ]
80 
81 def _makeDistPlots(postfix, quantity, common={}):
82  p = postfix
83  q = quantity
84 
85  args = dict(xtitle="track "+q, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
86  args.update(common)
87 
88  return [
89  Plot("num_reco_"+p , ytitle="tracks", **args),
90  Plot("num_assoc(recoToSim)_"+p, ytitle="true tracks", **args),
91  Plot(Subtract("num_fake_"+p, "num_reco_"+p, "num_assoc(recoToSim)_"+p), ytitle="fake tracks", **args),
92  Plot("num_duplicate_"+p , ytitle="duplicate tracks", **args),
93  ]
94 
95 def _makeDistSimPlots(postfix, quantity, common={}):
96  p = postfix
97  q = quantity
98 
99  args = dict(xtitle="TP "+q, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
100  args.update(common)
101 
102  return [
103  Plot("num_simul_"+p , ytitle="TrackingParticles", **args),
104  Plot("num_assoc(simToReco)_"+p, ytitle="Reconstructed TPs", **args),
105  ]
106 
107 def _makeMVAPlots(num, hp=False):
108  pfix = "_hp" if hp else ""
109  pfix2 = "Hp" if hp else ""
110 
111  xtitle = "MVA%d output"%num
112  xtitlecut = "Cut on MVA%d output"%num
113  args = dict(xtitle=xtitle, ylog=True, ymin=_minMaxN, ymax=_minMaxN)
114 
115  argsroc = dict(
116  xtitle="Efficiency (excl. trk eff)", ytitle="Fake rate",
117  xmax=_maxEff, ymax=_maxFake,
118  drawStyle="EP",
119  )
120  argsroc2 = dict(
121  ztitle="Cut on MVA%d"%num,
122  xtitleoffset=5, ytitleoffset=6.5, ztitleoffset=4,
123  adjustMarginRight=0.12
124  )
125  argsroc2.update(argsroc)
126  argsroc2["drawStyle"] = "pcolz"
127 
128  true_cuteff = CutEfficiency("trueeff_vs_mva%dcut%s"%(num,pfix), "num_assoc(recoToSim)_mva%dcut%s"%(num,pfix))
129  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)))
130 
131  return PlotGroup("mva%d%s"%(num,pfix2), [
132  Plot("num_assoc(recoToSim)_mva%d%s"%(num,pfix), ytitle="true tracks", **args),
133  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),
134  Plot("effic_vs_mva%dcut%s"%(num,pfix), xtitle=xtitlecut, ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
135  #
136  Plot("fakerate_vs_mva%dcut%s"%(num,pfix), xtitle=xtitlecut, ytitle="Fake rate", ymax=_maxFake),
137  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),
138  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),
139  # Same signal efficiency, background efficiency, and ROC definitions as in TMVA
140  Plot(true_cuteff, xtitle=xtitlecut, ytitle="True track selection efficiency", ymax=_maxEff),
141  Plot(fake_cuteff, xtitle=xtitlecut, ytitle="Fake track selection efficiency", ymax=_maxEff),
142  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),
143  ], ncols=3, legendDy=_legendDy_1row)
144 
145 _effandfake1 = PlotGroup("effandfake1", [
146  Plot("efficPt", title="Efficiency vs p_{T}", xtitle="TP p_{T} (GeV)", ytitle="efficiency vs p_{T}", xlog=True, ymax=_maxEff),
147  Plot(FakeDuplicate("fakeduprate_vs_pT", assoc="num_assoc(recoToSim)_pT", dup="num_duplicate_pT", reco="num_reco_pT", title="fake+duplicates vs p_{T}"),
148  xtitle="track p_{T} (GeV)", ytitle="fake+duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
149  Plot("effic", xtitle="TP #eta", ytitle="efficiency vs #eta", title="", ymax=_maxEff),
150  Plot(FakeDuplicate("fakeduprate_vs_eta", assoc="num_assoc(recoToSim)_eta", dup="num_duplicate_eta", reco="num_reco_eta", title=""),
151  xtitle="track #eta", ytitle="fake+duplicates rate vs #eta", ymax=_maxFake),
152 ] +
153  _makeEffFakeDupPlots("phi", "#phi")
154 )
155 
156 _effandfake2 = PlotGroup("effandfake2",
157  _makeEffFakeDupPlots("dxy" , "dxy" , "cm") +
158  _makeEffFakeDupPlots("dxypv", "dxy(PV)", "cm") +
159  _makeEffFakeDupPlots("dz" , "dz" , "cm") +
160  _makeEffFakeDupPlots("dzpv" , "dz(PV)" , "cm"),
161  legendDy=_legendDy_4rows
162 )
163 _effandfake3 = PlotGroup("effandfake3",
164  _makeEffFakeDupPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
165  _makeEffFakeDupPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
166  _makeEffFakeDupPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
167  _makeEffFakeDupPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
168  legendDy=_legendDy_4rows
169 )
170 _common = {"ymin": 0, "ymax": _maxEff}
171 _effandfake4 = PlotGroup("effandfake4",
172  _makeEffFakeDupPlots("vertpos", "vert r", "cm", fakeopts=dict(xtitle="track ref. point r (cm)", ytitle="fake+duplicates vs. r")) +
173  _makeEffFakeDupPlots("zpos" , "vert z", "cm", fakeopts=dict(xtitle="track ref. point z (cm)", ytitle="fake+duplicates vs. z")) +
174  _makeEffFakeDupPlots("dr" , "#DeltaR", effopts=dict(xtitle="TP min #DeltaR"), fakeopts=dict(xtitle="track min #DeltaR"), common=dict(xlog=True)) +
175  _makeEffFakeDupPlots("pu" , "PU" , common=dict(xtitle="Pileup", xmin=_minPU, xmax=_maxPU)),
176  legendDy=_legendDy_4rows
177 )
178 
179 _dupandfake1 = PlotGroup("dupandfake1", [
180  Plot("fakeratePt", xtitle="track p_{T} (GeV)", ytitle="fakerate vs p_{T}", xlog=True, ymax=_maxFake),
181  Plot("duplicatesRate_Pt", xtitle="track p_{T} (GeV)", ytitle="duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
182  Plot("pileuprate_Pt", xtitle="track p_{T} (GeV)", ytitle="pileup rate vs p_{T}", ymax=_maxFake, xlog=True),
183  Plot("fakerate", xtitle="track #eta", ytitle="fakerate vs #eta", title="", ymax=_maxFake),
184  Plot("duplicatesRate", xtitle="track #eta", ytitle="duplicates rate vs #eta", title="", ymax=_maxFake),
185  Plot("pileuprate", xtitle="track #eta", ytitle="pileup rate vs #eta", title="", ymax=_maxFake),
186 ] + _makeFakeDupPileupPlots("phi", "#phi"),
187  ncols=3
188 )
189 _dupandfake2 = PlotGroup("dupandfake2",
190  _makeFakeDupPileupPlots("dxy" , "dxy" , "cm") +
191  _makeFakeDupPileupPlots("dxypv", "dxy(PV)", "cm") +
192  _makeFakeDupPileupPlots("dz" , "dz" , "cm") +
193  _makeFakeDupPileupPlots("dzpv" , "dz(PV)" , "cm"),
194  ncols=3, legendDy=_legendDy_4rows
195 )
196 _dupandfake3 = PlotGroup("dupandfake3",
197  _makeFakeDupPileupPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
198  _makeFakeDupPileupPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
199  _makeFakeDupPileupPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
200  _makeFakeDupPileupPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
201  ncols=3, legendDy=_legendDy_4rows
202 )
203 _dupandfake4 = PlotGroup("dupandfake4",
204  _makeFakeDupPileupPlots("vertpos", "r", "cm", xquantity="ref. point r (cm)") +
205  _makeFakeDupPileupPlots("zpos" , "z", "cm", xquantity="ref. point z (cm)") +
206  _makeFakeDupPileupPlots("dr" , "#DeltaR", xquantity="min #DeltaR", common=dict(xlog=True)) +
207  _makeFakeDupPileupPlots("pu" , "PU" , xtitle="Pileup", common=dict(xmin=_minPU, xmax=_maxPU)),
208  ncols=3, legendDy=_legendDy_4rows
209 )
210 _seedingLayerSet_common = dict(removeEmptyBins=True, xbinlabelsize=8, xinlabeloption="d", adjustMarginRight=0.1)
211 _dupandfake5 = PlotGroup("dupandfake5",
212  _makeFakeDupPileupPlots("chi2", "#chi^{2}") +
213  _makeFakeDupPileupPlots("seedingLayerSet", "seeding layers", xtitle="", common=_seedingLayerSet_common),
214  ncols=3, legendDy=_legendDy_2rows_3cols
215 )
216 
217 
218 _common = {
219  "ytitle": "Fake+pileup rate",
220  "ymax": _maxFake,
221  "drawStyle": "EP",
222 }
223 _common2 = {}
224 _common2.update(_common)
225 _common2["drawStyle"] = "pcolz"
226 _common2["ztitleoffset"] = 1.5
227 _common2["xtitleoffset"] = 7
228 _common2["ytitleoffset"] = 10
229 _common2["ztitleoffset"] = 6
230 _pvassociation1 = PlotGroup("pvassociation1", [
231  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")),
232  xtitle="Efficiency vs. cut on dz(PV)", **_common),
233  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),
234  xtitle="Efficiency", ztitle="Cut on dz(PV)", **_common2),
235  #
236  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")),
237  xtitle="Efficiency vs. cut on dz(PV)/dzError", **_common),
238  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),
239  xtitle="Efficiency", ztitle="Cut on dz(PV)/dzError", **_common2),
240 
241  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")),
242  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)", **_common),
243  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),
244  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)", **_common2),
245  #
246  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")),
247  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)/dzError", **_common),
248  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),
249  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)/dzError", **_common2),
250 ], onlyForPileup=True,
251  legendDy=_legendDy_4rows
252 )
253 _pvassociation2 = PlotGroup("pvassociation2", [
254  Plot("effic_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency vs. cut on dz(PV)", ymax=_maxEff),
255  Plot("effic_vs_dzpvcut2", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
256  Plot("fakerate_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate vs. cut on dz(PV)", ymax=_maxFake),
257  Plot("pileuprate_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate vs. cut on dz(PV)", ymax=_maxFake),
258  #
259  Plot("effic_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency vs. cut on dz(PV)/dzError", ymax=_maxEff),
260  Plot("effic_vs_dzpvsigcut2", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
261  Plot("fakerate_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
262  Plot("pileuprate_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
263 ], onlyForPileup=True,
264  legendDy=_legendDy_4rows
265 )
266 _pvassociation3 = PlotGroup("pvassociation3", [
267  Plot("effic_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
268  Plot("effic_vs_dzpvcut2_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
269  Plot("fakerate_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
270  Plot("pileuprate_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
271  #
272  Plot("effic_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
273  Plot("effic_vs_dzpvsigcut2_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
274  Plot("fakerate_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
275  Plot("pileuprate_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
276 ], onlyForPileup=True,
277  legendDy=_legendDy_4rows
278 )
279 
280 
281 # These don't exist in FastSim
282 _common = {"normalizeToUnitArea": True, "stat": True, "drawStyle": "hist"}
283 _dedx = PlotGroup("dedx", [
284  Plot("h_dedx_estim1", xtitle="dE/dx, harm2", **_common),
285  Plot("h_dedx_estim2", xtitle="dE/dx, trunc40", **_common),
286  Plot("h_dedx_nom1", xtitle="dE/dx number of measurements", title="", **_common),
287  Plot("h_dedx_sat1", xtitle="dE/dx number of measurements with saturation", title="", **_common),
288  ],
289  legendDy=_legendDy_2rows
290 )
291 
292 _chargemisid = PlotGroup("chargemisid", [
293  Plot("chargeMisIdRate", xtitle="#eta", ytitle="charge mis-id rate vs #eta", ymax=0.05),
294  Plot("chargeMisIdRate_Pt", xtitle="p_{T}", ytitle="charge mis-id rate vs p_{T}", xmax=300, ymax=0.1, xlog=True),
295  Plot("chargeMisIdRate_hit", xtitle="hits", ytitle="charge mis-id rate vs hits", title=""),
296  Plot("chargeMisIdRate_phi", xtitle="#phi", ytitle="charge mis-id rate vs #phi", title="", ymax=0.01),
297  Plot("chargeMisIdRate_dxy", xtitle="dxy", ytitle="charge mis-id rate vs dxy", ymax=0.1),
298  Plot("chargeMisIdRate_dz", xtitle="dz", ytitle="charge mis-id rate vs dz", ymax=0.1)
299 ])
300 _common = {"stat": True, "normalizeToUnitArea": True, "ylog": True, "ymin": 1e-6, "drawStyle": "hist"}
301 _hitsAndPt = PlotGroup("hitsAndPt", [
302  Plot("missing_inner_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
303  Plot("missing_outer_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
304  Plot("hits_eta", xtitle="track #eta", ytitle="<hits> vs #eta", ymin=_minHits, ymax=_maxHits, statyadjust=[0,0,-0.15],
305  fallback={"name": "nhits_vs_eta", "profileX": True}),
306  Plot("hits", stat=True, xtitle="track hits", xmin=_minHits, xmax=_maxHits, ylog=True, ymin=[5e-1, 5, 5e1, 5e2, 5e3], drawStyle="hist"),
307  Plot("num_simul_pT", xtitle="TP p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common),
308  Plot("num_reco_pT", xtitle="track p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common)
309 ])
310 _tuning = PlotGroup("tuning", [
311  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),
312  Plot("chi2_prob", stat=True, normalizeToUnitArea=True, drawStyle="hist", xtitle="Prob(#chi^{2})"),
313  Plot("chi2mean", title="", xtitle="#eta", ytitle="< #chi^{2} / ndf >", ymin=[0, 0.5], ymax=[2, 2.5, 3, 5],
314  fallback={"name": "chi2_vs_eta", "profileX": True}),
315  Plot("ptres_vs_eta_Mean", scale=100, title="", xtitle="TP #eta (PCA to beamline)", ytitle="< #delta p_{T} / p_{T} > [%]", ymin=-1.5, ymax=1.5)
316 ])
317 _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}
318 _pulls = PlotGroup("pulls", [
319  Plot("pullPt", **_common),
320  Plot("pullQoverp", **_common),
321  Plot("pullPhi", **_common),
322  Plot("pullTheta", **_common),
323  Plot("pullDxy", **_common),
324  Plot("pullDz", **_common),
325 ],
326  legendDx=0.1, legendDw=-0.1, legendDh=-0.015
327 )
328 _common = {"title": "", "ylog": True, "xtitle": "TP #eta (PCA to beamline)", "ymin": _minMaxResol, "ymax": _minMaxResol}
329 _resolutionsEta = PlotGroup("resolutionsEta", [
330  Plot("phires_vs_eta_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
331  Plot("cotThetares_vs_eta_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
332  Plot("dxyres_vs_eta_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
333  Plot("dzres_vs_eta_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
334  Plot("ptres_vs_eta_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
335 ])
336 _common = {"title": "", "ylog": True, "xlog": True, "xtitle": "TP p_{T} (PCA to beamline)", "xmin": 0.1, "xmax": 1000, "ymin": _minMaxResol, "ymax": _minMaxResol}
337 _resolutionsPt = PlotGroup("resolutionsPt", [
338  Plot("phires_vs_pt_Sigma", ytitle="#sigma(#delta #phi) (rad)", **_common),
339  Plot("cotThetares_vs_pt_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
340  Plot("dxyres_vs_pt_Sigma", ytitle="#sigma(#delta d_{xy}) (cm)", **_common),
341  Plot("dzres_vs_pt_Sigma", ytitle="#sigma(#delta d_{z}) (cm)", **_common),
342  Plot("ptres_vs_pt_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
343 ])
344 
345 ## Extended set of plots
346 _extDist1 = PlotGroup("dist1",
347  _makeDistPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
348  _makeDistPlots("eta", "#eta") +
349  _makeDistPlots("phi", "#phi"),
350  ncols=4)
351 _extDist2 = PlotGroup("dist2",
352  _makeDistPlots("dxy" , "dxy (cm)") +
353  _makeDistPlots("dxypv", "dxy(PV) (cm)") +
354  _makeDistPlots("dz" , "dz (cm)") +
355  _makeDistPlots("dzpv" , "dz(PV) (cm)"),
356  ncols=4, legendDy=_legendDy_4rows)
357 _extDist3 = PlotGroup("dist3",
358  _makeDistPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
359  _makeDistPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
360  _makeDistPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
361  _makeDistPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
362  ncols=4, legendDy=_legendDy_4rows,
363 )
364 _extDist4 = PlotGroup("dist4",
365  _makeDistPlots("vertpos", "ref. point xy (cm)") +
366  _makeDistPlots("zpos" , "ref. point z (cm)") +
367  _makeDistPlots("dr" , "min #DeltaR", common=dict(xlog=True)),
368  ncols=4
369 )
370 _extDist5 = PlotGroup("dist5",
371  _makeDistPlots("chi2", "#chi^{2}") +
372  _makeDistPlots("seedingLayerSet", "seeding layers", common=dict(xtitle="", **_seedingLayerSet_common)),
373  ncols=4, legendDy=_legendDy_2rows_3cols
374 )
375 _common = dict(title="", ytitle="Selected tracks/TrackingParticles", ymax=_maxEff)
376 _extNrecVsNsim = PlotGroup("nrecVsNsim", [
377  Plot("nrec_vs_nsim", title="", xtitle="TrackingParticles", ytitle="Tracks", profileX=True, xmin=_minMaxTracks, xmax=_minMaxTracks, ymin=_minMaxTracks, ymax=_minMaxTracks),
378  Plot("nrecPerNsim_vs_pu", xtitle="Pileup", xmin=_minPU, xmax=_maxPU, **_common),
379  Plot("nrecPerNsimPt", xtitle="p_{T} (GeV)", xlog=True, **_common),
380  Plot("nrecPerNsim", xtitle="#eta", **_common)
381 ], legendDy=_legendDy_2rows)
382 _extHitsLayers = PlotGroup("hitsLayers", [
383  Plot("PXLhits_vs_eta", xtitle="#eta", ytitle="<pixel hits>"),
384  Plot("PXLlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<pixel layers>"),
385  Plot("STRIPhits_vs_eta", xtitle="#eta", ytitle="<strip hits>"),
386  Plot("STRIPlayersWithMeas_vs_eta", xtitle="#eta", ytitle="<strip layers>"),
387 ], legendDy=_legendDy_2rows)
388 
389 
390 ## Extended set of plots also for simulation
391 _extDistSim1 = PlotGroup("distsim1",
392  _makeDistSimPlots("pT", "p_{T} (GeV)", common=dict(xlog=True)) +
393  _makeDistSimPlots("eta", "#eta") +
394  _makeDistSimPlots("phi", "#phi"),
395  ncols=2)
396 _extDistSim2 = PlotGroup("distsim2",
397  _makeDistSimPlots("dxy" , "dxy (cm)") +
398  _makeDistSimPlots("dxypv", "dxy(PV) (cm)") +
399  _makeDistSimPlots("dz" , "dz (cm)") +
400  _makeDistSimPlots("dzpv" , "dz(PV) (cm)"),
401  ncols=2, legendDy=_legendDy_4rows)
402 _extDistSim3 = PlotGroup("distsim3",
403  _makeDistSimPlots("hit" , "hits" , common=dict(xmin=_minHits , xmax=_maxHits)) +
404  _makeDistSimPlots("layer" , "layers" , common=dict(xmin=_minLayers , xmax=_maxLayers)) +
405  _makeDistSimPlots("pixellayer", "pixel layers", common=dict( xmax=_maxPixelLayers)) +
406  _makeDistSimPlots("3Dlayer" , "3D layers" , common=dict(xmin=_min3DLayers, xmax=_max3DLayers)),
407  ncols=2, legendDy=_legendDy_4rows,
408 )
409 _extDistSim4 = PlotGroup("distsim4",
410  _makeDistSimPlots("vertpos", "ref. point xy (cm)") +
411  _makeDistSimPlots("zpos" , "ref. point z (cm)") +
412  _makeDistSimPlots("dr" , "min #DeltaR", common=dict(xlog=True)),
413  ncols=2
414 )
415 
416 ########################################
417 #
418 # Summary plots
419 #
420 ########################################
421 
422 _possibleTrackingNonIterationColls = [
423  'ak4PFJets',
424  'btvLike',
425 ]
426 _possibleTrackingColls = [
427  'initialStepPreSplitting',
428  'initialStep',
429  'highPtTripletStep', # phase1
430  'detachedQuadStep', # phase1
431  'detachedTripletStep',
432  'lowPtQuadStep', # phase1
433  'lowPtTripletStep',
434  'pixelPairStep',
435  'mixedTripletStepA', # seeds
436  'mixedTripletStepB', # seeds
437  'mixedTripletStep',
438  'pixelLessStep',
439  'tobTecStepPair', # seeds
440  'tobTecStepTripl', # seeds
441  'tobTecStep',
442  'jetCoreRegionalStep',
443  'muonSeededStepInOut',
444  'muonSeededStepOutIn',
445  'duplicateMerge',
446 ] + _possibleTrackingNonIterationColls
447 _possibleTrackingCollsOld = {
448  "Zero" : "iter0",
449  "First" : "iter1",
450  "Second": "iter2",
451  "Third" : "iter3",
452  "Fourth": "iter4",
453  "Fifth" : "iter5",
454  "Sixth" : "iter6",
455  "Seventh": "iter7",
456  "Ninth" : "iter9",
457  "Tenth" : "iter10",
458 }
459 
461  ret = subfolder.replace("trackingParticleRecoAsssociation", "AssociatorByHitsRecoDenom")
462  for (old, new) in [("InitialStep", "Zero"),
463  ("LowPtTripletStep", "First"),
464  ("PixelPairStep", "Second"),
465  ("MixedTripletStep", "Fourth"),
466  ("MuonSeededStepInOut", "Ninth"),
467  ("MuonSeededStepOutIn", "Tenth")]:
468 
469  ret = ret.replace(old, new)
470  if ret == subfolder:
471  return None
472  return ret
474  for (old, new) in [("initialStep", "iter0"),
475  ("lowPtTripletStep", "iter1"),
476  ("pixelPairStep", "iter2"),
477  ("mixedTripletStep", "iter4"),
478  ("muonSeededStepInOut", "iter9"),
479  ("muonSeededStepOutIn", "iter10")]:
480  path = path.replace(old, new)
481  return path
482 
484  ret = subfolder.replace("trackingParticleRecoAsssociation", "AssociatorByHitsRecoDenom")
485  for (old, new) in [("InitialStep", "Zero"),
486  ("HighPtTripletStep", "First"),
487  ("LowPtQuadStep", "Second"),
488  ("LowPtTripletStep", "Third"),
489  ("DetachedQuadStep", "Fourth"),
490  ("PixelPairStep", "Fifth"),
491  ("MuonSeededStepInOut", "Ninth"),
492  ("MuonSeededStepOutIn", "Tenth")]:
493  ret = ret.replace(old, new)
494  if ret == subfolder:
495  return None
496  return ret
498  for (old, new) in [("initialStep", "iter0"),
499  ("highPtTripletStep", "iter1"),
500  ("lowPtQuadStep", "iter2"),
501  ("lowPtTripletStep", "iter3"),
502  ("detachedQuadStep", "iter4"),
503  ("pixelPairStep", "iter5"),
504  ("muonSeededStepInOut", "iter9"),
505  ("muonSeededStepOutIn", "iter10")]:
506  path = path.replace(old, new)
507  return path
508 
510  return subfolder.replace("trackingParticleRecoAsssociation", "trackingParticleRecoAsssociationSignal")
512  return subfolder.replace("quickAssociatorByHits", "quickAssociatorByHitsConversion")
513 
515  if "Hp" in collName:
516  quality = "highPurity"
517  else:
518  quality = ""
519  hasPtCut = "Pt09" in collName
520  collNameNoQuality = collName.replace("Hp", "")
521  if hasPtCut:
522  quality += "Pt09"
523  collNameNoQuality = collNameNoQuality.replace("Pt09", "")
524  if "ByOriginalAlgo" in collName:
525  quality += "ByOriginalAlgo"
526  collNameNoQuality = collNameNoQuality.replace("ByOriginalAlgo", "")
527  if "ByAlgoMask" in collName:
528  quality += "ByAlgoMask"
529  collNameNoQuality = collNameNoQuality.replace("ByAlgoMask", "")
530  collNameNoQuality = collNameNoQuality.replace("Tracks", "", 1) # make summary naming consistent with iteration folders
531  collNameLow = collNameNoQuality.lower().replace("frompv2", "").replace("frompv", "").replace("frompvalltp", "").replace("alltp", "")
532 
533  if collNameLow.find("seed") == 0:
534  if quality != "":
535  raise Exception("Assumption of empty quality for seeds failed, got quality '%s'" % quality)
536  collNameLow = collNameLow[4:]
537  if collNameLow == "initialstepseedspresplitting":
538  collNameLow = "initialsteppresplittingseeds"
539  elif collNameLow == "muonseededseedsinout":
540  collNameLow = "muonseededstepinoutseeds"
541  elif collNameLow == "muonseededseedsoutin":
542  collNameLow = "muonseededstepoutinseeds"
543 
544  i_seeds = collNameLow.index("seeds")
545  quality = collNameLow[i_seeds:]
546 
547  collNameLow = collNameLow[:i_seeds]
548 
549  algo = None
550  prefixes = ["cutsreco", "cutsrecofrompv", "cutsrecofrompv2", "cutsrecofrompvalltp"]
551  if collNameLow in ["general", "generalfrompv"]+prefixes:
552  algo = "ootb"
553  else:
554  def testColl(coll):
555  for pfx in prefixes:
556  if coll == collNameLow.replace(pfx, ""):
557  return True
558  return False
559 
560  for coll in _possibleTrackingColls:
561  if testColl(coll.lower()):
562  algo = coll
563  break
564  # next try "old style"
565  if algo is None:
566  for coll, name in _possibleTrackingCollsOld.iteritems():
567  if testColl(coll.lower()):
568  algo = name
569  break
570 
571  # fallback
572  if algo is None:
573  algo = collNameNoQuality
574 
575  # fix for track collection naming convention
576  if algo == "muonSeededInOut":
577  algo = "muonSeededStepInOut"
578  if algo == "muonSeededOutIn":
579  algo = "muonSeededStepOutIn"
580 
581  return (algo, quality)
582 
583 def _collhelper(name):
584  return (name, [name])
585 _collLabelMap = collections.OrderedDict(map(_collhelper, ["generalTracks"]+_possibleTrackingColls))
586 _collLabelMapHp = collections.OrderedDict(map(_collhelper, ["generalTracks"]+filter(lambda n: "Step" in n, _possibleTrackingColls)))
587 def _summaryBinRename(binLabel, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds):
588  (algo, quality) = _mapCollectionToAlgoQuality(binLabel)
589  if algo == "ootb":
590  algo = "generalTracks"
591  ret = None
592 
593  if byOriginalAlgo:
594  if algo != "generalTracks" and "ByOriginalAlgo" not in quality:
595  return None
596  quality = quality.replace("ByOriginalAlgo", "")
597  if byAlgoMask:
598  if algo != "generalTracks" and "ByAlgoMask" not in quality:
599  return None
600  quality = quality.replace("ByAlgoMask", "")
601  if ptCut:
602  if algo != "generalTracks" and "Pt09" not in quality:
603  return None
604  quality = quality.replace("Pt09", "")
605 
606  if highPurity:
607  if quality == "highPurity":
608  ret = algo
609  elif seeds:
610  i_seeds = quality.find("seeds")
611  if i_seeds == 0:
612  ret = algo
613  seedSubColl = quality[i_seeds+5:]
614  if seedSubColl != "":
615  ret += seedSubColl[0].upper() + seedSubColl[1:]
616  else:
617  if quality == "":
618  ret = algo
619 
620  return ret
621 
622 def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False, midfix=""):
623  _common = {"drawStyle": "EP", "xbinlabelsize": 10, "xbinlabeloption": "d"}
624  _commonN = dict(ylog=True, ymin=_minMaxN, ymax=_minMaxN,
625  normalizeToNumberOfEvents=True,
626  )
627  _commonN.update(_common)
628  _commonAB = dict(mapping=mapping,
629  renameBin=lambda bl: _summaryBinRename(bl, highPurity, byOriginalAlgo, byAlgoMask, ptCut, seeds),
630  ignoreMissingBins=True,
631  originalOrder=True,
632  )
633  if byOriginalAlgo or byAlgoMask:
634  _commonAB["minExistingBins"] = 2
635  prefix = "summary"+midfix
636 
637  h_eff = "effic_vs_coll"
638  h_eff_allpt = "effic_vs_coll_allPt"
639  h_fakerate = "fakerate_vs_coll"
640  h_duplicaterate = "duplicatesRate_coll"
641  h_pileuprate = "pileuprate_coll"
642 
643  h_reco = "num_reco_coll"
644  h_true = "num_assoc(recoToSim)_coll"
645  h_fake = Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll")
646  h_duplicate = "num_duplicate_coll"
647  h_pileup = "num_pileup_coll"
648  if mapping is not None:
649  h_eff = AggregateBins("efficiency", h_eff, **_commonAB)
650  h_eff_allpt = AggregateBins("efficiencyAllPt", h_eff_allpt, **_commonAB)
651  h_fakerate = AggregateBins("fakerate", h_fakerate, **_commonAB)
652  h_duplicaterate = AggregateBins("duplicatesRate", h_duplicaterate, **_commonAB)
653  h_pileuprate = AggregateBins("pileuprate", h_pileuprate, **_commonAB)
654 
655  h_reco = AggregateBins("num_reco_coll", h_reco, **_commonAB)
656  h_true = AggregateBins("num_true_coll", h_true, **_commonAB)
657  h_fake = AggregateBins("num_fake_coll", h_fake, **_commonAB)
658  h_duplicate = AggregateBins("num_duplicate_coll", h_duplicate, **_commonAB)
659  h_pileup = AggregateBins("num_pileup_coll", h_pileup, **_commonAB)
660 
661  summary = PlotGroup(prefix, [
662  Plot(h_eff, title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
663  Plot(h_eff_allpt, title="Efficiency vs collection (no pT cut in denominator)", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
664 
665  Plot(h_fakerate, title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
666  Plot(h_duplicaterate, title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
667  Plot(h_pileuprate, title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
668  ])
669  summaryN = PlotGroup(prefix+"_ntracks", [
670  Plot(h_reco, ytitle="Tracks/event", title="Number of tracks/event vs collection", **_commonN),
671  Plot(h_true, ytitle="True tracks/event", title="Number of true tracks/event vs collection", **_commonN),
672  Plot(h_fake, ytitle="Fake tracks/event", title="Number of fake tracks/event vs collection", **_commonN),
673  Plot(h_duplicate, ytitle="Duplicate tracks/event", title="Number of duplicate tracks/event vs collection", **_commonN),
674  Plot(h_pileup, ytitle="Pileup tracks/event", title="Number of pileup tracks/event vs collection", **_commonN),
675  ])
676 
677  return (summary, summaryN)
678 
679 (_summaryRaw, _summaryRawN) = _constructSummary(midfix="Raw")
680 (_summary, _summaryN) = _constructSummary(_collLabelMap)
681 (_summaryHp, _summaryNHp) = _constructSummary(_collLabelMapHp, highPurity=True)
682 (_summaryByOriginalAlgo, _summaryByOriginalAlgoN) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo")
683 (_summaryByOriginalAlgoHp, _summaryByOriginalAlgoNHp) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo", highPurity=True)
684 (_summaryByAlgoMask, _summaryByAlgoMaskN) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask")
685 (_summaryByAlgoMaskHp, _summaryByAlgoMaskNHp) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask", highPurity=True)
686 (_summaryPt09, _summaryPt09N) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09")
687 (_summaryPt09Hp, _summaryPt09NHp) = _constructSummary(_collLabelMap, ptCut=True, midfix="Pt09", highPurity=True)
688 (_summarySeeds, _summarySeedsN) = _constructSummary(_collLabelMapHp, seeds=True)
689 
690 ########################################
691 #
692 # PackedCandidate plots
693 #
694 ########################################
695 
696 _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]}
697 _commonStatus = {}
698 _commonStatus.update(_common)
699 _commonStatus.update({"xbinlabelsize": 10, "xbinlabeloption": "d", "drawStyle": "hist", "adjustMarginRight": 0.08})
700 _commonLabelSize = {}
701 _commonLabelSize.update(_common)
702 _commonLabelSize.update({"xlabelsize": 17})
703 
704 _packedCandidateFlow = PlotGroup("flow", [
705  Plot("selectionFlow", xbinlabelsize=10, xbinlabeloption="d", adjustMarginRight=0.1, drawStyle="hist", ylog=True, ymin=[0.9, 9, 9e1, 9e2, 9e3, 9e4, 9e5, 9e6, 9e7]),
706  Plot("diffCharge", xtitle="Charge", **_common),
707  Plot("diffIsHighPurity", xtitle="High purity status", **_common),
708  Plot("diffNdof", xtitle="ndof", **_common),
709  Plot("diffNormalizedChi2", xtitle="#chi^{2}/ndof", **_common),
710 ])
711 
712 _packedCandidateHitsHitPattern = PlotGroup("hitsHitPattern", [
713  Plot("diffHitPatternNumberOfValidHits", xtitle="Valid hits (via HitPattern)", **_common),
714  Plot("diffHitPatternNumberOfValidPixelHits", xtitle="Valid pixel hits (via HitPattern)", **_common),
715  Plot("diffHitPatternHasValidHitInFirstPixelBarrel", xtitle="Has valid hit in BPix1 layer (via HitPattern)", **_common),
716  Plot("diffHitPatternNumberOfLostPixelHits", xtitle="Lost pixel hits (via HitPattern)", **_common),
717 ],
718  legendDy=_legendDy_2rows
719 )
720 _packedCandidateHits = PlotGroup("hits", [
721  Plot("diffNumberOfHits", xtitle="Hits", **_common),
722  Plot("diffNumberOfPixelHits", xtitle="Pixel hits", **_common),
723  Plot("diffLostInnerHits", xtitle="Lost inner hits", **_common),
724  Plot("numberHitsOverMax", xtitle="Number of overflown hits", **_common),
725  Plot("numberPixelHitsOverMax", xtitle="Number of overflown pixel hits", **_common),
726  Plot("numberStripHitsOverMax", xtitle="Number of overflown strip hits", **_common),
727 ],
728  ncols=3, legendDy=_legendDy_2rows_3cols
729 )
730 
731 _packedCandidateImpactParameter1 = PlotGroup("impactParameter1", [
732  Plot("diffDxyAssocPV", xtitle="dxy(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
733  Plot("diffDxyAssocPVStatus", **_commonStatus),
734  Plot("diffDxyAssocPVUnderOverFlowSign", xtitle="dxy(assocPV)", **_common),
735  Plot("diffDzAssocPV", xtitle="dz(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
736  Plot("diffDzAssocPVStatus", **_commonStatus),
737  Plot("diffDzAssocPVUnderOverFlowSign", xtitle="dz(assocPV)", **_common),
738  Plot("diffDxyError", xtitle="dxyError()", adjustMarginRight=0.02, **_commonLabelSize),
739  Plot("diffDszError", xtitle="dszError()", adjustMarginRight=0.02, **_commonLabelSize),
740  Plot("diffDzError", xtitle="dzError()", adjustMarginRight=0.02, **_commonLabelSize),
741 
742 ],
743  ncols=3
744 )
745 
746 _packedCandidateImpactParameter2 = PlotGroup("impactParameter2", [
747  Plot("diffDxyPV", xtitle="dxy(PV) via PC", **_commonLabelSize),
748  Plot("diffDzPV", xtitle="dz(PV) via PC", **_commonLabelSize),
749  Plot("diffTrackDxyAssocPV", xtitle="dxy(PV) via PC::bestTrack()", **_commonLabelSize),
750  Plot("diffTrackDzAssocPV", xtitle="dz(PV) via PC::bestTrack()", **_commonLabelSize),
751  Plot("diffTrackDxyError", xtitle="dxyError() via PC::bestTrack()", adjustMarginRight=0.02, **_commonLabelSize),
752  Plot("diffTrackDzError", xtitle="dzError() via PC::bestTrack()", **_commonLabelSize),
753 ])
754 
755 _packedCandidateCovarianceMatrix1 = PlotGroup("covarianceMatrix1", [
756  Plot("diffCovQoverpQoverp", xtitle="cov(qoverp, qoverp)", **_commonLabelSize),
757  Plot("diffCovQoverpQoverpStatus", **_commonStatus),
758  Plot("diffCovQoverpQoverpUnderOverFlowSign", xtitle="cov(qoverp, qoverp)", **_common),
759  Plot("diffCovLambdaLambda", xtitle="cov(lambda, lambda)", **_commonLabelSize),
760  Plot("diffCovLambdaLambdaStatus", **_commonStatus),
761  Plot("diffCovLambdaLambdaUnderOverFlowSign", xtitle="cov(lambda, lambda)", **_common),
762  Plot("diffCovLambdaDsz", xtitle="cov(lambda, dsz)", **_commonLabelSize),
763  Plot("diffCovLambdaDszStatus", **_commonStatus),
764  Plot("diffCovLambdaDszUnderOverFlowSign", xtitle="cov(lambda, dsz)", **_common),
765  Plot("diffCovPhiPhi", xtitle="cov(phi, phi)", **_commonLabelSize),
766  Plot("diffCovPhiPhiStatus", **_commonStatus),
767  Plot("diffCovPhiPhiUnderOverFlowSign", xtitle="cov(phi, phi)", **_common),
768 ],
769  ncols=3, legendDy=_legendDy_4rows
770 )
771 _packedCandidateCovarianceMatrix2 = PlotGroup("covarianceMatrix2", [
772  Plot("diffCovPhiDxy", xtitle="cov(phi, dxy)", **_commonLabelSize),
773  Plot("diffCovPhiDxyStatus", **_commonStatus),
774  Plot("diffCovPhiDxyUnderOverFlowSign", xtitle="cov(phi, dxy)", **_common),
775  Plot("diffCovDxyDxy", xtitle="cov(dxy, dxy)", adjustMarginRight=0.02, **_commonLabelSize),
776  Plot("diffCovDxyDxyStatus", **_commonStatus),
777  Plot("diffCovDxyDxyUnderOverFlowSign", xtitle="cov(dxy, dxy)", **_common),
778  Plot("diffCovDxyDsz", xtitle="cov(dxy, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
779  Plot("diffCovDxyDszStatus", **_commonStatus),
780  Plot("diffCovDxyDszUnderOverFlowSign", xtitle="cov(dxy, dsz)", **_common),
781  Plot("diffCovDszDsz", xtitle="cov(dsz, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
782  Plot("diffCovDszDszStatus", **_commonStatus),
783  Plot("diffCovDszDszUnderOverFlowSign", xtitle="cov(dsz, dsz)", **_common),
784 ],
785  ncols=3, legendDy=_legendDy_4rows
786 )
787 
788 _common["xlabelsize"] = 16
789 _packedCandidateVertex = PlotGroup("vertex", [
790  Plot("diffVx", xtitle="Reference point x", **_common),
791  Plot("diffVy", xtitle="Reference point y", **_common),
792  Plot("diffVz", xtitle="Reference point z", **_common),
793 ],
794  legendDy=_legendDy_2rows
795 )
796 
797 _common["adjustMarginRight"] = 0.05
798 _packedCandidateKinematics = PlotGroup("kinematics", [
799  Plot("diffPt", xtitle="p_{T}", **_common),
800  Plot("diffPtError", xtitle="p_{T} error", **_common),
801  Plot("diffEta", xtitle="#eta", **_common),
802  Plot("diffEtaError", xtitle="#eta error", **_common),
803  Plot("diffPhi", xtitle="#phi", **_common),
804 ])
805 
807  def __init__(self, *args, **kwargs):
808  self._fallbackRefFiles = kwargs.pop("fallbackRefFiles", [])
809  PlotFolder.__init__(self, *args, **kwargs)
810 
811  def translateSubFolder(self, dqmSubFolderName):
812  spl = dqmSubFolderName.split("_")
813  if len(spl) != 2:
814  return None
815  collName = spl[0]
816  return _mapCollectionToAlgoQuality(collName)
817 
818  def iterSelectionName(self, plotFolderName, translatedDqmSubFolder):
819  (algoOrig, quality) = translatedDqmSubFolder
820 
821  for fallback in [lambda n: n]+self._fallbackRefFiles:
822  algo = fallback(algoOrig)
823 
824  ret = ""
825  if plotFolderName != "":
826  ret += "_"+plotFolderName
827  if quality != "":
828  ret += "_"+quality
829  if not (algo == "ootb" and quality != ""):
830  ret += "_"+algo
831  yield ret
832 
833  def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder):
834  """Return True if this subfolder should be processed
835 
836  Arguments:
837  limitOnlyTo -- Function '(algo, quality) -> bool'
838  translatedDqmSubFolder -- Return value of translateSubFolder
839  """
840  (algo, quality) = translatedDqmSubFolder
841  return limitOnlyTo(algo, quality)
842 
843  # track-specific hack
844  def isAlgoIterative(self, algo):
845  return algo not in _possibleTrackingNonIterationColls
846 
848  class GeneralTracks: pass
849  class HighPurity: pass
850  class BTVLike: pass
851  class AK4PFJets: pass
852 
853  def __init__(self, section, collection=GeneralTracks):
854  self._collection = collection
856  self._page = "summary"
857  self._section = section
858 
859  def getPurpose(self):
860  return self._purpose
861 
862  def getPage(self):
863  return self._page
864 
865  def getSection(self, dqmSubFolder):
866  return self._section
867 
868  def create(self, tdirectory):
869  def _getAlgoQuality(data, algo, quality):
870  for label, value in data.iteritems():
871  (a, q) = _mapCollectionToAlgoQuality(label)
872  if a == algo and q == quality:
873  return value[0] # value is (value, uncertainty) tuple
874  return None
875  def _getN(hname):
876  h = tdirectory.Get(hname)
877  if not h:
878  return None
881  return _getAlgoQuality(data, "ootb", "")
883  return _getAlgoQuality(data, "ootb", "highPurity")
885  return _getAlgoQuality(data, "btvLike", "")
887  return _getAlgoQuality(data, "ak4PFJets", "")
888  else:
889  raise Exception("Collection not recognized, %s" % str(self._collection))
890  def _formatOrNone(num, func):
891  if num is None:
892  return None
893  return func(num)
894 
895  n_tps = _formatOrNone(_getN("num_simul_coll"), int)
896  n_m_tps = _formatOrNone(_getN("num_assoc(simToReco)_coll"), int)
897 
898  n_tracks = _formatOrNone(_getN("num_reco_coll"), int)
899  n_true = _formatOrNone(_getN("num_assoc(recoToSim)_coll"), int)
900  if n_tracks is not None and n_true is not None:
901  n_fake = n_tracks-n_true
902  else:
903  n_fake = None
904  n_pileup = _formatOrNone(_getN("num_pileup_coll"), int)
905  n_duplicate = _formatOrNone(_getN("num_duplicate_coll"), int)
906 
907  eff = _formatOrNone(_getN("effic_vs_coll"), lambda n: "%.4f" % n)
908  eff_nopt = _formatOrNone(_getN("effic_vs_coll_allPt"), lambda n: "%.4f" % n)
909  fake = _formatOrNone(_getN("fakerate_vs_coll"), lambda n: "%.4f" % n)
910  duplicate = _formatOrNone(_getN("duplicatesRate_coll"), lambda n: "%.4f" % n)
911 
912  ret = [eff, n_tps, n_m_tps,
913  eff_nopt, fake, duplicate,
914  n_tracks, n_true, n_fake, n_pileup, n_duplicate]
915  if ret.count(None) == len(ret):
916  return None
917  return ret
918 
919  def headers(self):
920  return [
921  "Efficiency",
922  "Number of TrackingParticles (after cuts)",
923  "Number of matched TrackingParticles",
924  "Efficiency (w/o pT cut)",
925  "Fake rate",
926  "Duplicate rate",
927  "Number of tracks",
928  "Number of true tracks",
929  "Number of fake tracks",
930  "Number of pileup tracks",
931  "Number of duplicate tracks"
932  ]
933 
934 def _trackingFolders(lastDirName="Track"):
935  return [
936  "DQMData/Run 1/Tracking/Run summary/"+lastDirName,
937  "DQMData/Tracking/"+lastDirName,
938  "DQMData/Run 1/RecoTrackV/Run summary/"+lastDirName,
939  "DQMData/RecoTrackV/"+lastDirName,
940  ]
941 
942 _simBasedPlots = [
943  _effandfake1,
944  _effandfake2,
945  _effandfake3,
946  _effandfake4,
947 ]
948 _recoBasedPlots = [
949  _dupandfake1,
950  _dupandfake2,
951  _dupandfake3,
952  _dupandfake4,
953  _dupandfake5,
954  _pvassociation1,
955  _pvassociation2,
956  _pvassociation3,
957  _dedx,
958 # _chargemisid,
959  _hitsAndPt,
960  _pulls,
961  _resolutionsEta,
962  _resolutionsPt,
963  _tuning,
964 ]
965 _seedingBuildingPlots = _simBasedPlots + [
966  _dupandfake1,
967  _dupandfake2,
968  _dupandfake3,
969  _dupandfake4,
970  _dupandfake5,
971  _hitsAndPt,
972  _makeMVAPlots(1),
973  _makeMVAPlots(2),
974  _makeMVAPlots(2, hp=True),
975  _makeMVAPlots(3), # add more if needed
976  _makeMVAPlots(3, hp=True), # add more if needed
977 ]
978 _extendedPlots = [
979  _extDist1,
980  _extDist2,
981  _extDist3,
982  _extDist4,
983  _extDist5,
984  _extNrecVsNsim,
985  _extHitsLayers,
986  _extDistSim1,
987  _extDistSim2,
988  _extDistSim3,
989  _extDistSim4,
990 ]
991 _summaryPlots = [
992  _summary,
993  _summaryN,
994  _summaryByOriginalAlgo,
995  _summaryByOriginalAlgoN,
996  _summaryByAlgoMask,
997  _summaryByAlgoMaskN,
998  _summaryPt09,
999  _summaryPt09N,
1000 ]
1001 _summaryPlotsHp = [
1002  _summaryHp,
1003  _summaryNHp,
1004  _summaryByOriginalAlgoHp,
1005  _summaryByOriginalAlgoNHp,
1006  _summaryByAlgoMaskHp,
1007  _summaryByAlgoMaskNHp,
1008  _summaryPt09Hp,
1009  _summaryPt09NHp,
1010 ]
1011 _summaryPlotsSeeds = [
1012  _summarySeeds,
1013  _summarySeedsN,
1014 ]
1015 _packedCandidatePlots = [
1016  _packedCandidateFlow,
1017  _packedCandidateKinematics,
1018  _packedCandidateVertex,
1019  _packedCandidateImpactParameter1,
1020  _packedCandidateImpactParameter2,
1021  _packedCandidateCovarianceMatrix1,
1022  _packedCandidateCovarianceMatrix2,
1023  _packedCandidateHits,
1024  _packedCandidateHitsHitPattern,
1025 ]
1026 plotter = Plotter()
1027 plotterExt = Plotter()
1028 def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, onlyForElectron=False, onlyForConversion=False, seeding=False, rawSummary=False):
1029  folders = _trackingFolders(lastDirName)
1030  # to keep backward compatibility, this set of plots has empty name
1031  limiters = dict(onlyForPileup=onlyForPileup, onlyForElectron=onlyForElectron, onlyForConversion=onlyForConversion)
1032  commonForTPF = dict(purpose=PlotPurpose.TrackingIteration, fallbackRefFiles=[
1033  #_trackingRefFileFallbackSLHC_Phase1PU70_OldMapping
1034  _trackingRefFileFallbackSLHC_Phase1PU140
1035  ], **limiters)
1036  common = dict(fallbackDqmSubFolders=[
1037  #_trackingSubFoldersFallbackSLHC_Phase1PU70_OldMapping,
1038  _trackingSubFoldersFallbackSLHC_Phase1PU140,
1039  _trackingSubFoldersFallbackFromPV, _trackingSubFoldersFallbackConversion])
1040  plotter.append(name, folders, TrackingPlotFolder(*algoPlots, **commonForTPF), **common)
1041  plotterExt.append(name, folders, TrackingPlotFolder(*_extendedPlots, **commonForTPF), **common)
1042 
1043  summaryName = ""
1044  if name != "":
1045  summaryName += name+"_"
1046  summaryName += "summary"
1047  summaryPlots = []
1048  if rawSummary:
1049  summaryPlots.extend([_summaryRaw, _summaryRawN])
1050  summaryPlots.extend(_summaryPlots)
1051 
1052  common = dict(loopSubFolders=False, purpose=PlotPurpose.TrackingSummary, page="summary", numberOfEventsHistogram=_trackingNumberOfEventsHistogram, **limiters)
1053  plotter.append(summaryName, folders,
1054  PlotFolder(*summaryPlots, section=name, **common))
1055  plotter.append(summaryName+"_highPurity", folders,
1056  PlotFolder(*_summaryPlotsHp, section=name+"_highPurity" if name != "" else "highPurity", **common),
1057  fallbackNames=[summaryName]) # backward compatibility for release validation, the HP plots used to be in the same directory with all-track plots
1058  if seeding:
1059  plotter.append(summaryName+"_seeds", folders,
1060  PlotFolder(*_summaryPlotsSeeds, section=name+"_seeds", **common))
1061 
1062  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section=name))
1063  plotter.appendTable(summaryName+"_highPurity", folders, TrackingSummaryTable(section=name+"_highPurity" if name != "" else "highPurity", collection=TrackingSummaryTable.HighPurity))
1064  if name == "":
1065  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="btvLike", collection=TrackingSummaryTable.BTVLike))
1066  plotter.appendTable(summaryName, folders, TrackingSummaryTable(section="ak4PFJets", collection=TrackingSummaryTable.AK4PFJets))
1067 _appendTrackingPlots("Track", "", _simBasedPlots+_recoBasedPlots)
1068 _appendTrackingPlots("TrackAllTPEffic", "allTPEffic", _simBasedPlots, onlyForPileup=True)
1069 _appendTrackingPlots("TrackFromPV", "fromPV", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1070 _appendTrackingPlots("TrackFromPVAllTP", "fromPVAllTP", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1071 _appendTrackingPlots("TrackFromPVAllTP2", "fromPVAllTP2", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
1072 _appendTrackingPlots("TrackSeeding", "seeding", _seedingBuildingPlots, seeding=True)
1073 _appendTrackingPlots("TrackBuilding", "building", _seedingBuildingPlots)
1074 _appendTrackingPlots("TrackConversion", "conversion", _simBasedPlots+_recoBasedPlots, onlyForConversion=True, rawSummary=True)
1075 _appendTrackingPlots("TrackGsf", "gsf", _simBasedPlots+_recoBasedPlots, onlyForElectron=True, rawSummary=True)
1076 
1077 # MiniAOD
1078 plotter.append("packedCandidate", _trackingFolders("PackedCandidate"),
1079  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1080  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate"))
1081 plotter.append("packedCandidateLostTracks", _trackingFolders("PackedCandidate/lostTracks"),
1082  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
1083  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate (lostTracks)"))
1084 
1085 # HLT
1086 _hltFolder = [
1087  "DQMData/Run 1/HLT/Run summary/Tracking/ValidationWRTtp",
1088 ]
1089 plotterHLT = Plotter()
1090 plotterHLTExt = Plotter()
1091 _common = dict(purpose=PlotPurpose.HLT, page="hlt")
1092 plotterHLT.append("hlt", _hltFolder, TrackingPlotFolder(*(_simBasedPlots+_recoBasedPlots), **_common))
1093 plotterHLTExt.append("hlt", _hltFolder, TrackingPlotFolder(*_extendedPlots, **_common))
1094 
1095 # Timing
1097  def __init__(self, name, clusterMasking=None, seeding=None, building=None, fit=None, selection=None, other=[]):
1098  self._name = name
1099 
1100  def _set(param, name, modules):
1101  if param is not None:
1102  setattr(self, name, param)
1103  else:
1104  setattr(self, name, modules)
1105 
1106  _set(clusterMasking, "_clusterMasking", [self._name+"Clusters"])
1107  # it's fine to include e.g. quadruplets here also for pair
1108  # steps, as non-existing modules are just ignored
1109  _set(seeding, "_seeding", [self._name+"SeedingLayers", self._name+"TrackingRegions", self._name+"HitDoublets", self._name+"HitTriplets", self._name+"HitQuadruplets", self._name+"Seeds"])
1110  _set(building, "_building", [self._name+"TrackCandidates"])
1111  _set(fit, "_fit", [self._name+"Tracks"])
1112  _set(selection, "_selection", [self._name])
1113  self._other = other
1114 
1115  def name(self):
1116  return self._name
1117 
1118  def all(self):
1119  return self._clusterMasking+self._seeding+self._building+self._fit+self._selection+self._other
1120 
1121  def clusterMasking(self):
1122  return self._clusterMasking
1123 
1124  def seeding(self):
1125  return self._seeding
1126 
1127  def building(self):
1128  return self._building
1129 
1130  def fit(self):
1131  return self._fit
1132 
1133  def selection(self):
1134  return self._selection
1135 
1136  def other(self):
1137  return self._other
1138 
1139  def modules(self):
1140  return [("ClusterMask", self.clusterMasking()),
1141  ("Seeding", self.seeding()),
1142  ("Building", self.building()),
1143  ("Fit", self.fit()),
1144  ("Selection", self.selection()),
1145  ("Other", self.other())]
1146 
1147 
1148 _iterations = [
1149  Iteration("initialStepPreSplitting", clusterMasking=[],
1150  seeding=["initialStepSeedLayersPreSplitting",
1151  "initialStepTrackingRegionsPreSplitting",
1152  "initialStepHitDoubletsPreSplitting",
1153  "initialStepHitTripletsPreSplitting",
1154  "initialStepHitQuadrupletsPreSplitting",
1155  "initialStepSeedsPreSplitting"],
1156  building=["initialStepTrackCandidatesPreSplitting"],
1157  fit=["initialStepTracksPreSplitting"],
1158  other=["firstStepPrimaryVerticesPreSplitting",
1159  "initialStepTrackRefsForJetsPreSplitting",
1160  "caloTowerForTrkPreSplitting",
1161  "ak4CaloJetsForTrkPreSplitting",
1162  "jetsForCoreTrackingPreSplitting",
1163  "siPixelClusters",
1164  "siPixelRecHits",
1165  "MeasurementTrackerEvent",
1166  "siPixelClusterShapeCache"]),
1167  Iteration("initialStep", clusterMasking=[],
1168  selection=["initialStepClassifier1",
1169  "initialStepClassifier2",
1170  "initialStepClassifier3",
1171  "initialStep"],
1172  other=["firstStepPrimaryVertices"]),
1173  Iteration("highPtTripletStep",
1174  selection=["highPtTripletStepClassifier1",
1175  "highPtTripletStepClassifier2",
1176  "highPtTripletStepClassifier3",
1177  "highPtTripletStep"]),
1178  Iteration("detachedQuadStep",
1179  selection=["detachedQuadStepClassifier1",
1180  "detachedQuadStepClassifier2",
1181  "detachedQuadStep"]),
1182  Iteration("detachedTripletStep",
1183  selection=["detachedTripletStepClassifier1",
1184  "detachedTripletStepClassifier2",
1185  "detachedTripletStep"]),
1186  Iteration("lowPtQuadStep"),
1187  Iteration("lowPtTripletStep"),
1188  Iteration("pixelPairStep"),
1189  Iteration("mixedTripletStep",
1190  seeding=["mixedTripletStepSeedLayersA",
1191  "mixedTripletStepSeedLayersB",
1192  "mixedTripletStepTrackingRegionsA",
1193  "mixedTripletStepTrackingRegionsB",
1194  "mixedTripletStepHitDoubletsA",
1195  "mixedTripletStepHitDoubletsB",
1196  "mixedTripletStepHitTripletsA",
1197  "mixedTripletStepHitTripletsB",
1198  "mixedTripletStepSeedsA",
1199  "mixedTripletStepSeedsB",
1200  "mixedTripletStepSeeds"],
1201  selection=["mixedTripletStepClassifier1",
1202  "mixedTripletStepClassifier2",
1203  "mixedTripletStep"]),
1204  Iteration("pixelLessStep",
1205  selection=["pixelLessStepClassifier1",
1206  "pixelLessStepClassifier2",
1207  "pixelLessStep"]),
1208  Iteration("tobTecStep",
1209  seeding=["tobTecStepSeedLayersTripl",
1210  "tobTecStepSeedLayersPair",
1211  "tobTecStepTrackingRegionsTripl",
1212  "tobTecStepTrackingRegionsPair",
1213  "tobTecStepHitDoubletsTripl",
1214  "tobTecStepHitDoubletsPair",
1215  "tobTecStepHitTripletsTripl",
1216  "tobTecStepSeedsTripl",
1217  "tobTecStepSeedsPair",
1218  "tobTecStepSeeds"],
1219  selection=["tobTecStepClassifier1",
1220  "tobTecStepClassifier2",
1221  "tobTecStep"]),
1222  Iteration("jetCoreRegionalStep",
1223  clusterMasking=[],
1224  other=["initialStepTrackRefsForJets",
1225  "caloJetsForTrk",
1226  "jetsForCoreTracking",
1227  "firstStepGoodPrimaryVertices",
1228  ]),
1229  Iteration("muonSeededSteps",
1230  clusterMasking=[],
1231  seeding=["muonSeededSeedsInOut",
1232  "muonSeededSeedsOutIn"],
1233  building=["muonSeededTrackCandidatesInOut",
1234  "muonSeededTrackCandidatesOutIn"],
1235  fit=["muonSeededTracksInOut",
1236  "muonSeededTracksOutIn"],
1237  selection=["muonSeededTracksInOutClassifier",
1238  "muonSeededTracksOutIntClassifier"],
1239 # other=["earlyMuons"]
1240  ),
1241  Iteration("duplicateMerge",
1242  clusterMasking=[], seeding=[],
1243  building=["duplicateTrackCandidates"],
1244  fit=["mergedDuplicateTracks"],
1245  selection=["duplicateTrackClassifier"]),
1246  Iteration("generalTracks",
1247  clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1248  other=["preDuplicateMergingGeneralTracks",
1249  "generalTracks"]),
1250  Iteration("ConvStep",
1251  clusterMasking=["convClusters"],
1252  seeding=["convLayerPairs",
1253  "photonConvTrajSeedFromSingleLeg"],
1254  building=["convTrackCandidates"],
1255  fit=["convStepTracks"],
1256  selection=["convStepSelector"]),
1257  Iteration("Other", clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
1258  other=["trackerClusterCheckPreSplitting",
1259  "trackerClusterCheck"]),
1260 ]
1261 
1262 def _iterModuleMap(includeConvStep=True, onlyConvStep=False):
1263  iterations = _iterations
1264  if not includeConvStep:
1265  iterations = filter(lambda i: i.name() != "ConvStep", iterations)
1266  if onlyConvStep:
1267  iterations = filter(lambda i: i.name() == "ConvStep", iterations)
1268  return collections.OrderedDict([(i.name(), i.all()) for i in iterations])
1270  def getProp(prop):
1271  ret = []
1272  for i in _iterations:
1273  if i.name() == "ConvStep":
1274  continue
1275  ret.extend(getattr(i, prop)())
1276  return ret
1277 
1278  return collections.OrderedDict([
1279  ("ClusterMask", getProp("clusterMasking")),
1280  ("Seeding", getProp("seeding")),
1281  ("Building", getProp("building")),
1282  ("Fitting", getProp("fit")),
1283  ("Selection", getProp("selection")),
1284  ("Other", getProp("other"))
1285  ])
1286 
1288  def __init__(self):
1290  self._page = "timing"
1291  self._section = "timing"
1292 
1293  def getPurpose(self):
1294  return self._purpose
1295 
1296  def getPage(self):
1297  return self._page
1298 
1299  def getSection(self, dqmSubFolder):
1300  return self._section
1301 
1302  def create(self, tdirectory):
1303  h = tdirectory.Get("reconstruction_step_module_average")
1304  totalReco = None
1305  if h:
1306  totalReco = "%.1f" % h.Integral()
1307 
1308  creator = AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(includeConvStep=False), ignoreMissingBins=True)
1309  h = creator.create(tdirectory)
1310  totalTracking = None
1311  if h:
1312  totalTracking = "%.1f" % h.Integral()
1313 
1314  creator = AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(onlyConvStep=True), ignoreMissingBins=True)
1315  h = creator.create(tdirectory)
1316  totalConvStep = None
1317  if h:
1318  totalConvStep = "%.1f" % h.Integral()
1319 
1320  return [
1321  totalReco,
1322  totalTracking,
1323  totalConvStep,
1324  ]
1325 
1326  def headers(self):
1327  return [
1328  "Average reco time / event (ms)",
1329  "Average tracking (w/o convStep) time / event (ms)",
1330  "Average convStep time / event (ms)",
1331  ]
1333  def __init__(self, name, timeHisto, selectedTracks=False):
1334  self._name = name
1335  self._timeHisto = timeHisto
1336  self._selectedTracks = selectedTracks
1337 
1338  def __str__(self):
1339  return self._name
1340 
1341  def _getDirectory(self, tfile):
1342  for dirName in _trackingFolders():
1343  tdir = tfile.Get(dirName)
1344  if tdir != None:
1345  return tdir
1346  return None
1347 
1348  def create(self, tdirectory):
1349  timeTh1 = plotting._getOrCreateObject(tdirectory, self._timeHisto)
1350  if timeTh1 is None:
1351  return None
1352 
1353  # this is bit of a hack, but as long as it is needed only
1354  # here, I won't invest in better solution
1355  tfile = tdirectory.GetFile()
1356  trkDir = self._getDirectory(tfile)
1357  if trkDir is None:
1358  return None
1359 
1360  iterMap = copy.copy(_collLabelMapHp)
1361  del iterMap["generalTracks"]
1362  del iterMap["jetCoreRegionalStep"] # this is expensive per track on purpose
1363  if self._selectedTracks:
1364  renameBin = lambda bl: _summaryBinRename(bl, highPurity=True, byOriginalAlgo=False, byAlgoMask=True, ptCut=False, seeds=False)
1365  else:
1366  renameBin = lambda bl: _summaryBinRename(bl, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False)
1367  recoAB = AggregateBins("tmp", "num_reco_coll", mapping=iterMap,ignoreMissingBins=True, renameBin=renameBin)
1368  h_reco_per_iter = recoAB.create(trkDir)
1369  if h_reco_per_iter is None:
1370  return None
1371  values = {}
1372  for i in xrange(1, h_reco_per_iter.GetNbinsX()+1):
1373  values[h_reco_per_iter.GetXaxis().GetBinLabel(i)] = h_reco_per_iter.GetBinContent(i)
1374 
1375 
1376  result = []
1377  for i in xrange(1, timeTh1.GetNbinsX()+1):
1378  iterName = timeTh1.GetXaxis().GetBinLabel(i)
1379  if iterName in values:
1380  ntrk = values[iterName]
1381  result.append( (iterName,
1382  timeTh1.GetBinContent(i)/ntrk if ntrk > 0 else 0,
1383  timeTh1.GetBinError(i)/ntrk if ntrk > 0 else 0) )
1384 
1385  if len(result) == 0:
1386  return None
1387 
1388  res = ROOT.TH1F(self._name, self._name, len(result), 0, len(result))
1389  for i, (label, value, error) in enumerate(result):
1390  res.GetXaxis().SetBinLabel(i+1, label)
1391  res.SetBinContent(i+1, value)
1392  res.SetBinError(i+1, error)
1393 
1394  return res
1395 
1396 _common = {
1397  "drawStyle": "P",
1398  "xbinlabelsize": 10,
1399  "xbinlabeloption": "d"
1400 }
1401 _time_per_iter = AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(), ignoreMissingBins=True, originalOrder=True)
1402 _timing_summary = PlotGroup("summary", [
1403  Plot(_time_per_iter,
1404  ytitle="Average processing time (ms)", title="Average processing time / event", legendDx=-0.4, **_common),
1405  Plot(AggregateBins("iteration_fraction", "reconstruction_step_module_average", _iterModuleMap(), ignoreMissingBins=True, originalOrder=True),
1406  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1407  #
1408  Plot(AggregateBins("step", "reconstruction_step_module_average", _stepModuleMap(), ignoreMissingBins=True),
1409  ytitle="Average processing time (ms)", title="Average processing time / event", **_common),
1410  Plot(AggregateBins("step_fraction", "reconstruction_step_module_average", _stepModuleMap(), ignoreMissingBins=True),
1411  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1412  #
1413  Plot(TimePerTrackPlot("iteration_track", _time_per_iter, selectedTracks=False),
1414  ytitle="Average time / built track (ms)", title="Average time / built track", **_common),
1415  Plot(TimePerTrackPlot("iteration_trackhp", _time_per_iter, selectedTracks=True),
1416  ytitle="Average time / selected track (ms)", title="Average time / selected HP track by algoMask", **_common),
1417 # Plot(AggregateBins("iterative_norm", "reconstruction_step_module_average", _iterModuleMap), ytitle="Average processing time", title="Average processing time / event (normalized)", drawStyle="HIST", xbinlabelsize=0.03, normalizeToUnitArea=True)
1418 # Plot(AggregateBins("iterative_norm", "reconstruction_step_module_average", _iterModuleMap, normalizeTo="ak7CaloJets"), ytitle="Average processing time / ak7CaloJets", title="Average processing time / event (normalized to ak7CaloJets)", drawStyle="HIST", xbinlabelsize=0.03)
1419 
1420  ],
1421 )
1422 _timing_iterations = PlotGroup("iterations", [
1423  Plot(AggregateBins(i.name(), "reconstruction_step_module_average", collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1424  ytitle="Average processing time (ms)", title=i.name(), **_common)
1425  for i in _iterations
1426 ],
1427  ncols=4, legend=False
1428 )
1429 _pixelTiming = PlotGroup("pixelTiming", [
1430  Plot(AggregateBins("pixel", "reconstruction_step_module_average", {"pixelTracks": ["pixelTracks"]}), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST")
1431 ])
1432 
1433 _timeFolders = [
1434  "DQMData/Run 1/DQM/Run summary/TimerService/Paths",
1435  "DQMData/Run 1/DQM/Run summary/TimerService/process RECO/Paths",
1436 ]
1437 timePlotter = Plotter()
1438 timePlotter.append("timing", _timeFolders, PlotFolder(
1439  _timing_summary,
1440  _timing_iterations,
1441  # _pixelTiming,
1442  loopSubFolders=False, purpose=PlotPurpose.Timing, page="timing"
1443 ))
1444 timePlotter.appendTable("timing", _timeFolders, TrackingTimingTable())
1445 
1446 _common = {"stat": True, "normalizeToUnitArea": True, "drawStyle": "hist"}
1447 _tplifetime = PlotGroup("tplifetime", [
1448  Plot("TPlip", xtitle="TP lip", **_common),
1449  Plot("TPtip", xtitle="TP tip", **_common),
1450 ])
1451 
1452 tpPlotter = Plotter()
1453 tpPlotter.append("tp", [
1454  "DQMData/Run 1/Tracking/Run summary/TrackingMCTruth/TrackingParticle",
1455  "DQMData/Tracking/TrackingMCTruth/TrackingParticle",
1456 ], PlotFolder(
1457  _tplifetime,
1458 ))
1459 
1460 
def iterSelectionName(self, plotFolderName, translatedDqmSubFolder)
def getSection(self, dqmSubFolder)
def _makeFakeDupPileupPlots(postfix, quantity, unit="", xquantity="", xtitle=None, common={})
def _getOrCreateObject(tdirectory, nameOrCreator)
Definition: plotting.py:53
def _iterModuleMap(includeConvStep=True, onlyConvStep=False)
def replace(string, replacements)
def _makeDistSimPlots(postfix, quantity, common={})
def _trackingSubFoldersFallbackSLHC_Phase1PU70_OldMapping(subfolder)
def getSection(self, dqmSubFolder)
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 _trackingSubFoldersFallbackConversion(subfolder)
def _trackingSubFoldersFallbackSLHC_Phase1PU140(subfolder)
def _trackingRefFileFallbackSLHC_Phase1PU70_OldMapping(path)
def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder)
def __init__(self, name, timeHisto, selectedTracks=False)
def _makeMVAPlots(num, hp=False)
def _trackingRefFileFallbackSLHC_Phase1PU140(path)
def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, ptCut=False, seeds=False, midfix="")
def _trackingSubFoldersFallbackFromPV(subfolder)
def _makeDistPlots(postfix, quantity, common={})
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:96
def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, onlyForElectron=False, onlyForConversion=False, seeding=False, rawSummary=False)