test
CMS 3D CMS Logo

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