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 collections
2 
3 from plotting import Subtract, FakeDuplicate, AggregateBins, ROC, Plot, PlotGroup, PlotFolder, Plotter
4 import validation
5 from html import PlotPurpose
6 
7 ########################################
8 #
9 # Per track collection plots
10 #
11 ########################################
12 
13 _maxEff = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025]
14 _maxFake = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 0.8, 1.025]
15 
16 #_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]
17 _minMaxResol = [1e-5, 4e-5, 1e-4, 4e-4, 1e-3, 4e-3, 1e-2, 4e-2, 0.1, 0.4, 1]
18 _minMaxN = [5e-1, 5, 5e1, 5e2, 5e3, 5e4, 5e5, 5e6, 5e7, 5e8, 5e9]
19 
20 _minHits = [0, 5, 10]
21 _maxHits = [5, 10, 20, 40, 60, 80]
22 _minLayers = [0, 5, 10]
23 _maxLayers = [5, 10, 25]
24 _maxPixelLayers = 8
25 _min3DLayers = [0, 5, 10]
26 _max3DLayers = [5, 10, 20]
27 
28 _legendDy_4rows = 0.09
29 _legendDy_2rows = -0.025
30 _legendDy_2rows_3cols = -0.17
31 
32 
33 _effandfake1 = PlotGroup("effandfake1", [
34  Plot("efficPt", title="Efficiency vs p_{T}", xtitle="TP p_{T} (GeV)", ytitle="efficiency vs p_{T}", xlog=True, ymax=_maxEff),
35  Plot(FakeDuplicate("fakeduprate_vs_pT", assoc="num_assoc(recoToSim)_pT", dup="num_duplicate_pT", reco="num_reco_pT", title="fake+duplicates vs p_{T}"),
36  xtitle="track p_{T} (GeV)", ytitle="fake+duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
37  Plot("effic", xtitle="TP #eta", ytitle="efficiency vs #eta", title="", ymax=_maxEff),
38  Plot(FakeDuplicate("fakeduprate_vs_eta", assoc="num_assoc(recoToSim)_eta", dup="num_duplicate_eta", reco="num_reco_eta", title=""),
39  xtitle="track #eta", ytitle="fake+duplicates rate vs #eta", ymax=_maxFake),
40  Plot("effic_vs_phi", xtitle="TP #phi", ytitle="efficiency vs #phi", ymax=_maxEff),
41  Plot(FakeDuplicate("fakeduprate_vs_phi", assoc="num_assoc(recoToSim)_phi", dup="num_duplicate_phi", reco="num_reco_phi", title="fake+duplicates vs #phi"),
42  xtitle="track #phi", ytitle="fake+duplicates rate vs #phi", ymax=_maxFake),
43 ])
44 
45 _effandfake2 = PlotGroup("effandfake2", [
46  Plot("effic_vs_dxy", title="Efficiency vs dxy", xtitle="TP dxy (cm)", ytitle="efficiency vs dxy", ymax=_maxEff),
47  Plot(FakeDuplicate("fakeduprate_vs_dxy", assoc="num_assoc(recoToSim)_dxy", dup="num_duplicate_dxy", reco="num_reco_dxy", title="fake+duplicates vs dxy"),
48  xtitle="track dxy (cm)", ytitle="fake+duplicates rate vs dxy", ymax=_maxFake),
49  Plot("effic_vs_dxypv", title="Efficiency vs dxy(PV)", xtitle="TP dxy(PV) (cm)", ytitle="efficiency vs dxy(PV)", ymax=_maxEff),
50  Plot(FakeDuplicate("fakeduprate_vs_dxypv", assoc="num_assoc(recoToSim)_dxypv", dup="num_duplicate_dxypv", reco="num_reco_dxypv", title="fake+duplicates vs dxy(PV)"),
51  xtitle="track dxy(PV) (cm)", ytitle="fake+duplicates rate vs dxy(PV)", ymax=_maxFake),
52  Plot("effic_vs_dz", xtitle="TP dz (cm)", ytitle="Efficiency vs dz", title="", ymax=_maxEff),
53  Plot(FakeDuplicate("fakeduprate_vs_dz", assoc="num_assoc(recoToSim)_dz", dup="num_duplicate_dz", reco="num_reco_dz", title=""),
54  xtitle="track dz (cm)", ytitle="fake+duplicates rate vs dz", ymax=_maxFake),
55  Plot("effic_vs_dzpv", xtitle="TP dz(PV) (cm)", ytitle="Efficiency vs dz(PV)", title="", ymax=_maxEff),
56  Plot(FakeDuplicate("fakeduprate_vs_dz(PV)", assoc="num_assoc(recoToSim)_dzpv", dup="num_duplicate_dzpv", reco="num_reco_dzpv", title=""),
57  xtitle="track dz(PV) (cm)", ytitle="fake+duplicates rate vs dz(PV)", ymax=_maxFake),
58 ],
59  legendDy=_legendDy_4rows
60 )
61 _effandfake3 = PlotGroup("effandfake3", [
62  Plot("effic_vs_hit", xtitle="TP hits", ytitle="efficiency vs hits", xmin=_minHits, xmax=_maxHits, ymax=_maxEff),
63  Plot(FakeDuplicate("fakeduprate_vs_hit", assoc="num_assoc(recoToSim)_hit", dup="num_duplicate_hit", reco="num_reco_hit", title="fake+duplicates vs hit"),
64  xtitle="track hits", ytitle="fake+duplicates rate vs hits", xmin=_minHits, xmax=_maxHits, ymax=_maxFake),
65  Plot("effic_vs_layer", xtitle="TP layers", ytitle="efficiency vs layers", xmin=_minLayers, xmax=_maxLayers, ymax=_maxEff),
66  Plot(FakeDuplicate("fakeduprate_vs_layer", assoc="num_assoc(recoToSim)_layer", dup="num_duplicate_layer", reco="num_reco_layer", title="fake+duplicates vs layer"),
67  xtitle="track layers", ytitle="fake+duplicates rate vs layers", xmin=_minLayers, xmax=_maxLayers, ymax=_maxFake),
68  Plot("effic_vs_pixellayer", xtitle="TP pixel layers", ytitle="efficiency vs pixel layers", title="", xmax=_maxPixelLayers, ymax=_maxEff),
69  Plot(FakeDuplicate("fakeduprate_vs_pixellayer", assoc="num_assoc(recoToSim)_pixellayer", dup="num_duplicate_pixellayer", reco="num_reco_pixellayer", title=""),
70  xtitle="track pixel layers", ytitle="fake+duplicates rate vs pixel layers", xmax=_maxPixelLayers, ymax=_maxFake),
71  Plot("effic_vs_3Dlayer", xtitle="TP 3D layers", ytitle="efficiency vs 3D layers", xmin=_min3DLayers, xmax=_max3DLayers, ymax=_maxEff),
72  Plot(FakeDuplicate("fakeduprate_vs_3Dlayer", assoc="num_assoc(recoToSim)_3Dlayer", dup="num_duplicate_3Dlayer", reco="num_reco_3Dlayer", title="fake+duplicates vs 3D layer"),
73  xtitle="track 3D layers", ytitle="fake+duplicates rate vs 3D layers", xmin=_min3DLayers, xmax=_max3DLayers, ymax=_maxFake),
74 ],
75  legendDy=_legendDy_4rows
76 )
77 _common = {"ymin": 0, "ymax": _maxEff}
78 _effandfake4 = PlotGroup("effandfake4", [
79  Plot("effic_vs_vertpos", xtitle="TP vert xy (cm)", ytitle="efficiency vs vert xy", **_common),
80  Plot(FakeDuplicate("fakeduprate_vs_vertpos", assoc="num_assoc(recoToSim)_vertpos", dup="num_duplicate_vertpos", reco="num_reco_vertpos", title="fake+duplicates vs. ref. point xy"),
81  xtitle="track ref. point xy (cm)", ytitle="fake+duplicates vs xy", ymax=_maxFake),
82  Plot("effic_vs_zpos", xtitle="TP vert z (cm)", ytitle="efficiency vs vert z", **_common),
83  Plot(FakeDuplicate("fakeduprate_vs_zpos", assoc="num_assoc(recoToSim)_zpos", dup="num_duplicate_zpos", reco="num_reco_zpos", title="fake+duplicates vs. ref. point z"),
84  xtitle="track ref. point z (cm)", ytitle="fake+duplicates vs z", ymax=_maxFake),
85  Plot("effic_vs_dr", xlog=True, xtitle="TP min #DeltaR", ytitle="efficiency vs dr", **_common),
86  Plot(FakeDuplicate("fakeduprate_vs_dr", assoc="num_assoc(recoToSim)_dr", dup="num_duplicate_dr", reco="num_reco_dr", title="fake+duplicates vs. #DeltaR"),
87  xtitle="track min #DeltaR", ytitle="fake+duplicates vs #DeltaR", xlog=True, ymax=_maxFake),
88 ])
89 
90 _dupandfake1 = PlotGroup("dupandfake1", [
91  Plot("fakeratePt", xtitle="track p_{T} (GeV)", ytitle="fakerate vs p_{T}", xlog=True, ymax=_maxFake),
92  Plot("duplicatesRate_Pt", xtitle="track p_{T} (GeV)", ytitle="duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
93  Plot("pileuprate_Pt", xtitle="track p_{T} (GeV)", ytitle="pileup rate vs p_{T}", ymax=_maxFake, xlog=True),
94  Plot("fakerate", xtitle="track #eta", ytitle="fakerate vs #eta", title="", ymax=_maxFake),
95  Plot("duplicatesRate", xtitle="track #eta", ytitle="duplicates rate vs #eta", title="", ymax=_maxFake),
96  Plot("pileuprate", xtitle="track #eta", ytitle="pileup rate vs #eta", title="", ymax=_maxFake),
97  Plot("fakerate_vs_phi", xtitle="track #phi", ytitle="fakerate vs #phi", ymax=_maxFake),
98  Plot("duplicatesRate_phi", xtitle="track #phi", ytitle="duplicates rate vs #phi", ymax=_maxFake),
99  Plot("pileuprate_phi", xtitle="track #phi", ytitle="pileup rate vs #phi", ymax=_maxFake),
100 ], ncols=3)
101 _dupandfake2 = PlotGroup("dupandfake2", [
102  Plot("fakerate_vs_dxy", xtitle="track dxy (cm)", ytitle="fakerate vs dxy", ymax=_maxFake),
103  Plot("duplicatesRate_dxy", xtitle="track dxy (cm)", ytitle="duplicates rate vs dxy", ymax=_maxFake),
104  Plot("pileuprate_dxy", xtitle="track dxy (cm)", ytitle="pileup rate vs dxy", ymax=_maxFake),
105  #
106  Plot("fakerate_vs_dxypv", xtitle="track dxy(PV) (cm)", ytitle="fakerate vs dxy(PV)", ymax=_maxFake),
107  Plot("duplicatesRate_dxypv", xtitle="track dxy(PV) (cm)", ytitle="duplicates rate vs dxy(PV)", ymax=_maxFake),
108  Plot("pileuprate_dxypv", xtitle="track dxy(PV) (cm)", ytitle="pileup rate vs dxy(PV)", ymax=_maxFake),
109  #
110  Plot("fakerate_vs_dz", xtitle="track dz (cm)", ytitle="fakerate vs dz", title="", ymax=_maxFake),
111  Plot("duplicatesRate_dz", xtitle="track dz (cm)", ytitle="duplicates rate vs dz", title="", ymax=_maxFake),
112  Plot("pileuprate_dz", xtitle="track dz (cm)", ytitle="pileup rate vs dz", title="", ymax=_maxFake),
113  #
114  Plot("fakerate_vs_dzpv", xtitle="track dz(PV) (cm)", ytitle="fakerate vs dz(PV)", title="", ymax=_maxFake),
115  Plot("duplicatesRate_dzpv", xtitle="track dz(PV) (cm)", ytitle="duplicates rate vs dz(PV)", title="", ymax=_maxFake),
116  Plot("pileuprate_dzpv", xtitle="track dz(PV) (cm)", ytitle="pileup rate vs dz(PV)", title="", ymax=_maxFake),
117 ],
118  ncols=3, legendDy=_legendDy_4rows
119 )
120 _dupandfake3 = PlotGroup("dupandfake3", [
121  Plot("fakerate_vs_hit", xtitle="track hits", ytitle="fakerate vs hits", ymax=_maxFake, xmin=_minHits, xmax=_maxHits),
122  Plot("duplicatesRate_hit", xtitle="track hits", ytitle="duplicates rate vs hits", ymax=_maxFake, xmin=_minHits, xmax=_maxHits),
123  Plot("pileuprate_hit", xtitle="track hits", ytitle="pileup rate vs hits", ymax=_maxFake, xmin=_minHits, xmax=_maxHits),
124  #
125  Plot("fakerate_vs_layer", xtitle="track layers", ytitle="fakerate vs layer", ymax=_maxFake, xmin=_minLayers, xmax=_maxLayers),
126  Plot("duplicatesRate_layer", xtitle="track layers", ytitle="duplicates rate vs layers", ymax=_maxFake, xmin=_minLayers, xmax=_maxLayers),
127  Plot("pileuprate_layer", xtitle="track layers", ytitle="pileup rate vs layers", ymax=_maxFake, xmin=_minLayers, xmax=_maxLayers),
128  #
129  Plot("fakerate_vs_pixellayer", xtitle="track pixel layers", ytitle="fakerate vs pixel layers", title="", ymax=_maxFake, xmax=_maxPixelLayers),
130  Plot("duplicatesRate_pixellayer", xtitle="track pixel layers", ytitle="duplicates rate vs pixel layers", title="", ymax=_maxFake, xmax=_maxPixelLayers),
131  Plot("pileuprate_pixellayer", xtitle="track pixel layers", ytitle="pileup rate vs pixel layers", title="", ymax=_maxFake, xmax=_maxPixelLayers),
132  #
133  Plot("fakerate_vs_3Dlayer", xtitle="track 3D layers", ytitle="fakerate vs 3D layers", ymax=_maxFake, xmin=_min3DLayers, xmax=_max3DLayers),
134  Plot("duplicatesRate_3Dlayer", xtitle="track 3D layers", ytitle="duplicates rate vs 3D layers", ymax=_maxFake, xmin=_min3DLayers, xmax=_max3DLayers),
135  Plot("pileuprate_3Dlayer", xtitle="track 3D layers", ytitle="pileup rate vs 3D layers", ymax=_maxFake, xmin=_min3DLayers, xmax=_max3DLayers)
136 ],
137  ncols=3, legendDy=_legendDy_4rows
138 )
139 _dupandfake4 = PlotGroup("dupandfake4", [
140  Plot("fakerate_vs_vertpos", xtitle="track ref. point xy (cm)", ytitle="fakerate vs xy", ymax=_maxFake),
141  Plot("duplicatesRate_vertpos", xtitle="track ref. point xy (cm)", ytitle="duplicates rate vs xy", ymax=_maxFake),
142  Plot("pileuprate_vertpos", xtitle="track ref. point xy (cm)", ytitle="pileup rate vs xy", ymax=_maxFake),
143  #
144  Plot("fakerate_vs_zpos", xtitle="track ref. point z (cm)", ytitle="fakerate vs z", ymax=_maxFake),
145  Plot("duplicatesRate_zpos", xtitle="track ref. point z (cm)", ytitle="duplicates rate vs z", ymax=_maxFake),
146  Plot("pileuprate_zpos", xtitle="track ref. point z (cm)", ytitle="pileup rate vs z", ymax=_maxFake),
147  #
148  Plot("fakerate_vs_dr", xtitle="track min #DeltaR", ytitle="fakerate vs #DeltaR", xlog=True, ymax=_maxFake),
149  Plot("duplicatesRate_dr", xtitle="track min #DeltaR", ytitle="duplicates rate vs #DeltaR", xlog=True, ymax=_maxFake),
150  Plot("pileuprate_dr", xtitle="track min #DeltaR", ytitle="pileup rate vs #DeltaR", xlog=True, ymax=_maxFake),
151  #
152  Plot("fakerate_vs_chi2", xtitle="track #chi^{2}", ytitle="fakerate vs #chi^{2}", ymax=_maxFake),
153  Plot("duplicatesRate_chi2", xtitle="track #chi^{2}", ytitle="duplicates rate vs #chi^{2}", ymax=_maxFake),
154  Plot("pileuprate_chi2", xtitle="track #chi^{2}", ytitle="pileup rate vs #chi^{2}", ymax=_maxFake)
155 ],
156  ncols=3, legendDy=_legendDy_4rows
157 )
158 _common = {
159  "ytitle": "Fake+pileup rate",
160  "ymax": _maxFake,
161  "drawStyle": "EP",
162 }
163 _common2 = {}
164 _common2.update(_common)
165 _common2["drawStyle"] = "pcolz"
166 _common2["ztitleoffset"] = 1.5
167 _common2["xtitleoffset"] = 7
168 _common2["ytitleoffset"] = 10
169 _common2["ztitleoffset"] = 6
170 _pvassociation1 = PlotGroup("pvassociation1", [
171  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")),
172  xtitle="Efficiency vs. cut on dz(PV)", **_common),
173  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),
174  xtitle="Efficiency", ztitle="Cut on dz(PV)", **_common2),
175  #
176  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")),
177  xtitle="Efficiency vs. cut on dz(PV)/dzError", **_common),
178  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),
179  xtitle="Efficiency", ztitle="Cut on dz(PV)/dzError", **_common2),
180  ##
181  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")),
182  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)", **_common),
183  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),
184  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)", **_common2),
185  #
186  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")),
187  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)/dzError", **_common),
188  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),
189  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)/dzError", **_common2),
190 ], onlyForPileup=True,
191  legendDy=_legendDy_4rows
192 )
193 _pvassociation2 = PlotGroup("pvassociation2", [
194  Plot("effic_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency vs. cut on dz(PV)", ymax=_maxEff),
195  Plot("effic_vs_dzpvcut2", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
196  Plot("fakerate_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate vs. cut on dz(PV)", ymax=_maxFake),
197  Plot("pileuprate_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate vs. cut on dz(PV)", ymax=_maxFake),
198  #
199  Plot("effic_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency vs. cut on dz(PV)/dzError", ymax=_maxEff),
200  Plot("effic_vs_dzpvsigcut2", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
201  Plot("fakerate_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
202  Plot("pileuprate_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
203 ], onlyForPileup=True,
204  legendDy=_legendDy_4rows
205 )
206 _pvassociation3 = PlotGroup("pvassociation3", [
207  Plot("effic_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
208  Plot("effic_vs_dzpvcut2_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
209  Plot("fakerate_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
210  Plot("pileuprate_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
211  #
212  Plot("effic_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
213  Plot("effic_vs_dzpvsigcut2_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
214  Plot("fakerate_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
215  Plot("pileuprate_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
216 ], onlyForPileup=True,
217  legendDy=_legendDy_4rows
218 )
219 
220 
221 # These don't exist in FastSim
222 _common = {"normalizeToUnitArea": True, "stat": True, "drawStyle": "hist"}
223 _dedx = PlotGroup("dedx", [
224  Plot("h_dedx_estim1", xtitle="dE/dx, harm2", **_common),
225  Plot("h_dedx_estim2", xtitle="dE/dx, trunc40", **_common),
226  Plot("h_dedx_nom1", xtitle="dE/dx number of measurements", title="", **_common),
227  Plot("h_dedx_sat1", xtitle="dE/dx number of measurements with saturation", title="", **_common),
228  ],
229  legendDy=_legendDy_2rows
230 )
231 
232 _chargemisid = PlotGroup("chargemisid", [
233  Plot("chargeMisIdRate", xtitle="#eta", ytitle="charge mis-id rate vs #eta", ymax=0.05),
234  Plot("chargeMisIdRate_Pt", xtitle="p_{T}", ytitle="charge mis-id rate vs p_{T}", xmax=300, ymax=0.1, xlog=True),
235  Plot("chargeMisIdRate_hit", xtitle="hits", ytitle="charge mis-id rate vs hits", title=""),
236  Plot("chargeMisIdRate_phi", xtitle="#phi", ytitle="charge mis-id rate vs #phi", title="", ymax=0.01),
237  Plot("chargeMisIdRate_dxy", xtitle="dxy", ytitle="charge mis-id rate vs dxy", ymax=0.1),
238  Plot("chargeMisIdRate_dz", xtitle="dz", ytitle="charge mis-id rate vs dz", ymax=0.1)
239 ])
240 _common = {"stat": True, "normalizeToUnitArea": True, "ylog": True, "ymin": 1e-6, "drawStyle": "hist"}
241 _hitsAndPt = PlotGroup("hitsAndPt", [
242  Plot("missing_inner_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
243  Plot("missing_outer_layers", xmin=_minLayers, xmax=_maxLayers, ymax=1, **_common),
244  Plot("hits_eta", stat=True, statx=0.38, xtitle="track #eta", ytitle="<hits> vs #eta", ymin=_minHits, ymax=_maxHits, statyadjust=[0,0,-0.15],
245  fallback={"name": "nhits_vs_eta", "profileX": True}),
246  Plot("hits", stat=True, xtitle="track hits", xmin=_minHits, xmax=_maxHits, ylog=True, ymin=[5e-1, 5, 5e1, 5e2, 5e3], drawStyle="hist"),
247  Plot("num_simul_pT", xtitle="TP p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common),
248  Plot("num_reco_pT", xtitle="track p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common)
249 ])
250 _tuning = PlotGroup("tuning", [
251  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),
252  Plot("chi2_prob", stat=True, normalizeToUnitArea=True, drawStyle="hist", xtitle="Prob(#chi^{2})"),
253  Plot("chi2mean", stat=True, title="", xtitle="#eta", ytitle="< #chi^{2} / ndf >", ymax=2.5,
254  fallback={"name": "chi2_vs_eta", "profileX": True}),
255  Plot("ptres_vs_eta_Mean", stat=True, scale=100, title="", xtitle="#eta", ytitle="< #delta p_{T} / p_{T} > [%]", ymin=-1.5, ymax=1.5)
256 ])
257 _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}
258 _pulls = PlotGroup("pulls", [
259  Plot("pullPt", **_common),
260  Plot("pullQoverp", **_common),
261  Plot("pullPhi", **_common),
262  Plot("pullTheta", **_common),
263  Plot("pullDxy", **_common),
264  Plot("pullDz", **_common),
265 ],
266  legendDx=0.1, legendDw=-0.1, legendDh=-0.015
267 )
268 _common = {"title": "", "ylog": True, "xtitle": "#eta", "ymin": _minMaxResol, "ymax": _minMaxResol}
269 _resolutionsEta = PlotGroup("resolutionsEta", [
270  Plot("phires_vs_eta_Sigma", ytitle="#sigma(#delta #phi) [rad]", **_common),
271  Plot("cotThetares_vs_eta_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
272  Plot("dxyres_vs_eta_Sigma", ytitle="#sigma(#delta d_{0}) [cm]", **_common),
273  Plot("dzres_vs_eta_Sigma", ytitle="#sigma(#delta z_{0}) [cm]", **_common),
274  Plot("ptres_vs_eta_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
275 ])
276 _common = {"title": "", "ylog": True, "xlog": True, "xtitle": "p_{T}", "xmin": 0.1, "xmax": 1000, "ymin": _minMaxResol, "ymax": _minMaxResol}
277 _resolutionsPt = PlotGroup("resolutionsPt", [
278  Plot("phires_vs_pt_Sigma", ytitle="#sigma(#delta #phi) [rad]", **_common),
279  Plot("cotThetares_vs_pt_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
280  Plot("dxyres_vs_pt_Sigma", ytitle="#sigma(#delta d_{0}) [cm]", **_common),
281  Plot("dzres_vs_pt_Sigma", ytitle="#sigma(#delta z_{0}) [cm]", **_common),
282  Plot("ptres_vs_pt_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
283 ])
284 
285 ########################################
286 #
287 # Summary plots
288 #
289 ########################################
290 
291 _possibleTrackingNonIterationColls = [
292  'ak4PFJets',
293  'btvLike',
294 ]
295 _possibleTrackingColls = [
296  'initialStepPreSplitting',
297  'initialStep',
298  'highPtTripletStep', # phase1
299  'lowPtQuadStep', # phase1
300  'lowPtTripletStep',
301  'pixelPairStep',
302  'detachedQuadStep', # phase1
303  'detachedTripletStep',
304  'mixedTripletStepA', # seeds
305  'mixedTripletStepB', # seeds
306  'mixedTripletStep',
307  'pixelLessStep',
308  'tobTecStepPair', # seeds
309  'tobTecStepTripl', # seeds
310  'tobTecStep',
311  'jetCoreRegionalStep',
312  'muonSeededStepInOut',
313  'muonSeededStepOutIn',
314  'duplicateMerge',
315 ] + _possibleTrackingNonIterationColls
316 _possibleTrackingCollsOld = {
317  "Zero" : "iter0",
318  "First" : "iter1",
319  "Second": "iter2",
320  "Third" : "iter3",
321  "Fourth": "iter4",
322  "Fifth" : "iter5",
323  "Sixth" : "iter6",
324  "Seventh": "iter7",
325  "Ninth" : "iter9",
326  "Tenth" : "iter10",
327 }
328 
330  ret = subfolder.replace("trackingParticleRecoAsssociation", "AssociatorByHitsRecoDenom")
331  for (old, new) in [("InitialStep", "Zero"),
332  ("LowPtTripletStep", "First"),
333  ("PixelPairStep", "Second"),
334  ("MixedTripletStep", "Fourth"),
335  ("MuonSeededStepInOut", "Ninth"),
336  ("MuonSeededStepOutIn", "Tenth")]:
337  ret = ret.replace(old, new)
338  if ret == subfolder:
339  return None
340  return ret
342  for (old, new) in [("initialStep", "iter0"),
343  ("lowPtTripletStep", "iter1"),
344  ("pixelPairStep", "iter2"),
345  ("mixedTripletStep", "iter4"),
346  ("muonSeededStepInOut", "iter9"),
347  ("muonSeededStepOutIn", "iter10")]:
348  path = path.replace(old, new)
349  return path
350 
352  if "Hp" in collName:
353  quality = "highPurity"
354  else:
355  quality = ""
356  hasPtCut = False
357  if "Pt" in collName:
358  if "Step" in collName:
359  hasPtCut = collName.index("Pt") > collName.index("Step")
360  else:
361  hasPtCut = True
362  collNameNoQuality = collName.replace("Hp", "")
363  if hasPtCut:
364  quality += "Pt"
365  collNameNoQuality = collNameNoQuality.replace("Pt", "")
366  if "ByOriginalAlgo" in collName:
367  quality += "ByOriginalAlgo"
368  collNameNoQuality = collNameNoQuality.replace("ByOriginalAlgo", "")
369  if "ByAlgoMask" in collName:
370  quality += "ByAlgoMask"
371  collNameNoQuality = collNameNoQuality.replace("ByAlgoMask", "")
372  collNameNoQuality = collNameNoQuality.replace("Tracks", "", 1) # make summary naming consistent with iteration folders
373  collNameLow = collNameNoQuality.lower().replace("frompv2", "").replace("frompv", "").replace("frompvalltp", "").replace("alltp", "")
374 
375  if collNameLow.find("seed") == 0:
376  if quality != "":
377  raise Exception("Assumption of empty quality for seeds failed, got quality '%s'" % quality)
378  collNameLow = collNameLow[4:]
379  if collNameLow == "initialstepseedspresplitting":
380  collNameLow = "initialsteppresplittingseeds"
381  elif collNameLow == "muonseededseedsinout":
382  collNameLow = "muonseededstepinoutseeds"
383  elif collNameLow == "muonseededseedsoutin":
384  collNameLow = "muonseededstepoutinseeds"
385 
386  i_seeds = collNameLow.index("seeds")
387  quality = collNameLow[i_seeds:]
388 
389  collNameLow = collNameLow[:i_seeds]
390 
391  algo = None
392  prefixes = ["cutsreco", "cutsrecofrompv", "cutsrecofrompv2", "cutsrecofrompvalltp"]
393  if collNameLow in ["general", "generalfrompv"]+prefixes:
394  algo = "ootb"
395  else:
396  def testColl(coll):
397  for pfx in prefixes:
398  if coll == collNameLow.replace(pfx, ""):
399  return True
400  return False
401 
402  for coll in _possibleTrackingColls:
403  if testColl(coll.lower()):
404  algo = coll
405  break
406  # next try "old style"
407  if algo is None:
408  for coll, name in _possibleTrackingCollsOld.iteritems():
409  if testColl(coll.lower()):
410  algo = name
411  break
412 
413  # fallback
414  if algo is None:
415  algo = collNameNoQuality
416 
417  # fix for track collection naming convention
418  if algo == "muonSeededInOut":
419  algo = "muonSeededStepInOut"
420  if algo == "muonSeededOutIn":
421  algo = "muonSeededStepOutIn"
422 
423  return (algo, quality)
424 
425 def _collhelper(name):
426  return (name, [name])
427 _collLabelMap = collections.OrderedDict(map(_collhelper, ["generalTracks"]+_possibleTrackingColls))
428 _collLabelMapHp = collections.OrderedDict(map(_collhelper, ["generalTracks"]+filter(lambda n: "Step" in n, _possibleTrackingColls)))
429 def _summaryBinRename(binLabel, highPurity, byOriginalAlgo, byAlgoMask, seeds):
430  (algo, quality) = _mapCollectionToAlgoQuality(binLabel)
431  if algo == "ootb":
432  algo = "generalTracks"
433  ret = None
434 
435  if byOriginalAlgo:
436  if algo != "generalTracks" and "ByOriginalAlgo" not in quality:
437  return None
438  quality = quality.replace("ByOriginalAlgo", "")
439  if byAlgoMask:
440  if algo != "generalTracks" and "ByAlgoMask" not in quality:
441  return None
442  quality = quality.replace("ByAlgoMask", "")
443 
444  if highPurity:
445  if quality == "highPurity":
446  ret = algo
447  elif seeds:
448  i_seeds = quality.find("seeds")
449  if i_seeds == 0:
450  ret = algo
451  seedSubColl = quality[i_seeds+5:]
452  if seedSubColl != "":
453  ret += seedSubColl[0].upper() + seedSubColl[1:]
454  else:
455  if quality == "":
456  ret = algo
457 
458  return ret
459 
460 def _constructSummary(mapping=None, highPurity=False, byOriginalAlgo=False, byAlgoMask=False, seeds=False, midfix=""):
461  _common = {"drawStyle": "EP", "xbinlabelsize": 10, "xbinlabeloption": "d"}
462  _commonN = {"ylog": True, "ymin": _minMaxN, "ymax": _minMaxN}
463  _commonN.update(_common)
464  _commonAB = {"mapping": mapping,
465  "renameBin": lambda bl: _summaryBinRename(bl, highPurity, byOriginalAlgo, byAlgoMask, seeds),
466  "ignoreMissingBins": True,
467  }
468  if byOriginalAlgo or byAlgoMask:
469  _commonAB["minExistingBins"] = 2
470  prefix = "summary"+midfix
471 
472  h_eff = "effic_vs_coll"
473  h_eff_allpt = "effic_vs_coll_allPt"
474  h_fakerate = "fakerate_vs_coll"
475  h_duplicaterate = "duplicatesRate_coll"
476  h_pileuprate = "pileuprate_coll"
477 
478  h_reco = "num_reco_coll"
479  h_true = "num_assoc(recoToSim)_coll"
480  h_fake = Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll")
481  h_duplicate = "num_duplicate_coll"
482  h_pileup = "num_pileup_coll"
483  if mapping is not None:
484  h_eff = AggregateBins("efficiency", h_eff, **_commonAB)
485  h_eff_allpt = AggregateBins("efficiencyAllPt", h_eff_allpt, **_commonAB)
486  h_fakerate = AggregateBins("fakerate", h_fakerate, **_commonAB)
487  h_duplicaterate = AggregateBins("duplicatesRate", h_duplicaterate, **_commonAB)
488  h_pileuprate = AggregateBins("pileuprate", h_pileuprate, **_commonAB)
489 
490  h_reco = AggregateBins("num_reco_coll", h_reco, **_commonAB)
491  h_true = AggregateBins("num_true_coll", h_true, **_commonAB)
492  h_fake = AggregateBins("num_fake_coll", h_fake, **_commonAB)
493  h_duplicate = AggregateBins("num_duplicate_coll", h_duplicate, **_commonAB)
494  h_pileup = AggregateBins("num_pileup_coll", h_pileup, **_commonAB)
495 
496  summary = PlotGroup(prefix, [
497  Plot(h_eff, title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
498  Plot(h_eff_allpt, title="Efficiency vs collection (no pT cut in denominator)", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
499 
500  Plot(h_fakerate, title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
501  Plot(h_duplicaterate, title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
502  Plot(h_pileuprate, title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
503  ])
504  summaryN = PlotGroup(prefix+"_ntracks", [
505  Plot(h_reco, ytitle="Tracks", title="Number of tracks vs collection", **_commonN),
506  Plot(h_true, ytitle="True tracks", title="Number of true tracks vs collection", **_commonN),
507  Plot(h_fake, ytitle="Fake tracks", title="Number of fake tracks vs collection", **_commonN),
508  Plot(h_duplicate, ytitle="Duplicate tracks", title="Number of duplicate tracks vs collection", **_commonN),
509  Plot(h_pileup, ytitle="Pileup tracks", title="Number of pileup tracks vs collection", **_commonN),
510  ])
511 
512  return (summary, summaryN)
513 
514 (_summaryRaw, _summaryRawN) = _constructSummary(midfix="Raw")
515 (_summary, _summaryN) = _constructSummary(_collLabelMap)
516 (_summaryHp, _summaryNHp) = _constructSummary(_collLabelMapHp, highPurity=True)
517 (_summaryByOriginalAlgo, _summaryByOriginalAlgoN) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo")
518 (_summaryByOriginalAlgoHp, _summaryByOriginalAlgoNHp) = _constructSummary(_collLabelMapHp, byOriginalAlgo=True, midfix="ByOriginalAlgo", highPurity=True)
519 (_summaryByAlgoMask, _summaryByAlgoMaskN) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask")
520 (_summaryByAlgoMaskHp, _summaryByAlgoMaskNHp) = _constructSummary(_collLabelMapHp, byAlgoMask=True, midfix="ByAlgoMask", highPurity=True)
521 (_summarySeeds, _summarySeedsN) = _constructSummary(_collLabelMapHp, seeds=True)
522 
523 ########################################
524 #
525 # PackedCandidate plots
526 #
527 ########################################
528 
529 _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]}
530 _commonStatus = {}
531 _commonStatus.update(_common)
532 _commonStatus.update({"xbinlabelsize": 10, "xbinlabeloption": "d", "drawStyle": "hist", "adjustMarginRight": 0.08})
533 _commonLabelSize = {}
534 _commonLabelSize.update(_common)
535 _commonLabelSize.update({"xlabelsize": 17})
536 
537 _packedCandidateFlow = PlotGroup("flow", [
538  Plot("selectionFlow", xbinlabelsize=10, xbinlabeloption="d", adjustMarginRight=0.1, drawStyle="hist", ylog=True, ymin=[0.9, 9, 9e1, 9e2, 9e3, 9e4, 9e5, 9e6, 9e7]),
539  Plot("diffCharge", xtitle="Charge", **_common),
540  Plot("diffIsHighPurity", xtitle="High purity status", **_common),
541  Plot("diffNdof", xtitle="ndof", **_common),
542  Plot("diffNormalizedChi2", xtitle="#chi^{2}/ndof", **_common),
543 ])
544 
545 _packedCandidateHitsHitPattern = PlotGroup("hitsHitPattern", [
546  Plot("diffHitPatternNumberOfValidHits", xtitle="Valid hits (via HitPattern)", **_common),
547  Plot("diffHitPatternNumberOfValidPixelHits", xtitle="Valid pixel hits (via HitPattern)", **_common),
548  Plot("diffHitPatternHasValidHitInFirstPixelBarrel", xtitle="Has valid hit in BPix1 layer (via HitPattern)", **_common),
549  Plot("diffHitPatternNumberOfLostPixelHits", xtitle="Lost pixel hits (via HitPattern)", **_common),
550 ],
551  legendDy=_legendDy_2rows
552 )
553 _packedCandidateHits = PlotGroup("hits", [
554  Plot("diffNumberOfHits", xtitle="Hits", **_common),
555  Plot("diffNumberOfPixelHits", xtitle="Pixel hits", **_common),
556  Plot("diffLostInnerHits", xtitle="Lost inner hits", **_common),
557  Plot("numberHitsOverMax", xtitle="Number of overflown hits", **_common),
558  Plot("numberPixelHitsOverMax", xtitle="Number of overflown pixel hits", **_common),
559  Plot("numberStripHitsOverMax", xtitle="Number of overflown strip hits", **_common),
560 ],
561  ncols=3, legendDy=_legendDy_2rows_3cols
562 )
563 
564 _packedCandidateImpactParameter1 = PlotGroup("impactParameter1", [
565  Plot("diffDxyAssocPV", xtitle="dxy(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
566  Plot("diffDxyAssocPVStatus", **_commonStatus),
567  Plot("diffDxyAssocPVUnderOverFlowSign", xtitle="dxy(assocPV)", **_common),
568  Plot("diffDzAssocPV", xtitle="dz(assocPV)", adjustMarginRight=0.02, **_commonLabelSize),
569  Plot("diffDzAssocPVStatus", **_commonStatus),
570  Plot("diffDzAssocPVUnderOverFlowSign", xtitle="dz(assocPV)", **_common),
571  Plot("diffDxyError", xtitle="dxyError()", adjustMarginRight=0.02, **_commonLabelSize),
572  Plot("diffDszError", xtitle="dszError()", adjustMarginRight=0.02, **_commonLabelSize),
573  Plot("diffDzError", xtitle="dzError()", adjustMarginRight=0.02, **_commonLabelSize),
574 
575 ],
576  ncols=3
577 )
578 
579 _packedCandidateImpactParameter2 = PlotGroup("impactParameter2", [
580  Plot("diffDxyPV", xtitle="dxy(PV) via PC", **_commonLabelSize),
581  Plot("diffDzPV", xtitle="dz(PV) via PC", **_commonLabelSize),
582  Plot("diffTrackDxyAssocPV", xtitle="dxy(PV) via PC::bestTrack()", **_commonLabelSize),
583  Plot("diffTrackDzAssocPV", xtitle="dz(PV) via PC::bestTrack()", **_commonLabelSize),
584  Plot("diffTrackDxyError", xtitle="dxyError() via PC::bestTrack()", adjustMarginRight=0.02, **_commonLabelSize),
585  Plot("diffTrackDzError", xtitle="dzError() via PC::bestTrack()", **_commonLabelSize),
586 ])
587 
588 _packedCandidateCovarianceMatrix1 = PlotGroup("covarianceMatrix1", [
589  Plot("diffCovQoverpQoverp", xtitle="cov(qoverp, qoverp)", **_commonLabelSize),
590  Plot("diffCovQoverpQoverpStatus", **_commonStatus),
591  Plot("diffCovQoverpQoverpUnderOverFlowSign", xtitle="cov(qoverp, qoverp)", **_common),
592  Plot("diffCovLambdaLambda", xtitle="cov(lambda, lambda)", **_commonLabelSize),
593  Plot("diffCovLambdaLambdaStatus", **_commonStatus),
594  Plot("diffCovLambdaLambdaUnderOverFlowSign", xtitle="cov(lambda, lambda)", **_common),
595  Plot("diffCovLambdaDsz", xtitle="cov(lambda, dsz)", **_commonLabelSize),
596  Plot("diffCovLambdaDszStatus", **_commonStatus),
597  Plot("diffCovLambdaDszUnderOverFlowSign", xtitle="cov(lambda, dsz)", **_common),
598  Plot("diffCovPhiPhi", xtitle="cov(phi, phi)", **_commonLabelSize),
599  Plot("diffCovPhiPhiStatus", **_commonStatus),
600  Plot("diffCovPhiPhiUnderOverFlowSign", xtitle="cov(phi, phi)", **_common),
601 ],
602  ncols=3, legendDy=_legendDy_4rows
603 )
604 _packedCandidateCovarianceMatrix2 = PlotGroup("covarianceMatrix2", [
605  Plot("diffCovPhiDxy", xtitle="cov(phi, dxy)", **_commonLabelSize),
606  Plot("diffCovPhiDxyStatus", **_commonStatus),
607  Plot("diffCovPhiDxyUnderOverFlowSign", xtitle="cov(phi, dxy)", **_common),
608  Plot("diffCovDxyDxy", xtitle="cov(dxy, dxy)", adjustMarginRight=0.02, **_commonLabelSize),
609  Plot("diffCovDxyDxyStatus", **_commonStatus),
610  Plot("diffCovDxyDxyUnderOverFlowSign", xtitle="cov(dxy, dxy)", **_common),
611  Plot("diffCovDxyDsz", xtitle="cov(dxy, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
612  Plot("diffCovDxyDszStatus", **_commonStatus),
613  Plot("diffCovDxyDszUnderOverFlowSign", xtitle="cov(dxy, dsz)", **_common),
614  Plot("diffCovDszDsz", xtitle="cov(dsz, dsz)", adjustMarginRight=0.02, **_commonLabelSize),
615  Plot("diffCovDszDszStatus", **_commonStatus),
616  Plot("diffCovDszDszUnderOverFlowSign", xtitle="cov(dsz, dsz)", **_common),
617 ],
618  ncols=3, legendDy=_legendDy_4rows
619 )
620 
621 _common["xlabelsize"] = 16
622 _packedCandidateVertex = PlotGroup("vertex", [
623  Plot("diffVx", xtitle="Reference point x", **_common),
624  Plot("diffVy", xtitle="Reference point y", **_common),
625  Plot("diffVz", xtitle="Reference point z", **_common),
626 ],
627  legendDy=_legendDy_2rows
628 )
629 
630 _common["adjustMarginRight"] = 0.05
631 _packedCandidateKinematics = PlotGroup("kinematics", [
632  Plot("diffPt", xtitle="p_{T}", **_common),
633  Plot("diffPtError", xtitle="p_{T} error", **_common),
634  Plot("diffEta", xtitle="#eta", **_common),
635  Plot("diffEtaError", xtitle="#eta error", **_common),
636  Plot("diffPhi", xtitle="#phi", **_common),
637 ])
638 
640  def __init__(self, *args, **kwargs):
641  self._fallbackRefFiles = kwargs.pop("fallbackRefFiles", [])
642  PlotFolder.__init__(self, *args, **kwargs)
643 
644  def translateSubFolder(self, dqmSubFolderName):
645  spl = dqmSubFolderName.split("_")
646  if len(spl) != 2:
647  return None
648  collName = spl[0]
649  return _mapCollectionToAlgoQuality(collName)
650 
651  def iterSelectionName(self, plotFolderName, translatedDqmSubFolder):
652  (algoOrig, quality) = translatedDqmSubFolder
653 
654  for fallback in [lambda n: n]+self._fallbackRefFiles:
655  algo = fallback(algoOrig)
656 
657  ret = ""
658  if plotFolderName != "":
659  ret += "_"+plotFolderName
660  if quality != "":
661  ret += "_"+quality
662  if not (algo == "ootb" and quality != ""):
663  ret += "_"+algo
664  yield ret
665 
666  def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder):
667  """Return True if this subfolder should be processed
668 
669  Arguments:
670  limitOnlyTo -- Function '(algo, quality) -> bool'
671  translatedDqmSubFolder -- Return value of translateSubFolder
672  """
673  (algo, quality) = translatedDqmSubFolder
674  return limitOnlyTo(algo, quality)
675 
676  # track-specific hack
677  def isAlgoIterative(self, algo):
678  return algo not in _possibleTrackingNonIterationColls
679 
681  def __init__(self, section, highPurity=False):
682  self._highPurity = highPurity
684  self._page = "summary"
685  self._section = section
686 
687  def getPurpose(self):
688  return self._purpose
689 
690  def getPage(self):
691  return self._page
692 
693  def getSection(self, dqmSubFolder):
694  return self._section
695 
696  def create(self, tdirectory):
697  def _getN(hname):
698  h = tdirectory.Get(hname)
699  if not h:
700  return None
701  if self._highPurity:
702  (algo, quality) = _mapCollectionToAlgoQuality(h.GetXaxis().GetBinLabel(2))
703  if algo != "ootb" and quality != "highPurity":
704  return None
705  return h.GetBinContent(2)
706  else:
707  (algo, quality) = _mapCollectionToAlgoQuality(h.GetXaxis().GetBinLabel(1))
708  if algo != "ootb" and quality != "":
709  return None
710  return h.GetBinContent(1)
711  def _formatOrNone(num, func):
712  if num is None:
713  return None
714  return func(num)
715 
716  n_tracks = _formatOrNone(_getN("num_reco_coll"), int)
717  n_true = _formatOrNone(_getN("num_assoc(recoToSim)_coll"), int)
718  if n_tracks is not None and n_true is not None:
719  n_fake = n_tracks-n_true
720  else:
721  n_fake = None
722  n_pileup = _formatOrNone(_getN("num_pileup_coll"), int)
723  n_duplicate = _formatOrNone(_getN("num_duplicate_coll"), int)
724 
725  eff = _formatOrNone(_getN("effic_vs_coll"), lambda n: "%.4f" % n)
726 
727  ret = [eff, n_tracks, n_true, n_fake, n_pileup, n_duplicate]
728  if ret.count(None) == len(ret):
729  return None
730  return ret
731 
732  def headers(self):
733  return [
734  "Efficiency",
735  "Number of tracks",
736  "Number of true tracks",
737  "Number of fake tracks",
738  "Number of pileup tracks",
739  "Number of duplicate tracks"
740  ]
741 
742 def _trackingFolders(lastDirName="Track"):
743  return [
744  "DQMData/Run 1/Tracking/Run summary/"+lastDirName,
745  "DQMData/Tracking/"+lastDirName,
746  "DQMData/Run 1/RecoTrackV/Run summary/"+lastDirName,
747  "DQMData/RecoTrackV/"+lastDirName,
748  ]
749 
750 _simBasedPlots = [
751  _effandfake1,
752  _effandfake2,
753  _effandfake3,
754  _effandfake4,
755 ]
756 _recoBasedPlots = [
757  _dupandfake1,
758  _dupandfake2,
759  _dupandfake3,
760  _dupandfake4,
761  _pvassociation1,
762  _pvassociation2,
763  _pvassociation3,
764  _dedx,
765 # _chargemisid,
766  _hitsAndPt,
767  _pulls,
768  _resolutionsEta,
769  _resolutionsPt,
770  _tuning,
771 ]
772 _seedingBuildingPlots = _simBasedPlots + [
773  _dupandfake1,
774  _dupandfake2,
775  _dupandfake3,
776  _dupandfake4,
777  _hitsAndPt,
778 ]
779 _summaryPlots = [
780  _summary,
781  _summaryN,
782  _summaryByOriginalAlgo,
783  _summaryByOriginalAlgoN,
784  _summaryByAlgoMask,
785  _summaryByAlgoMaskN,
786 ]
787 _summaryPlotsHp = [
788  _summaryHp,
789  _summaryNHp,
790  _summaryByOriginalAlgoHp,
791  _summaryByOriginalAlgoNHp,
792  _summaryByAlgoMaskHp,
793  _summaryByAlgoMaskNHp,
794 ]
795 _summaryPlotsSeeds = [
796  _summarySeeds,
797  _summarySeedsN,
798 ]
799 _packedCandidatePlots = [
800  _packedCandidateFlow,
801  _packedCandidateKinematics,
802  _packedCandidateVertex,
803  _packedCandidateImpactParameter1,
804  _packedCandidateImpactParameter2,
805  _packedCandidateCovarianceMatrix1,
806  _packedCandidateCovarianceMatrix2,
807  _packedCandidateHits,
808  _packedCandidateHitsHitPattern,
809 ]
810 plotter = Plotter()
811 def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False, seeding=False, rawSummary=False):
812  # to keep backward compatibility, this set of plots has empty name
813  plotter.append(name, _trackingFolders(lastDirName), TrackingPlotFolder(*algoPlots, onlyForPileup=onlyForPileup, purpose=PlotPurpose.TrackingIteration, fallbackRefFiles=[_trackingRefFileFallbackSLHC]), fallbackDqmSubFolders=[_trackingSubFoldersFallbackSLHC])
814  summaryName = ""
815  if name != "":
816  summaryName += name+"_"
817  summaryName += "summary"
818  summaryPlots = []
819  if rawSummary:
820  summaryPlots.extend([_summaryRaw, _summaryRawN])
821  summaryPlots.extend(_summaryPlots)
822  plotter.append(summaryName, _trackingFolders(lastDirName),
823  PlotFolder(*summaryPlots, loopSubFolders=False, onlyForPileup=onlyForPileup,
824  purpose=PlotPurpose.TrackingSummary, page="summary", section=name))
825  plotter.append(summaryName+"_highPurity", _trackingFolders(lastDirName),
826  PlotFolder(*_summaryPlotsHp, loopSubFolders=False, onlyForPileup=onlyForPileup,
827  purpose=PlotPurpose.TrackingSummary, page="summary",
828  section=name+"_highPurity" if name != "" else "highPurity"),
829  fallbackNames=[summaryName]) # backward compatibility for release validation, the HP plots used to be in the same directory with all-track plots
830  if seeding:
831  plotter.append(summaryName+"_seeds", _trackingFolders(lastDirName),
832  PlotFolder(*_summaryPlotsSeeds, loopSubFolders=False, onlyForPileup=onlyForPileup,
833  purpose=PlotPurpose.TrackingSummary, page="summary",
834  section=name+"_seeds"))
835 
836  plotter.appendTable(summaryName, _trackingFolders(lastDirName), TrackingSummaryTable(section=name))
837  plotter.appendTable(summaryName+"_highPurity", _trackingFolders(lastDirName), TrackingSummaryTable(section=name+"_highPurity" if name != "" else "highPurity", highPurity=True))
838 _appendTrackingPlots("Track", "", _simBasedPlots+_recoBasedPlots)
839 _appendTrackingPlots("TrackAllTPEffic", "allTPEffic", _simBasedPlots, onlyForPileup=True)
840 _appendTrackingPlots("TrackFromPV", "fromPV", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
841 _appendTrackingPlots("TrackFromPVAllTP", "fromPVAllTP", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
842 _appendTrackingPlots("TrackFromPVAllTP2", "fromPVAllTP2", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
843 _appendTrackingPlots("TrackSeeding", "seeding", _seedingBuildingPlots, seeding=True)
844 _appendTrackingPlots("TrackBuilding", "building", _seedingBuildingPlots)
845 _appendTrackingPlots("TrackConversion", "conversion", _simBasedPlots+_recoBasedPlots, rawSummary=True)
846 
847 # MiniAOD
848 plotter.append("packedCandidate", _trackingFolders("PackedCandidate"),
849  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
850  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate"))
851 plotter.append("packedCandidateLostTracks", _trackingFolders("PackedCandidate/lostTracks"),
852  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
853  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate (lostTracks)"))
854 
855 # Timing
856 class Iteration:
857  def __init__(self, name, clusterMasking=None, seeding=None, building=None, fit=None, selection=None, other=[]):
858  self._name = name
859 
860  def _set(param, name, modules):
861  if param is not None:
862  setattr(self, name, param)
863  else:
864  setattr(self, name, modules)
865 
866  _set(clusterMasking, "_clusterMasking", [self._name+"Clusters"])
867  _set(seeding, "_seeding", [self._name+"SeedingLayers", self._name+"Seeds"])
868  _set(building, "_building", [self._name+"TrackCandidates"])
869  _set(fit, "_fit", [self._name+"Tracks"])
870  _set(selection, "_selection", [self._name])
871  self._other = other
872 
873  def name(self):
874  return self._name
875 
876  def all(self):
877  return self._clusterMasking+self._seeding+self._building+self._fit+self._selection+self._other
878 
879  def clusterMasking(self):
880  return self._clusterMasking
881 
882  def seeding(self):
883  return self._seeding
884 
885  def building(self):
886  return self._building
887 
888  def fit(self):
889  return self._fit
890 
891  def selection(self):
892  return self._selection
893 
894  def other(self):
895  return self._other
896 
897  def modules(self):
898  return [("ClusterMask", self.clusterMasking()),
899  ("Seeding", self.seeding()),
900  ("Building", self.building()),
901  ("Fit", self.fit()),
902  ("Selection", self.selection()),
903  ("Other", self.other())]
904 
905 
906 _iterations = [
907  Iteration("initialStepPreSplitting", clusterMasking=[],
908  seeding=["initialStepSeedLayersPreSplitting",
909  "initialStepSeedsPreSplitting"],
910  building=["initialStepTrackCandidatesPreSplitting"],
911  fit=["initialStepTracksPreSplitting"],
912  other=["firstStepPrimaryVerticesPreSplitting",
913  "initialStepTrackRefsForJetsPreSplitting",
914  "caloTowerForTrkPreSplitting",
915  "ak4CaloJetsForTrkPreSplitting",
916  "jetsForCoreTrackingPreSplitting",
917  "siPixelClusters",
918  "siPixelRecHits",
919  "MeasurementTrackerEvent",
920  "siPixelClusterShapeCache"]),
921  Iteration("initialStep", clusterMasking=[],
922  selection=["initialStepClassifier1",
923  "initialStepClassifier2",
924  "initialStepClassifier3",
925  "initialStep"],
926  other=["firstStepPrimaryVertices"]),
927  Iteration("highPtTripletStep",
928  selection=["highPtTripletStepClassifier1",
929  "highPtTripletStepClassifier2",
930  "highPtTripletStepClassifier3",
931  "highPtTripletStep"]),
932  Iteration("detachedQuadStep",
933  selection=["detachedQuadStepClassifier1",
934  "detachedQuadStepClassifier2",
935  "detachedQuadStep"]),
936  Iteration("detachedTripletStep",
937  selection=["detachedTripletStepClassifier1",
938  "detachedTripletStepClassifier2",
939  "detachedTripletStep"]),
940  Iteration("lowPtQuadStep"),
941  Iteration("lowPtTripletStep"),
942  Iteration("pixelPairStep"),
943  Iteration("mixedTripletStep",
944  seeding=["mixedTripletStepSeedLayersA",
945  "mixedTripletStepSeedLayersB",
946  "mixedTripletStepSeedsA",
947  "mixedTripletStepSeedsB",
948  "mixedTripletStepSeeds"],
949  selection=["mixedTripletStepClassifier1",
950  "mixedTripletStepClassifier2",
951  "mixedTripletStep"]),
952  Iteration("pixelLessStep",
953  selection=["pixelLessStepClassifier1",
954  "pixelLessStepClassifier2",
955  "pixelLessStep"]),
956  Iteration("tobTecStep",
957  seeding=["tobTecStepSeedLayersTripl",
958  "tobTecStepSeedLayersPair",
959  "tobTecStepSeedsTripl",
960  "tobTecStepSeedsPair",
961  "tobTecStepSeeds"],
962  selection=["tobTecStepClassifier1",
963  "tobTecStepClassifier2",
964  "tobTecStep"]),
965  Iteration("jetCoreRegionalStep",
966  clusterMasking=[],
967  other=["initialStepTrackRefsForJets",
968  "caloJetsForTrk",
969  "jetsForCoreTracking",
970  "firstStepGoodPrimaryVertices",
971  ]),
972  Iteration("muonSeededSteps",
973  clusterMasking=[],
974  seeding=["muonSeededSeedsInOut",
975  "muonSeededSeedsOutIn"],
976  building=["muonSeededTrackCandidatesInOut",
977  "muonSeededTrackCandidatesOutIn"],
978  fit=["muonSeededTracksInOut",
979  "muonSeededTracksOutIn"],
980  selection=["muonSeededTracksInOutClassifier",
981  "muonSeededTracksOutIntClassifier"],
982 # other=["earlyMuons"]
983  ),
984  Iteration("duplicateMerge",
985  clusterMasking=[], seeding=[],
986  building=["duplicateTrackCandidates"],
987  fit=["mergedDuplicateTracks"],
988  selection=["duplicateTrackClassifier"]),
989  Iteration("generalTracks",
990  clusterMasking=[], seeding=[], building=[], fit=[], selection=[],
991  other=["preDuplicateMergingGeneralTracks",
992  "generalTracks"]),
993  Iteration("ConvStep",
994  clusterMasking=["convClusters"],
995  seeding=["convLayerPairs",
996  "photonConvTrajSeedFromSingleLeg"],
997  building=["convTrackCandidates"],
998  fit=["convStepTracks"],
999  selection=["convStepSelector"]),
1000 ]
1001 
1002 def _iterModuleMap(includeConvStep=True, onlyConvStep=False):
1003  iterations = _iterations
1004  if not includeConvStep:
1005  iterations = filter(lambda i: i.name() != "ConvStep", iterations)
1006  if onlyConvStep:
1007  iterations = filter(lambda i: i.name() == "ConvStep", iterations)
1008  return collections.OrderedDict([(i.name(), i.all()) for i in iterations])
1010  def getProp(prop):
1011  ret = []
1012  for i in _iterations:
1013  if i.name() == "ConvStep":
1014  continue
1015  ret.extend(getattr(i, prop)())
1016  return ret
1017 
1018  return collections.OrderedDict([
1019  ("ClusterMask", getProp("clusterMasking")),
1020  ("Seeding", getProp("seeding")),
1021  ("Building", getProp("building")),
1022  ("Fitting", getProp("fit")),
1023  ("Selection", getProp("selection")),
1024  ("Other", getProp("other"))
1025  ])
1026 
1028  def __init__(self):
1030  self._page = "timing"
1031  self._section = "timing"
1032 
1033  def getPurpose(self):
1034  return self._purpose
1035 
1036  def getPage(self):
1037  return self._page
1038 
1039  def getSection(self, dqmSubFolder):
1040  return self._section
1041 
1042  def create(self, tdirectory):
1043  h = tdirectory.Get("reconstruction_step_module_average")
1044  totalReco = None
1045  if h:
1046  totalReco = "%.1f" % h.Integral()
1047 
1048  creator = AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(includeConvStep=False), ignoreMissingBins=True)
1049  h = creator.create(tdirectory)
1050  totalTracking = None
1051  if h:
1052  totalTracking = "%.1f" % h.Integral()
1053 
1054  creator = AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(onlyConvStep=True), ignoreMissingBins=True)
1055  h = creator.create(tdirectory)
1056  totalConvStep = None
1057  if h:
1058  totalConvStep = "%.1f" % h.Integral()
1059 
1060  return [
1061  totalReco,
1062  totalTracking,
1063  totalConvStep,
1064  ]
1065 
1066  def headers(self):
1067  return [
1068  "Average reco time / event (ms)",
1069  "Average tracking (w/o convStep) time / event (ms)",
1070  "Average convStep time / event (ms)",
1071  ]
1072 
1073 _common = {
1074  "drawStyle": "P",
1075  "xbinlabelsize": 10,
1076  "xbinlabeloption": "d"
1077 }
1078 _timing_summary = PlotGroup("summary", [
1079  Plot(AggregateBins("iteration", "reconstruction_step_module_average", _iterModuleMap(), ignoreMissingBins=True),
1080  ytitle="Average processing time (ms)", title="Average processing time / event", legendDx=-0.4, **_common),
1081  Plot(AggregateBins("iteration_fraction", "reconstruction_step_module_average", _iterModuleMap(), ignoreMissingBins=True),
1082  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1083  #
1084  Plot(AggregateBins("step", "reconstruction_step_module_average", _stepModuleMap(), ignoreMissingBins=True),
1085  ytitle="Average processing time (ms)", title="Average processing time / event", **_common),
1086  Plot(AggregateBins("step_fraction", "reconstruction_step_module_average", _stepModuleMap(), ignoreMissingBins=True),
1087  ytitle="Fraction", title="", normalizeToUnitArea=True, **_common),
1088 # 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)
1089 # 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)
1090 
1091  ],
1092  legendDy=_legendDy_2rows
1093 )
1094 _timing_iterations = PlotGroup("iterations", [
1095  Plot(AggregateBins(i.name(), "reconstruction_step_module_average", collections.OrderedDict(i.modules()), ignoreMissingBins=True),
1096  ytitle="Average processing time (ms)", title=i.name(), **_common)
1097  for i in _iterations
1098 ],
1099  legend=False
1100 )
1101 _pixelTiming = PlotGroup("pixelTiming", [
1102  Plot(AggregateBins("pixel", "reconstruction_step_module_average", {"pixelTracks": ["pixelTracks"]}), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST")
1103 ])
1104 
1105 _timeFolders = [
1106  "DQMData/Run 1/DQM/Run summary/TimerService/Paths",
1107  "DQMData/Run 1/DQM/Run summary/TimerService/process RECO/Paths",
1108 ]
1109 timePlotter = Plotter()
1110 timePlotter.append("timing", _timeFolders, PlotFolder(
1111  _timing_summary,
1112  _timing_iterations,
1113  # _pixelTiming,
1114  loopSubFolders=False, purpose=PlotPurpose.Timing, page="timing"
1115 ))
1116 timePlotter.appendTable("timing", _timeFolders, TrackingTimingTable())
1117 
1118 _common = {"stat": True, "normalizeToUnitArea": True, "drawStyle": "hist"}
1119 _tplifetime = PlotGroup("tplifetime", [
1120  Plot("TPlip", xtitle="TP lip", **_common),
1121  Plot("TPtip", xtitle="TP tip", **_common),
1122 ])
1123 
1124 tpPlotter = Plotter()
1125 tpPlotter.append("tp", [
1126  "DQMData/Run 1/Tracking/Run summary/TrackingMCTruth/TrackingParticle",
1127  "DQMData/Tracking/TrackingMCTruth/TrackingParticle",
1128 ], PlotFolder(
1129  _tplifetime,
1130 ))
1131 
1132 
def _trackingSubFoldersFallbackSLHC
def _appendTrackingPlots
def _trackingRefFileFallbackSLHC
def _mapCollectionToAlgoQuality