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 _effandfake1 = PlotGroup("effandfake1", [
21  Plot("efficPt", title="Efficiency vs p_{T}", xtitle="TP p_{T} (GeV)", ytitle="efficiency vs p_{T}", xlog=True, ymax=_maxEff),
22  Plot(FakeDuplicate("fakeduprate_vs_pT", assoc="num_assoc(recoToSim)_pT", dup="num_duplicate_pT", reco="num_reco_pT", title="fake+duplicates vs p_{T}"),
23  xtitle="track p_{T} (GeV)", ytitle="fake+duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
24  Plot("effic", xtitle="TP #eta", ytitle="efficiency vs #eta", title="", ymax=_maxEff),
25  Plot(FakeDuplicate("fakeduprate_vs_eta", assoc="num_assoc(recoToSim)_eta", dup="num_duplicate_eta", reco="num_reco_eta", title=""),
26  xtitle="track #eta", ytitle="fake+duplicates rate vs #eta", ymax=_maxFake),
27  Plot("effic_vs_phi", xtitle="TP #phi", ytitle="efficiency vs #phi", ymax=_maxEff),
28  Plot(FakeDuplicate("fakeduprate_vs_phi", assoc="num_assoc(recoToSim)_phi", dup="num_duplicate_phi", reco="num_reco_phi", title="fake+duplicates vs #phi"),
29  xtitle="track #phi", ytitle="fake+duplicates rate vs #phi", ymax=_maxFake),
30 ])
31 
32 _effandfake2 = PlotGroup("effandfake2", [
33  Plot("effic_vs_dxy", title="Efficiency vs dxy", xtitle="TP dxy (cm)", ytitle="efficiency vs dxy", ymax=_maxEff),
34  Plot(FakeDuplicate("fakeduprate_vs_dxy", assoc="num_assoc(recoToSim)_dxy", dup="num_duplicate_dxy", reco="num_reco_dxy", title="fake+duplicates vs dxy"),
35  xtitle="track dxy (cm)", ytitle="fake+duplicates rate vs dxy", ymax=_maxFake),
36  Plot("effic_vs_dxypv", title="Efficiency vs dxy(PV)", xtitle="TP dxy(PV) (cm)", ytitle="efficiency vs dxy(PV)", ymax=_maxEff),
37  Plot(FakeDuplicate("fakeduprate_vs_dxypv", assoc="num_assoc(recoToSim)_dxypv", dup="num_duplicate_dxypv", reco="num_reco_dxypv", title="fake+duplicates vs dxy(PV)"),
38  xtitle="track dxy(PV) (cm)", ytitle="fake+duplicates rate vs dxy(PV)", ymax=_maxFake),
39  Plot("effic_vs_dz", xtitle="TP dz (cm)", ytitle="Efficiency vs dz", title="", ymax=_maxEff),
40  Plot(FakeDuplicate("fakeduprate_vs_dz", assoc="num_assoc(recoToSim)_dz", dup="num_duplicate_dz", reco="num_reco_dz", title=""),
41  xtitle="track dz (cm)", ytitle="fake+duplicates rate vs dz", ymax=_maxFake),
42  Plot("effic_vs_dzpv", xtitle="TP dz(PV) (cm)", ytitle="Efficiency vs dz(PV)", title="", ymax=_maxEff),
43  Plot(FakeDuplicate("fakeduprate_vs_dz(PV)", assoc="num_assoc(recoToSim)_dzpv", dup="num_duplicate_dzpv", reco="num_reco_dzpv", title=""),
44  xtitle="track dz(PV) (cm)", ytitle="fake+duplicates rate vs dz(PV)", ymax=_maxFake),
45 ],
46  legendDy=0.09
47 )
48 _effandfake3 = PlotGroup("effandfake3", [
49  Plot("effic_vs_hit", xtitle="TP hits", ytitle="efficiency vs hits", ymax=_maxEff),
50  Plot(FakeDuplicate("fakeduprate_vs_hit", assoc="num_assoc(recoToSim)_hit", dup="num_duplicate_hit", reco="num_reco_hit", title="fake+duplicates vs hit"),
51  xtitle="track hits", ytitle="fake+duplicates rate vs hits", ymax=_maxFake),
52  Plot("effic_vs_layer", xtitle="TP layers", ytitle="efficiency vs layers", xmax=25, ymax=_maxEff),
53  Plot(FakeDuplicate("fakeduprate_vs_layer", assoc="num_assoc(recoToSim)_layer", dup="num_duplicate_layer", reco="num_reco_layer", title="fake+duplicates vs layer"),
54  xtitle="track layers", ytitle="fake+duplicates rate vs layers", ymax=_maxFake, xmax=25),
55  Plot("effic_vs_pixellayer", xtitle="TP pixel layers", ytitle="efficiency vs pixel layers", title="", xmax=6, ymax=_maxEff),
56  Plot(FakeDuplicate("fakeduprate_vs_pixellayer", assoc="num_assoc(recoToSim)_pixellayer", dup="num_duplicate_pixellayer", reco="num_reco_pixellayer", title=""),
57  xtitle="track pixel layers", ytitle="fake+duplicates rate vs pixel layers", ymax=_maxFake, xmax=6),
58  Plot("effic_vs_3Dlayer", xtitle="TP 3D layers", ytitle="efficiency vs 3D layers", xmax=20, ymax=_maxEff),
59  Plot(FakeDuplicate("fakeduprate_vs_3Dlayer", assoc="num_assoc(recoToSim)_3Dlayer", dup="num_duplicate_3Dlayer", reco="num_reco_3Dlayer", title="fake+duplicates vs 3D layer"),
60  xtitle="track 3D layers", ytitle="fake+duplicates rate vs 3D layers", ymax=_maxFake, xmax=20),
61 ],
62  legendDy=0.09
63 )
64 _common = {"ymin": 0, "ymax": _maxEff}
65 _effvspos = PlotGroup("effvspos", [
66  Plot("effic_vs_vertpos", xtitle="TP vert xy pos (cm)", ytitle="efficiency vs vert xy pos", **_common),
67  Plot("effic_vs_zpos", xtitle="TP vert z pos (cm)", ytitle="efficiency vs vert z pos", **_common),
68  Plot("effic_vs_dr", xlog=True, xtitle="min #DeltaR", ytitle="efficiency vs #DeltaR", **_common),
69  Plot("fakerate_vs_dr", xlog=True, title="", xtitle="min #DeltaR", ytitle="Fake rate vs #DeltaR", ymin=0, ymax=_maxFake)
70 ],
71  legendDy=-0.025
72 )
73 
74 _dupandfake1 = PlotGroup("dupandfake1", [
75  Plot("fakeratePt", xtitle="track p_{T} (GeV)", ytitle="fakerate vs p_{T}", xlog=True, ymax=_maxFake),
76  Plot("duplicatesRate_Pt", xtitle="track p_{T} (GeV)", ytitle="duplicates rate vs p_{T}", ymax=_maxFake, xlog=True),
77  Plot("pileuprate_Pt", xtitle="track p_{T} (GeV)", ytitle="pileup rate vs p_{T}", ymax=_maxFake, xlog=True),
78  Plot("fakerate", xtitle="track #eta", ytitle="fakerate vs #eta", title="", ymax=_maxFake),
79  Plot("duplicatesRate", xtitle="track #eta", ytitle="duplicates rate vs #eta", title="", ymax=_maxFake),
80  Plot("pileuprate", xtitle="track #eta", ytitle="pileup rate vs #eta", title="", ymax=_maxFake),
81  Plot("fakerate_vs_phi", xtitle="track #phi", ytitle="fakerate vs #phi", ymax=_maxFake),
82  Plot("duplicatesRate_phi", xtitle="track #phi", ytitle="duplicates rate vs #phi", ymax=_maxFake),
83  Plot("pileuprate_phi", xtitle="track #phi", ytitle="pileup rate vs #phi", ymax=_maxFake),
84 ], ncols=3)
85 _dupandfake2 = PlotGroup("dupandfake2", [
86  Plot("fakerate_vs_dxy", xtitle="track dxy (cm)", ytitle="fakerate vs dxy", ymax=_maxFake),
87  Plot("duplicatesRate_dxy", xtitle="track dxy (cm)", ytitle="duplicates rate vs dxy", ymax=_maxFake),
88  Plot("pileuprate_dxy", xtitle="track dxy (cm)", ytitle="pileup rate vs dxy", ymax=_maxFake),
89  #
90  Plot("fakerate_vs_dxypv", xtitle="track dxy(PV) (cm)", ytitle="fakerate vs dxy(PV)", ymax=_maxFake),
91  Plot("duplicatesRate_dxypv", xtitle="track dxy(PV) (cm)", ytitle="duplicates rate vs dxy(PV)", ymax=_maxFake),
92  Plot("pileuprate_dxypv", xtitle="track dxy(PV) (cm)", ytitle="pileup rate vs dxy(PV)", ymax=_maxFake),
93  #
94  Plot("fakerate_vs_dz", xtitle="track dz (cm)", ytitle="fakerate vs dz", title="", ymax=_maxFake),
95  Plot("duplicatesRate_dz", xtitle="track dz (cm)", ytitle="duplicates rate vs dz", title="", ymax=_maxFake),
96  Plot("pileuprate_dz", xtitle="track dz (cm)", ytitle="pileup rate vs dz", title="", ymax=_maxFake),
97  #
98  Plot("fakerate_vs_dzpv", xtitle="track dz(PV) (cm)", ytitle="fakerate vs dz(PV)", title="", ymax=_maxFake),
99  Plot("duplicatesRate_dzpv", xtitle="track dz(PV) (cm)", ytitle="duplicates rate vs dz(PV)", title="", ymax=_maxFake),
100  Plot("pileuprate_dzpv", xtitle="track dz(PV) (cm)", ytitle="pileup rate vs dz(PV)", title="", ymax=_maxFake),
101 ], ncols=3,
102  legendDy=0.09
103 )
104 _dupandfake3 = PlotGroup("dupandfake3", [
105  Plot("fakerate_vs_hit", xtitle="track hits", ytitle="fakerate vs hits", ymax=_maxFake),
106  Plot("duplicatesRate_hit", xtitle="track hits", ytitle="duplicates rate vs hits", ymax=_maxFake),
107  Plot("pileuprate_hit", xtitle="track hits", ytitle="pileup rate vs hits", ymax=_maxFake),
108  #
109  Plot("fakerate_vs_layer", xtitle="track layers", ytitle="fakerate vs layer", ymax=_maxFake, xmax=25),
110  Plot("duplicatesRate_layer", xtitle="track layers", ytitle="duplicates rate vs layers", ymax=_maxFake, xmax=25),
111  Plot("pileuprate_layer", xtitle="track layers", ytitle="pileup rate vs layers", ymax=_maxFake, xmax=25),
112  #
113  Plot("fakerate_vs_pixellayer", xtitle="track pixel layers", ytitle="fakerate vs pixel layers", title="", ymax=_maxFake, xmax=6),
114  Plot("duplicatesRate_pixellayer", xtitle="track pixel layers", ytitle="duplicates rate vs pixel layers", title="", ymax=_maxFake, xmax=6),
115  Plot("pileuprate_pixellayer", xtitle="track pixel layers", ytitle="pileup rate vs pixel layers", title="", ymax=_maxFake, xmax=6),
116  #
117  Plot("fakerate_vs_3Dlayer", xtitle="track 3D layers", ytitle="fakerate vs 3D layers", ymax=_maxFake, xmax=20),
118  Plot("duplicatesRate_3Dlayer", xtitle="track 3D layers", ytitle="duplicates rate vs 3D layers", ymax=_maxFake, xmax=20),
119  Plot("pileuprate_3Dlayer", xtitle="track 3D layers", ytitle="pileup rate vs 3D layers", ymax=_maxFake, xmax=20)
120 ], ncols=3,
121  legendDy=0.09
122 )
123 _dupandfake4 = PlotGroup("dupandfake4", [
124  Plot("fakerate_vs_chi2", xtitle="track #chi^{2}", ytitle="fakerate vs #chi^{2}", ymax=_maxFake),
125  Plot("duplicatesRate_chi2", xtitle="track #chi^{2}", ytitle="duplicates rate vs #chi^{2}", ymax=_maxFake),
126  Plot("pileuprate_chi2", xtitle="track #chi^{2}", ytitle="pileup rate vs #chi^{2}", ymax=_maxFake)
127 ],
128  legendDy=-0.025
129 )
130 _common = {
131  "ytitle": "Fake+pileup rate",
132  "ymax": _maxFake,
133  "drawStyle": "EP",
134 }
135 _common2 = {}
136 _common2.update(_common)
137 _common2["drawStyle"] = "pcolz"
138 _common2["ztitleoffset"] = 1.5
139 _common2["xtitleoffset"] = 7
140 _common2["ytitleoffset"] = 10
141 _common2["ztitleoffset"] = 6
142 _pvassociation1 = PlotGroup("pvassociation1", [
143  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")),
144  xtitle="Efficiency vs. cut on dz(PV)", **_common),
145  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),
146  xtitle="Efficiency", ztitle="Cut on dz(PV)", **_common2),
147  #
148  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_dzpvcut")),
149  xtitle="Efficiency vs. cut on dz(PV)/dzError", **_common),
150  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_dzpvcut"), zaxis=True),
151  xtitle="Efficiency", ztitle="Cut on dz(PV)/dzError", **_common2),
152  ##
153  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")),
154  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)", **_common),
155  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"), zaxis=True),
156  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)", **_common2),
157  #
158  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_dzpvcut")),
159  xtitle="Efficiency (p_{T} weighted) vs. cut on dz(PV)/dzError", **_common),
160  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_dzpvcut"), zaxis=True),
161  xtitle="Efficiency (p_{T} weighted)", ztitle="Cut on dz(PV)/dzError", **_common2),
162 ], onlyForPileup=True,
163  legendDy=0.09
164 )
165 _pvassociation2 = PlotGroup("pvassociation2", [
166  Plot("effic_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency vs. cut on dz(PV)", ymax=_maxEff),
167  Plot("effic_vs_dzpvcut2", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
168  Plot("fakerate_vs_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate vs. cut on dz(PV)", ymax=_maxFake),
169  Plot("pileuprate_dzpvcut", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate vs. cut on dz(PV)", ymax=_maxFake),
170  #
171  Plot("effic_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency vs. cut on dz(PV)/dzError", ymax=_maxEff),
172  Plot("effic_vs_dzpvsigcut2", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (excl. trk eff)", ymax=_maxEff),
173  Plot("fakerate_vs_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
174  Plot("pileuprate_dzpvsigcut", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate vs. cut on dz(PV)/dzError", ymax=_maxFake),
175 ], onlyForPileup=True,
176  legendDy=0.09
177 )
178 _pvassociation3 = PlotGroup("pvassociation3", [
179  Plot("effic_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
180  Plot("effic_vs_dzpvcut2_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
181  Plot("fakerate_vs_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
182  Plot("pileuprate_dzpvcut_pt", xtitle="Cut on dz(PV) (cm)", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
183  #
184  Plot("effic_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted)", ymax=_maxEff),
185  Plot("effic_vs_dzpvsigcut2_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Efficiency (p_{T} weighted, excl. trk eff)", ymax=_maxEff),
186  Plot("fakerate_vs_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Fake rate (p_{T} weighted)", ymax=_maxFake),
187  Plot("pileuprate_dzpvsigcut_pt", xtitle="Cut on dz(PV)/dzError", ytitle="Pileup rate (p_{T} weighted)", ymax=_maxFake),
188 ], onlyForPileup=True,
189  legendDy=0.09
190 )
191 
192 
193 # These don't exist in FastSim
194 _common = {"normalizeToUnitArea": True, "stat": True, "drawStyle": "hist"}
195 _dedx = PlotGroup("dedx", [
196  Plot("h_dedx_estim1", xtitle="dE/dx, harm2", **_common),
197  Plot("h_dedx_estim2", xtitle="dE/dx, trunc40", **_common),
198  Plot("h_dedx_nom1", xtitle="dE/dx number of measurements", title="", **_common),
199  Plot("h_dedx_sat1", xtitle="dE/dx number of measurements with saturation", title="", **_common),
200  ],
201  legendDy=-0.025
202 )
203 
204 _chargemisid = PlotGroup("chargemisid", [
205  Plot("chargeMisIdRate", xtitle="#eta", ytitle="charge mis-id rate vs #eta", ymax=0.05),
206  Plot("chargeMisIdRate_Pt", xtitle="p_{T}", ytitle="charge mis-id rate vs p_{T}", xmax=300, ymax=0.1, xlog=True),
207  Plot("chargeMisIdRate_hit", xtitle="hits", ytitle="charge mis-id rate vs hits", title=""),
208  Plot("chargeMisIdRate_phi", xtitle="#phi", ytitle="charge mis-id rate vs #phi", title="", ymax=0.01),
209  Plot("chargeMisIdRate_dxy", xtitle="dxy", ytitle="charge mis-id rate vs dxy", ymax=0.1),
210  Plot("chargeMisIdRate_dz", xtitle="dz", ytitle="charge mis-id rate vs dz", ymax=0.1)
211 ])
212 _common = {"stat": True, "normalizeToUnitArea": True, "ylog": True, "ymin": 1e-6, "drawStyle": "hist"}
213 _hitsAndPt = PlotGroup("hitsAndPt", [
214  Plot("missing_inner_layers", ymax=1, **_common),
215  Plot("missing_outer_layers", ymax=1, **_common),
216  Plot("hits_eta", stat=True, statx=0.38, xtitle="track #eta", ytitle="<hits> vs #eta", ymin=8, ymax=24, statyadjust=[0,0,-0.15]),
217  Plot("hits", stat=True, xtitle="track hits", xmin=0, xmax=40, drawStyle="hist"),
218  Plot("num_simul_pT", xtitle="TP p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common),
219  Plot("num_reco_pT", xtitle="track p_{T}", xlog=True, ymax=[1e-1, 2e-1, 5e-1, 1], **_common)
220 ])
221 _tuning = PlotGroup("tuning", [
222  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),
223  Plot("chi2_prob", stat=True, normalizeToUnitArea=True, drawStyle="hist", xtitle="Prob(#chi^{2})"),
224  Plot("chi2mean", stat=True, title="", xtitle="#eta", ytitle="< #chi^{2} / ndf >", ymax=2.5),
225  Plot("ptres_vs_eta_Mean", stat=True, scale=100, title="", xtitle="#eta", ytitle="< #delta p_{T} / p_{T} > [%]", ymin=-1.5, ymax=1.5)
226 ])
227 _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}
228 _pulls = PlotGroup("pulls", [
229  Plot("pullPt", **_common),
230  Plot("pullQoverp", **_common),
231  Plot("pullPhi", **_common),
232  Plot("pullTheta", **_common),
233  Plot("pullDxy", **_common),
234  Plot("pullDz", **_common),
235 ],
236  legendDx=0.1, legendDw=-0.1, legendDh=-0.015
237 )
238 _common = {"title": "", "ylog": True, "xtitle": "#eta", "ymin": _minMaxResol, "ymax": _minMaxResol}
239 _resolutionsEta = PlotGroup("resolutionsEta", [
240  Plot("phires_vs_eta_Sigma", ytitle="#sigma(#delta #phi) [rad]", **_common),
241  Plot("cotThetares_vs_eta_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
242  Plot("dxyres_vs_eta_Sigma", ytitle="#sigma(#delta d_{0}) [cm]", **_common),
243  Plot("dzres_vs_eta_Sigma", ytitle="#sigma(#delta z_{0}) [cm]", **_common),
244  Plot("ptres_vs_eta_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
245 ])
246 _common = {"title": "", "ylog": True, "xlog": True, "xtitle": "p_{T}", "xmin": 0.1, "xmax": 1000, "ymin": _minMaxResol, "ymax": _minMaxResol}
247 _resolutionsPt = PlotGroup("resolutionsPt", [
248  Plot("phires_vs_pt_Sigma", ytitle="#sigma(#delta #phi) [rad]", **_common),
249  Plot("cotThetares_vs_pt_Sigma", ytitle="#sigma(#delta cot(#theta))", **_common),
250  Plot("dxyres_vs_pt_Sigma", ytitle="#sigma(#delta d_{0}) [cm]", **_common),
251  Plot("dzres_vs_pt_Sigma", ytitle="#sigma(#delta z_{0}) [cm]", **_common),
252  Plot("ptres_vs_pt_Sigma", ytitle="#sigma(#delta p_{T}/p_{T})", **_common),
253 ])
254 
255 ########################################
256 #
257 # Summary plots
258 #
259 ########################################
260 
261 _possibleTrackingColls = [
262  'initialStep',
263  'lowPtTripletStep',
264  'pixelPairStep',
265  'detachedTripletStep',
266  'mixedTripletStep',
267  'pixelLessStep',
268  'tobTecStep',
269  'jetCoreRegionalStep',
270  'muonSeededStepInOut',
271  'muonSeededStepOutIn',
272  'ak4PFJets',
273  'btvLike',
274 ]
276  if "Hp" in collName:
277  quality = "highPurity"
278  else:
279  quality = ""
280  collNameLow = collName.replace("Hp", "").lower()
281 
282  algo = None
283  if "general" in collNameLow or collNameLow in ["cutsreco", "cutsrecofrompv", "cutsrecofrompvalltp",
284  "cutsrecotracks", "custrecotracksfrompv", "cutsrecotracksfrompvalltp"]:
285  algo = "ootb"
286  else:
287  for coll in _possibleTrackingColls:
288  if coll.lower() in collNameLow:
289  algo = coll
290  break
291  # fallback
292  if algo is None:
293  algo = collName
294 
295  return (algo, quality)
296 
297 def _collhelper(name):
298  return (name, [name])
299 _collLabelMap = collections.OrderedDict(map(_collhelper, ["generalTracks"]+_possibleTrackingColls))
300 _collLabelMapHp = collections.OrderedDict(map(_collhelper, ["generalTracks"]+filter(lambda n: "Step" in n, _possibleTrackingColls)))
301 def _summaryBinRename(binLabel, highPurity):
302  (algo, quality) = _mapCollectionToAlgoQuality(binLabel)
303  ret = None
304  if highPurity:
305  if quality == "highPurity":
306  ret = algo
307  else:
308  if quality == "":
309  ret = algo
310  if ret == "ootb":
311  ret = "generalTracks"
312  return ret
313 
314 _common = {"drawStyle": "EP", "xbinlabelsize": 10, "xbinlabeloption": "d"}
315 _commonAB = {"mapping": _collLabelMap,
316  "renameBin": lambda bl: _summaryBinRename(bl, False)}
317 _commonN = {"ylog": True, "ymin": _minMaxN, "ymax": _minMaxN}
318 _commonN.update(_common)
319 _summary = PlotGroup("summary", [
320  Plot(AggregateBins("efficiency", "effic_vs_coll", **_commonAB),
321  title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
322  Plot(AggregateBins("efficiencyAllPt", "effic_vs_coll_allPt", **_commonAB),
323  title="Efficiency vs collection (no pT cut in denominator)", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
324 
325  Plot(AggregateBins("fakerate", "fakerate_vs_coll", **_commonAB), title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
326  Plot(AggregateBins("duplicatesRate", "duplicatesRate_coll", **_commonAB), title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
327  Plot(AggregateBins("pileuprate", "pileuprate_coll", **_commonAB), title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
328 ])
329 _summaryN = PlotGroup("summary_ntracks", [
330  Plot(AggregateBins("num_reco_coll", "num_reco_coll", **_commonAB), ytitle="Tracks", title="Number of tracks vs collection", **_commonN),
331  Plot(AggregateBins("num_signal_coll", "num_assoc(recoToSim)_coll", **_commonAB), ytitle="Signal tracks", title="Number of signal tracks vs collection", **_commonN),
332  Plot(AggregateBins("num_fake_coll", Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll"), **_commonAB), ytitle="Fake tracks", title="Number of fake tracks vs collection", **_commonN),
333  Plot(AggregateBins("num_pileup_coll", "num_pileup_coll", **_commonAB), ytitle="Pileup tracks", title="Number of pileup tracks vs collection", **_commonN),
334  Plot(AggregateBins("num_duplicate_coll", "num_duplicate_coll", **_commonAB), ytitle="Duplicate tracks", title="Number of duplicate tracks vs collection", **_commonN),
335 ])
336 _commonAB = {"mapping": _collLabelMapHp,
337  "renameBin": lambda bl: _summaryBinRename(bl, True)}
338 _summaryHp = PlotGroup("summary", [
339  Plot(AggregateBins("efficiency", "effic_vs_coll", **_commonAB),
340  title="Efficiency vs collection", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
341  Plot(AggregateBins("efficiencyefficiencyAllPt", "effic_vs_coll", **_commonAB),
342  title="Efficiency vs collection (no pT cut in denominator)", ytitle="Efficiency", ymin=1e-3, ymax=1, ylog=True, **_common),
343  Plot(AggregateBins("fakerate", "fakerate_vs_coll", **_commonAB), title="Fakerate vs collection", ytitle="Fake rate", ymax=_maxFake, **_common),
344  Plot(AggregateBins("duplicatesRate", "duplicatesRate_coll", **_commonAB), title="Duplicates rate vs collection", ytitle="Duplicates rate", ymax=_maxFake, **_common),
345  Plot(AggregateBins("pileuprate", "pileuprate_coll", **_commonAB), title="Pileup rate vs collection", ytitle="Pileup rate", ymax=_maxFake, **_common),
346 ])
347 _summaryNHp = PlotGroup("summary_ntracks", [
348  Plot(AggregateBins("num_reco_coll", "num_reco_coll", **_commonAB), ytitle="Tracks", title="Number of tracks vs collection", **_commonN),
349  Plot(AggregateBins("num_signal_coll", "num_assoc(recoToSim)_coll", **_commonAB), ytitle="Signal tracks", title="Number of signal tracks vs collection", **_commonN),
350  Plot(AggregateBins("num_fake_coll", Subtract("num_fake_coll_orig", "num_reco_coll", "num_assoc(recoToSim)_coll"), **_commonAB), ytitle="Fake tracks", title="Number of fake tracks vs collection", **_commonN),
351  Plot(AggregateBins("num_pileup_coll", "num_pileup_coll", **_commonAB), ytitle="Pileup tracks", title="Number of pileup tracks vs collection", **_commonN),
352  Plot(AggregateBins("num_duplicate_coll", "num_duplicate_coll", **_commonAB), ytitle="Duplicate tracks", title="Number of duplicate tracks vs collection", **_commonN),
353 ])
354 
355 ########################################
356 #
357 # PackedCandidate plots
358 #
359 ########################################
360 
361 _common = {"normalizeToUnitArea": True, "ylog": True, "ymin": [1e-6, 1e-5, 1e-4, 1e-3, 1e-2], "ymax": [1e-2, 1e-1, 1.1]}
362 _packedCandidateFlow = PlotGroup("flow", [
363  Plot("selectionFlow", xbinlabelsize=10, xbinlabeloption="d", drawStyle="hist", ylog=True, ymin=[0.9, 9, 9e1, 9e2, 9e3, 9e4, 9e5, 9e6, 9e7]),
364  Plot("diffCharge", xtitle="Charge", **_common),
365  Plot("diffIsHighPurity", xtitle="High purity status", **_common),
366  Plot("diffNdof", xtitle="ndof", **_common),
367  Plot("diffNormalizedChi2", xtitle="#chi^{2}/ndof", **_common),
368 ])
369 _packedCandidateHits = PlotGroup("hits", [
370  Plot("diffHitPatternNumberOfValidHits", xtitle="Valid hits (via HitPattern)", **_common),
371  Plot("diffHitPatternNumberOfValidPixelHits", xtitle="Valid pixel hits (via HitPattern)", **_common),
372  Plot("diffHitPatternHasValidHitInFirstPixelBarrel", xtitle="Has valid hit in BPix1 layer (via HitPattern)", **_common),
373  Plot("diffHitPatternNumberOfLostPixelHits", xtitle="Lost pixel hits (via HitPattern)", **_common),
374  Plot("diffNumberOfHits", xtitle="Hits", **_common),
375  Plot("diffNumberOfPixelHits", xtitle="Pixel hits", **_common),
376  Plot("diffLostInnerHits", xtitle="Lost inner hits", **_common),
377 ],
378  legendDy=0.09
379 )
380 
381 _common["xlabelsize"] = 16
382 _packedCandidateMomVert = PlotGroup("momentumVertex", [
383  Plot("diffPx", xtitle="p_{x}", **_common),
384  Plot("diffVx", xtitle="Reference point x", **_common),
385  Plot("diffPy", xtitle="p_{y}", **_common),
386  Plot("diffVy", xtitle="Reference point y", **_common),
387  Plot("diffPz", xtitle="p_{z}", **_common),
388  Plot("diffVz", xtitle="Reference point z", **_common),
389 ])
390 
391 _common["adjustMarginRight"] = 0.05
392 _packedCandidateParam1 = PlotGroup("param1", [
393  Plot("diffPt", xtitle="p_{T}", **_common),
394  Plot("diffPtError", xtitle="p_{T} error", **_common),
395  Plot("diffEta", xtitle="#eta", **_common),
396  Plot("diffEtaError", xtitle="#eta error", **_common),
397  Plot("diffPhi", xtitle="#phi", **_common),
398  Plot("diffPhiError", xtitle="#phi error", **_common),
399 ])
400 _packedCandidateParam2 = PlotGroup("param2", [
401  Plot("diffDxy", xtitle="d_{xy}", **_common),
402  Plot("diffDxyError", xtitle="d_{xy} error", **_common),
403  Plot("diffDz", xtitle="d_{z}", **_common),
404  Plot("diffDzError", xtitle="d_{z} error", **_common),
405  Plot("diffQoverp", xtitle="Q/p", **_common),
406  Plot("diffQoverpError", xtitle="Q/p error", **_common),
407  Plot("diffTheta", xtitle="#theta", **_common),
408  Plot("diffThetaError", xtitle="#theta error", **_common),
409 ],
410  legendDy=0.09
411 )
412 
414  def _init__(self, *args, **kwargs):
415  super(TrackingPlotFolder, self).__init__(*args, **kwargs)
416 
417  def translateSubFolder(self, dqmSubFolderName):
418  spl = dqmSubFolderName.split("_")
419  if len(spl) != 2:
420  return None
421  collName = spl[0]
422  return _mapCollectionToAlgoQuality(collName)
423 
424  def getSelectionName(self, plotFolderName, translatedDqmSubFolder):
425  (algo, quality) = translatedDqmSubFolder
426 
427  ret = ""
428  if plotFolderName != "":
429  ret += "_"+plotFolderName
430  if quality != "":
431  ret += "_"+quality
432  if not (algo == "ootb" and quality != ""):
433  ret += "_"+algo
434 
435  return ret
436 
437  def limitSubFolder(self, limitOnlyTo, translatedDqmSubFolder):
438  """Return True if this subfolder should be processed
439 
440  Arguments:
441  limitOnlyTo -- Function '(algo, quality) -> bool'
442  translatedDqmSubFolder -- Return value of translateSubFolder
443  """
444  (algo, quality) = translatedDqmSubFolder
445  return limitOnlyTo(algo, quality)
446 
447 def _trackingFolders(lastDirName="Track"):
448  return [
449  "DQMData/Run 1/Tracking/Run summary/"+lastDirName,
450  "DQMData/Tracking/"+lastDirName,
451  "DQMData/Run 1/RecoTrackV/Run summary/"+lastDirName,
452  "DQMData/RecoTrackV/"+lastDirName,
453  ]
454 
455 _simBasedPlots = [
456  _effandfake1,
457  _effandfake2,
458  _effandfake3,
459  _effvspos,
460 ]
461 _recoBasedPlots = [
462  _dupandfake1,
463  _dupandfake2,
464  _dupandfake3,
465  _dupandfake4,
466  _pvassociation1,
467  _pvassociation2,
468  _pvassociation3,
469  _dedx,
470 # _chargemisid,
471  _hitsAndPt,
472  _pulls,
473  _resolutionsEta,
474  _resolutionsPt,
475  _tuning,
476 ]
477 _summaryPlots = [
478  _summary,
479  _summaryN,
480 ]
481 _summaryPlotsHp = [
482  _summaryHp,
483  _summaryNHp,
484 ]
485 _packedCandidatePlots = [
486  _packedCandidateFlow,
487  _packedCandidateParam1,
488  _packedCandidateParam2,
489  _packedCandidateMomVert,
490  _packedCandidateHits,
491 ]
492 plotter = Plotter()
493 def _appendTrackingPlots(lastDirName, name, algoPlots, onlyForPileup=False):
494  # to keep backward compatibility, this set of plots has empty name
495  plotter.append(name, _trackingFolders(lastDirName), TrackingPlotFolder(*algoPlots, onlyForPileup=onlyForPileup, purpose=PlotPurpose.TrackingIteration))
496  summaryName = ""
497  if name != "":
498  summaryName += name+"_"
499  summaryName += "summary"
500  plotter.append(summaryName, _trackingFolders(lastDirName),
501  PlotFolder(*_summaryPlots, loopSubFolders=False, onlyForPileup=onlyForPileup,
502  purpose=PlotPurpose.TrackingSummary, page="summary", section=name))
503  plotter.append(summaryName+"_highPurity", _trackingFolders(lastDirName),
504  PlotFolder(*_summaryPlotsHp, loopSubFolders=False, onlyForPileup=onlyForPileup,
505  purpose=PlotPurpose.TrackingSummary, page="summary",
506  section=name+"_highPurity" if name != "" else "highPurity"),
507  fallbackNames=[summaryName]) # backward compatibility for release validation, the HP plots used to be in the same directory with all-track plots
508 _appendTrackingPlots("Track", "", _simBasedPlots+_recoBasedPlots)
509 _appendTrackingPlots("TrackAllTPEffic", "allTPEffic", _simBasedPlots, onlyForPileup=True)
510 _appendTrackingPlots("TrackFromPV", "fromPV", _simBasedPlots+_recoBasedPlots, onlyForPileup=True)
511 _appendTrackingPlots("TrackFromPVAllTP", "fromPVAllTP", _recoBasedPlots, onlyForPileup=True)
512 
513 # MiniAOD
514 plotter.append("packedCandidate", _trackingFolders("PackedCandidate"),
515  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
516  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate"))
517 plotter.append("packedCandidateLostTracks", _trackingFolders("PackedCandidate/lostTracks"),
518  PlotFolder(*_packedCandidatePlots, loopSubFolders=False,
519  purpose=PlotPurpose.MiniAOD, page="miniaod", section="PackedCandidate (lostTracks)"))
520 
521 _iterModuleMap = collections.OrderedDict([
522  ("initialStepPreSplitting", ["initialStepSeedLayersPreSplitting",
523  "initialStepSeedsPreSplitting",
524  "initialStepTrackCandidatesPreSplitting",
525  "initialStepTracksPreSplitting",
526  "firstStepPrimaryVerticesPreSplitting",
527  "iter0TrackRefsForJetsPreSplitting",
528  "caloTowerForTrkPreSplitting",
529  "ak4CaloJetsForTrkPreSplitting",
530  "jetsForCoreTrackingPreSplitting",
531  "siPixelClusters",
532  "siPixelRecHits",
533  "MeasurementTrackerEvent",
534  "siPixelClusterShapeCache"]),
535  ("initialStep", ['initialStepClusters',
536  'initialStepSeedLayers',
537  'initialStepSeeds',
538  'initialStepTrackCandidates',
539  'initialStepTracks',
540  'initialStepSelector',
541  'initialStep']),
542  ("lowPtTripletStep", ['lowPtTripletStepClusters',
543  'lowPtTripletStepSeedLayers',
544  'lowPtTripletStepSeeds',
545  'lowPtTripletStepTrackCandidates',
546  'lowPtTripletStepTracks',
547  'lowPtTripletStepSelector']),
548  ("pixelPairStep", ['pixelPairStepClusters',
549  'pixelPairStepSeedLayers',
550  'pixelPairStepSeeds',
551  'pixelPairStepTrackCandidates',
552  'pixelPairStepTracks',
553  'pixelPairStepSelector']),
554  ("detachedTripletStep", ['detachedTripletStepClusters',
555  'detachedTripletStepSeedLayers',
556  'detachedTripletStepSeeds',
557  'detachedTripletStepTrackCandidates',
558  'detachedTripletStepTracks',
559  'detachedTripletStepSelector',
560  'detachedTripletStep']),
561  ("mixedTripletStep", ['mixedTripletStepClusters',
562  'mixedTripletStepSeedLayersA',
563  'mixedTripletStepSeedLayersB',
564  'mixedTripletStepSeedsA',
565  'mixedTripletStepSeedsB',
566  'mixedTripletStepSeeds',
567  'mixedTripletStepTrackCandidates',
568  'mixedTripletStepTracks',
569  'mixedTripletStepSelector',
570  'mixedTripletStep']),
571  ("pixelLessStep", ['pixelLessStepClusters',
572  'pixelLessStepSeedClusters',
573  'pixelLessStepSeedLayers',
574  'pixelLessStepSeeds',
575  'pixelLessStepTrackCandidates',
576  'pixelLessStepTracks',
577  'pixelLessStepSelector',
578  'pixelLessStep']),
579  ("tobTecStep", ['tobTecStepClusters',
580  'tobTecStepSeedClusters',
581  'tobTecStepSeedLayersTripl',
582  'tobTecStepSeedLayersPair',
583  'tobTecStepSeedsTripl',
584  'tobTecStepSeedsPair',
585  'tobTecStepSeeds',
586  'tobTecStepTrackCandidates',
587  'tobTecStepTracks',
588  'tobTecStepSelector']),
589  ("jetCoreRegionalStep", ['iter0TrackRefsForJets',
590  'caloTowerForTrk',
591  'ak4CaloJetsForTrk',
592  'jetsForCoreTracking',
593  'firstStepPrimaryVertices',
594  'firstStepGoodPrimaryVertices',
595  'jetCoreRegionalStepSeedLayers',
596  'jetCoreRegionalStepSeeds',
597  'jetCoreRegionalStepTrackCandidates',
598  'jetCoreRegionalStepTracks',
599  'jetCoreRegionalStepSelector']),
600  ("muonSeededStep", ['earlyMuons',
601  'muonSeededSeedsInOut',
602  'muonSeededSeedsInOut',
603  'muonSeededTracksInOut',
604  'muonSeededSeedsOutIn',
605  'muonSeededTrackCandidatesOutIn',
606  'muonSeededTracksOutIn',
607  'muonSeededTracksInOutSelector',
608  'muonSeededTracksOutInSelector']),
609 ])
610 
611 
612 _timing = PlotGroup("", [
613  Plot(AggregateBins("iterative", "reconstruction_step_module_average", _iterModuleMap), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST", xbinlabelsize=0.03),
614 # 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)
615  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)
616 
617  ],
618  legendDx=-0.1, legendDw=-0.35, legendDy=0.39,
619 )
620 _pixelTiming = PlotGroup("pixelTiming", [
621  Plot(AggregateBins("pixel", "reconstruction_step_module_average", {"pixelTracks": ["pixelTracks"]}), ytitle="Average processing time [ms]", title="Average processing time / event", drawStyle="HIST")
622 ])
623 
624 timePlotter = Plotter()
625 timePlotter.append("timing", [
626  "DQMData/Run 1/DQM/Run summary/TimerService/Paths",
627  "DQMData/Run 1/DQM/Run summary/TimerService/process RECO/Paths",
628 ], PlotFolder(
629  _timing
630 # _pixelTiming
631 ))
632 
633 _common = {"stat": True, "normalizeToUnitArea": True, "drawStyle": "hist"}
634 _tplifetime = PlotGroup("tplifetime", [
635  Plot("TPlip", xtitle="TP lip", **_common),
636  Plot("TPtip", xtitle="TP tip", **_common),
637 ])
638 
639 tpPlotter = Plotter()
640 tpPlotter.append("tp", [
641  "DQMData/Run 1/Tracking/Run summary/TrackingMCTruth/TrackingParticle",
642  "DQMData/Tracking/TrackingMCTruth/TrackingParticle",
643 ], PlotFolder(
644  _tplifetime,
645 ))
646 
647 
def _appendTrackingPlots
def _mapCollectionToAlgoQuality