ATLAS Offline Software
Loading...
Searching...
No Matches
InDetPerfPlot_VertexTruthMatching.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
15#include "TFitResult.h"
16#include "TFitResultPtr.h"
17#include "GaudiKernel/PhysicalConstants.h"
18
19using namespace IDPVM;
20
21InDetPerfPlot_VertexTruthMatching::InDetPerfPlot_VertexTruthMatching(InDetPlotBase* pParent, const std::string& sDir, const int detailLevel, bool isITk) :
22 InDetPlotBase(pParent, sDir), m_isITk(isITk), m_detailLevel(detailLevel) {}
23
24
26
27 book(m_vx_type_truth,"vx_type_truth");
28 book(m_vx_x_diff,"vx_x_diff");
29 book(m_vx_x_diff_pull,"vx_x_diff_pull");
30 book(m_vx_y_diff,"vx_y_diff");
31 book(m_vx_y_diff_pull,"vx_y_diff_pull");
32 book(m_vx_z_diff,"vx_z_diff");
33 book(m_vx_z_diff_pull,"vx_z_diff_pull");
34 if(m_isITk){
35 book(m_vx_time_diff,"vx_time_diff");
36 book(m_vx_time_diff_pull,"vx_time_diff_pull");
37 }
38
39 book(m_vx_hs_classification,"vx_hs_classification");
40 book(m_vx_hs_sel_eff_dist_vs_nReco,"vx_hs_sel_eff_dist_vs_nReco");
41 book(m_vx_hs_sel_eff_mu,"vx_hs_sel_eff_mu");
42 book(m_vx_hs_sel_eff_vs_nReco,"vx_hs_sel_eff_vs_nReco");
43 book(m_vx_hs_reco_eff_mu,"vx_hs_reco_eff_mu");
44
45 book(m_resHelper_mu_hsVxTruthLong,"resHelper_mu_hsVxTruthLong");
46 book(m_resolution_vs_mu_hsVxTruthLong,"resolution_vs_mu_hsVxTruthLong");
47 book(m_resmean_vs_mu_hsVxTruthLong,"resmean_vs_mu_hsVxTruthLong");
48
49 if (m_detailLevel >= 200) {
50
51 book(m_vx_hs_reco_eff,"vx_hs_reco_eff");
52 book(m_vx_hs_sel_eff,"vx_hs_sel_eff");
53 book(m_vx_hs_sel_eff_dist,"vx_hs_sel_eff_dist");
54 book(m_vx_hs_reco_sel_eff,"vx_hs_reco_sel_eff");
55 book(m_vx_hs_reco_eff_vs_ntruth,"vx_hs_reco_eff_vs_ntruth");
56 book(m_vx_hs_sel_eff_vs_ntruth,"vx_hs_sel_eff_vs_ntruth");
57 book(m_vx_hs_reco_sel_eff_vs_ntruth,"vx_hs_reco_sel_eff_vs_ntruth");
58
59 book(m_vx_nReco_vs_nTruth_inclusive,"vx_nReco_vs_nTruth_inclusive");
60 book(m_vx_nReco_vs_nTruth_matched,"vx_nReco_vs_nTruth_matched");
61 book(m_vx_nReco_vs_nTruth_merged,"vx_nReco_vs_nTruth_merged");
62 book(m_vx_nReco_vs_nTruth_split,"vx_nReco_vs_nTruth_split");
63 book(m_vx_nReco_vs_nTruth_fake,"vx_nReco_vs_nTruth_fake");
64 book(m_vx_nReco_vs_nTruth_dummy,"vx_nReco_vs_nTruth_dummy");
65 book(m_vx_nReco_vs_nTruth_clean,"vx_nReco_vs_nTruth_clean");
66 book(m_vx_nReco_vs_nTruth_lowpu,"vx_nReco_vs_nTruth_lowpu");
67 book(m_vx_nReco_vs_nTruth_highpu,"vx_nReco_vs_nTruth_highpu");
68 book(m_vx_nReco_vs_nTruth_hssplit,"vx_nReco_vs_nTruth_hssplit");
69 book(m_vx_nReco_vs_nTruth_none,"vx_nReco_vs_nTruth_none");
70
71 book(m_vx_hs_z_pull,"vx_TYPE_z_pull","vx_hs_z_pull");
72 book(m_vx_hs_y_pull,"vx_TYPE_y_pull","vx_hs_y_pull");
73 book(m_vx_hs_x_pull,"vx_TYPE_x_pull","vx_hs_x_pull");
74
75 book(m_vx_all_z_pull,"vx_TYPE_z_pull","vx_all_z_pull");
76 book(m_vx_all_y_pull,"vx_TYPE_y_pull","vx_all_y_pull");
77 book(m_vx_all_x_pull,"vx_TYPE_x_pull","vx_all_x_pull");
78
79 book(m_vx_hs_z_res,"vx_TYPE_z_reso","vx_hs_z_res");
80 book(m_vx_hs_y_res,"vx_TYPE_y_reso","vx_hs_y_res");
81 book(m_vx_hs_x_res,"vx_TYPE_x_reso","vx_hs_x_res");
82 book(m_vx_all_z_res,"vx_TYPE_z_reso","vx_all_z_res");
83 book(m_vx_all_y_res,"vx_TYPE_y_reso","vx_all_y_res");
84 book(m_vx_all_x_res,"vx_TYPE_x_reso","vx_all_x_res");
85
86 book(m_vx_all_truth_z_res_vs_PU, "vx_TYPE_truth_reso_z_vs_PU", "vx_all_truth_reso_z_vs_PU");
87 book(m_vx_all_truth_x_res_vs_PU, "vx_TYPE_truth_reso_x_vs_PU", "vx_all_truth_reso_x_vs_PU");
88 book(m_vx_all_truth_y_res_vs_PU, "vx_TYPE_truth_reso_y_vs_PU", "vx_all_truth_reso_y_vs_PU");
89 book(m_vx_all_truth_z_res_vs_nTrk, "vx_TYPE_truth_reso_z_vs_nTrk", "vx_all_truth_reso_z_vs_nTrk");
90 book(m_vx_all_truth_x_res_vs_nTrk, "vx_TYPE_truth_reso_x_vs_nTrk", "vx_all_truth_reso_x_vs_nTrk");
91 book(m_vx_all_truth_y_res_vs_nTrk, "vx_TYPE_truth_reso_y_vs_nTrk", "vx_all_truth_reso_y_vs_nTrk");
92
93 book(m_vx_all_truth_z_pull_vs_PU, "vx_TYPE_truth_pull_z_vs_PU", "vx_all_truth_pull_z_vs_PU");
94 book(m_vx_all_truth_x_pull_vs_PU, "vx_TYPE_truth_pull_x_vs_PU", "vx_all_truth_pull_x_vs_PU");
95 book(m_vx_all_truth_y_pull_vs_PU, "vx_TYPE_truth_pull_y_vs_PU", "vx_all_truth_pull_y_vs_PU");
96 book(m_vx_all_truth_z_pull_vs_nTrk, "vx_TYPE_truth_pull_z_vs_nTrk", "vx_all_truth_pull_z_vs_nTrk");
97 book(m_vx_all_truth_x_pull_vs_nTrk, "vx_TYPE_truth_pull_x_vs_nTrk", "vx_all_truth_pull_x_vs_nTrk");
98 book(m_vx_all_truth_y_pull_vs_nTrk, "vx_TYPE_truth_pull_y_vs_nTrk", "vx_all_truth_pull_y_vs_nTrk");
99
100 book(m_vx_hs_truth_z_res_vs_PU, "vx_TYPE_truth_reso_z_vs_PU", "vx_hs_truth_reso_z_vs_PU");
101 book(m_vx_hs_truth_x_res_vs_PU, "vx_TYPE_truth_reso_x_vs_PU", "vx_hs_truth_reso_x_vs_PU");
102 book(m_vx_hs_truth_y_res_vs_PU, "vx_TYPE_truth_reso_y_vs_PU", "vx_hs_truth_reso_y_vs_PU");
103 book(m_vx_hs_truth_z_res_vs_nTrk, "vx_TYPE_truth_reso_z_vs_nTrk", "vx_hs_truth_reso_z_vs_nTrk");
104 book(m_vx_hs_truth_x_res_vs_nTrk, "vx_TYPE_truth_reso_x_vs_nTrk", "vx_hs_truth_reso_x_vs_nTrk");
105 book(m_vx_hs_truth_y_res_vs_nTrk, "vx_TYPE_truth_reso_y_vs_nTrk", "vx_hs_truth_reso_y_vs_nTrk");
106
107 book(m_vx_hs_truth_z_pull_vs_PU, "vx_TYPE_truth_pull_z_vs_PU", "vx_hs_truth_pull_z_vs_PU");
108 book(m_vx_hs_truth_x_pull_vs_PU, "vx_TYPE_truth_pull_x_vs_PU", "vx_hs_truth_pull_x_vs_PU");
109 book(m_vx_hs_truth_y_pull_vs_PU, "vx_TYPE_truth_pull_y_vs_PU", "vx_hs_truth_pull_y_vs_PU");
110 book(m_vx_hs_truth_z_pull_vs_nTrk, "vx_TYPE_truth_pull_z_vs_nTrk", "vx_hs_truth_pull_z_vs_nTrk");
111 book(m_vx_hs_truth_x_pull_vs_nTrk, "vx_TYPE_truth_pull_x_vs_nTrk", "vx_hs_truth_pull_x_vs_nTrk");
112 book(m_vx_hs_truth_y_pull_vs_nTrk, "vx_TYPE_truth_pull_y_vs_nTrk", "vx_hs_truth_pull_y_vs_nTrk");
113
114 // book the new expert histos for vertex classifications
115 std::vector<int> categories = {0, 1, 2};
116 std::vector<InDetVertexTruthMatchUtils::VertexMatchType> types = {
121
122 for(const auto& cat : categories) {
123 for(const auto& type : types) {
124 std::string suffix = "_";
125 if(cat==1) suffix += "HS_";
126 else if(cat==2) suffix += "ALL_";
127
129 suffix += "matched";
131 suffix += "merged";
133 suffix += "split";
135 suffix += "fake";
136
137 book(m_vx_nVertices[cat][type], "vx_nVertices" + suffix);
139
140 book(m_vx_ntracks[cat][type], "vx_ntracks" + suffix);
141 book(m_vx_sumpT[cat][type], "vx_sumpT" + suffix);
142 book(m_vx_z_asym[cat][type], "vx_z_asym"+suffix);
143 book(m_vx_z_asym_weighted[cat][type], "vx_z_asym_weighted"+suffix);
144 book(m_vx_track_weight[cat][type], "vx_track_weight"+suffix);
145 book(m_vx_normalised_track_weight[cat][type], "vx_normalised_track_weight"+suffix);
146 book(m_vx_chi2Over_ndf[cat][type], "vx_chi2Over_ndf"+suffix);
147 book(m_vx_z0_skewness[cat][type], "vx_z0_skewness"+suffix);
148 book(m_vx_z0_kurtosis[cat][type], "vx_z0_kurtosis"+suffix);
149 }
150 }
151
152 book(m_vx_hs_mindz,"vx_hs_mindz");
153 book(m_vx_all_dz,"vx_all_dz");
154
155 book(m_vx_hs_reco_long_reso,"vx_hs_reco_long_reso");
156 book(m_vx_hs_reco_trans_reso,"vx_hs_reco_trans_reso");
157
158 //Helpers for resolution plots for HS vertex
159 book(m_resHelper_PUdensity_hsVxTruthLong,"resHelper_PUdensity_hsVxTruthLong");
160 book(m_resolution_vs_PUdensity_hsVxTruthLong,"resolution_vs_PUdensity_hsVxTruthLong");
161 book(m_resmean_vs_PUdensity_hsVxTruthLong,"resmean_vs_PUdensity_hsVxTruthLong");
162
163 book(m_resHelper_PUdensity_hsVxTruthTransv,"resHelper_PUdensity_hsVxTruthTransv");
164 book(m_resolution_vs_PUdensity_hsVxTruthTransv,"resolution_vs_PUdensity_hsVxTruthTransv");
165 book(m_resmean_vs_PUdensity_hsVxTruthTransv,"resmean_vs_PUdensity_hsVxTruthTransv");
166
167 book(m_vx_PUdensity,"vx_PUdensity");
168 book(m_vx_nTruth,"vx_nTruth");
169 book(m_vx_nTruth_vs_PUdensity,"vx_nTruth_vs_PUdensity");
170 }
171
172}
173
174
175
177 const xAOD::Vertex* recoHSVertex = nullptr;
178 float sumPtMax = -1.;
179 const xAOD::TrackParticle* trackTmp = nullptr;
180 float sumPtTmp;
181 for (const auto& vtx : recoVertices.stdcont()) {
182 if (vtx) {
183 sumPtTmp = 0.;
184 for (size_t i = 0; i < vtx->nTrackParticles(); i++) {
185 trackTmp = vtx->trackParticle(i);
186 if (trackTmp) {
187 sumPtTmp += std::pow(trackTmp->pt(), 2);
188 }
189 }
190 if (sumPtTmp > sumPtMax) {
191 sumPtMax = sumPtTmp;
192 recoHSVertex = vtx;
193 }
194 }
195 }
196 return recoHSVertex;
197}
198
199
200template<typename U, typename V>
201float InDetPerfPlot_VertexTruthMatching::getRadialDiff2(const U* vtx1, const V* vtx2) const {
202 return (std::pow((vtx1->x() - vtx2->x()), 2) + std::pow((vtx1->y() - vtx2->y()), 2) + std::pow((vtx1->z() - vtx2->z()), 2));
203}
204
205float InDetPerfPlot_VertexTruthMatching::getLocalPUDensity(const xAOD::TruthVertex* vtxOfInterest, const std::vector<const xAOD::TruthVertex*>& truthHSVertices, const std::vector<const xAOD::TruthVertex*>& truthPUVertices, const float radialWindow) const {
206 float radialWindow2 = std::pow(radialWindow, 2);
207 int nTracksInWindow = 0;
208 float localPUDensity;
209 float radialDiff2;
210 for (const auto& vtx : truthHSVertices) {
211 if (vtx != vtxOfInterest) {
212 radialDiff2 = getRadialDiff2(vtxOfInterest, vtx);
213 if (radialDiff2 < radialWindow2) {
214 nTracksInWindow += 1;
215 }
216 }
217 }
218 for (const auto& vtx : truthPUVertices) {
219 if (vtx != vtxOfInterest) {
220 radialDiff2 = getRadialDiff2(vtxOfInterest, vtx);
221 if (radialDiff2 < radialWindow2) {
222 nTracksInWindow += 1;
223 }
224 }
225 }
226 localPUDensity = static_cast<float>(nTracksInWindow) / (2 * radialWindow);
227 return localPUDensity;
228}
229
231 return std::sqrt(recoVtx->covariancePosition()(2, 2));
232}
233
235 float x = recoVtx->x();
236 float y = recoVtx->y();
237 float xErr2 = recoVtx->covariancePosition()(0, 0);
238 float yErr2 = recoVtx->covariancePosition()(1, 1);
239 float xyCov = recoVtx->covariancePosition()(0, 1);
240 float r2 = std::pow(x, 2) + std::pow(y, 2);
241 return std::sqrt(std::pow(x, 2) / r2 * xErr2 + std::pow(y, 2) / r2 * yErr2 + 2 * x * y / r2 * xyCov);
242}
243
245 const xAOD::TruthVertex* truthVtx = nullptr;
246 if (recoVtx) {
247 const static xAOD::Vertex::Decorator<std::vector<InDetVertexTruthMatchUtils::VertexTruthMatchInfo>> truthMatchingInfos("TruthEventMatchingInfos");
248 try{
249 if (!truthMatchingInfos.isAvailable(*recoVtx)){
250 ATH_MSG_WARNING("TruthEventMatchingInfos DECORATOR not available -- returning nullptr!");
251 return truthVtx;
252 }
253 const std::vector<InDetVertexTruthMatchUtils::VertexTruthMatchInfo>& truthInfos = truthMatchingInfos(*recoVtx);
254 if (!truthInfos.empty()) {
255 const InDetVertexTruthMatchUtils::VertexTruthMatchInfo& truthInfo = truthInfos.at(0);
256 const ElementLink<xAOD::TruthEventBaseContainer> truthEventLink = std::get<0>(truthInfo);
257 if (truthEventLink.isValid() && *truthEventLink) {
258 size_t i_vtx = 0;
259 size_t n_vtx = (*truthEventLink)->nTruthVertices();
260 while(!truthVtx && i_vtx<n_vtx){
261 truthVtx = (*truthEventLink)->truthVertex(i_vtx);
262 i_vtx++;
263 }
264 }
265 }
266 else {
267 ATH_MSG_WARNING("TruthEventMatchingInfos DECORATOR yields empty vector -- returning nullptr!");
268 }
269 }
270 catch (SG::ExcBadAuxVar &){
271 ATH_MSG_WARNING("TruthEventMatchingInfos DECORATOR yields empty vector -- returning nullptr!");
272 }
273 }
274 return truthVtx;
275}
276
277void InDetPerfPlot_VertexTruthMatching::fill(const xAOD::Vertex& vertex, const xAOD::TruthVertex * tvrt, float weight) {
278 // not sure how to deal with this type of histogram
279 if (tvrt) {
280 const float diff_x = vertex.x() - tvrt->x();
281 const float diff_y = vertex.y() - tvrt->y();
282 const float diff_z = vertex.z() - tvrt->z();
283 const AmgSymMatrix(3)& covariance = vertex.covariancePosition();
284 const float err_x = std::abs(Amg::error(covariance, 0)) > 1e-7 ? Amg::error(covariance, 0) : 1000.;
285 const float err_y = std::abs(Amg::error(covariance, 1)) > 1e-7 ? Amg::error(covariance, 1) : 1000.;
286 const float err_z = std::abs(Amg::error(covariance, 2)) > 1e-7 ? Amg::error(covariance, 2) : 1000.;
287 fillHisto(m_vx_x_diff, diff_x, weight);
288 fillHisto(m_vx_x_diff_pull, diff_x / err_x, weight);
289 fillHisto(m_vx_y_diff, diff_y, weight);
290 fillHisto(m_vx_y_diff_pull, diff_y / err_y, weight);
291 fillHisto(m_vx_z_diff, diff_z, weight);
292 fillHisto(m_vx_z_diff_pull, diff_z / err_z, weight);
293
294 if (m_isITk) {
295 static const SG::Accessor<uint8_t> accHasValidTime("hasValidTime");
296 static const SG::Accessor<float> accTime("time");
297 static const SG::Accessor<float> accTimeResolution("timeResolution");
298 if (accHasValidTime.isAvailable(vertex) && accTime.isAvailable(vertex) &&
299 accTimeResolution.isAvailable(vertex)) {
300
301 if (vertex.hasValidTime()) {
302 float diff_time = vertex.time() - tvrt->t() / Gaudi::Units::c_light;
303 float err_time = vertex.timeResolution();
304 fillHisto(m_vx_time_diff, diff_time, weight);
305 fillHisto(m_vx_time_diff_pull, diff_time / err_time, weight);
306 }
307 }
308 }
309 }
310
311 // Get the match type info for each vertex:
312 const static xAOD::Vertex::Decorator<InDetVertexTruthMatchUtils::VertexMatchType> recoVtxMatchTypeInfo("VertexMatchType");
314 if (recoVtxMatchTypeInfo.isAvailable(vertex)) {
315 try {
316 matchType = recoVtxMatchTypeInfo(vertex);
317 ATH_MSG_DEBUG("VERTEX DECORATOR ======= " << matchType << ", with nTRACKS === " << vertex.nTrackParticles() << ", vertex index = " << vertex.index() << " AT (x, y, z) = (" << vertex.x() << ", " << vertex.y() << ", " << vertex.z() << ")");
318 fillHisto(m_vx_type_truth, matchType, weight);
319 }
320 catch (SG::ExcBadAuxVar &) {
321 ATH_MSG_WARNING("VertexMatchType DECORATOR seems to be available, but may be broken ===========");
322 }
323 }
324 else {
325 ATH_MSG_WARNING("VertexMatchType DECORATOR is NOT available ===========");
326 }
327
328} // void InDetPerfPlot_VertexTruthMatching::fill(const xAOD::Vertex& vertex) {
329
331(const xAOD::Vertex* recoHardScatter,
332 const xAOD::VertexContainer& vertexContainer,
333 const std::vector<const xAOD::TruthVertex*>& truthHSVertices,
334 const std::vector<const xAOD::TruthVertex*>& truthPUVertices,
335 float actualMu, float weight) {
336
337 // Fill our histograms
339 fillHisto(m_vx_hs_classification, hsType, weight);
340
341 int nRecoVertices = static_cast<int>(vertexContainer.size()-1); //Not counting the dummy vertex of type 0
342
343 // Get the truth HS vertex
344 const xAOD::TruthVertex* truthHSVtx = nullptr;
345
346 // Check that we have *exactly* 1 truth HS vertex
347 if (!truthHSVertices.empty()) {
348 if (truthHSVertices.size() != 1) {
349 ATH_MSG_WARNING("Size of truth HS vertex vector is >1 -- only using the first one in the vector.");
350 }
351 truthHSVtx = truthHSVertices.at(0);
352 }
353 else {
354 ATH_MSG_WARNING("Size of truth HS vertex vector is 0 -- assuming truth HS vertex to NOT be reconstructed.");
355 }
356
357 if (!truthHSVtx){
358 ATH_MSG_INFO("No truthHSVtx vertex - not filling vertex truth matching.");
359 return;
360 }
361
362 bool isHSVtx_dist_matched = recoHardScatter ? getRadialDiff2(recoHardScatter, truthHSVtx) < std::pow(m_cutMinTruthRecoRadialDiff, 2) : false;
363 fillHisto(m_vx_hs_sel_eff_dist_vs_nReco, nRecoVertices, isHSVtx_dist_matched, weight);
364
365 // Best reco HS vertex identified via truth HS weights
366 const xAOD::Vertex* bestRecoHSVtx_truth = InDetVertexTruthMatchUtils::bestHardScatterMatch(vertexContainer);
367
368 bool isHSVtx_vtx_matched = bestRecoHSVtx_truth && (recoHardScatter == bestRecoHSVtx_truth);
369 fillHisto(m_vx_hs_sel_eff_mu, actualMu, isHSVtx_vtx_matched, weight);
370 fillHisto(m_vx_hs_sel_eff_vs_nReco, nRecoVertices, isHSVtx_vtx_matched, weight);
371
372 // Did we successfully reconstruct our truth HS vertex?
373 bool isHSVtx_reco = bestRecoHSVtx_truth ? getRadialDiff2(bestRecoHSVtx_truth, truthHSVtx) < std::pow(m_cutMinTruthRecoRadialDiff, 2) : false;
374 fillHisto(m_vx_hs_reco_eff_mu, actualMu, isHSVtx_reco, weight);
375
376 float residual_z = isHSVtx_reco ? truthHSVtx->z() - bestRecoHSVtx_truth->z() : -9999.;
377 if(isHSVtx_reco) fillHisto(m_resHelper_mu_hsVxTruthLong, actualMu, residual_z, weight);
378
379 if (m_detailLevel >= 200) {
380 // Inclusive:
381 int nTruthVertices = static_cast<int>(truthHSVertices.size() + truthPUVertices.size());
382 fillHisto(m_vx_nReco_vs_nTruth_inclusive, nTruthVertices, nRecoVertices, weight);
383 fillHisto(m_vx_nTruth, nTruthVertices, weight);
384
385 // Let's also plot the vertices by vertex match type:
386 const static xAOD::Vertex::Decorator<InDetVertexTruthMatchUtils::VertexMatchType> recoVtxMatchTypeInfo("VertexMatchType");
387 std::map<InDetVertexTruthMatchUtils::VertexMatchType, int> breakdown = {};
393
394 fillHisto(m_vx_hs_sel_eff_dist, nTruthVertices, isHSVtx_dist_matched, weight);
395
396 //Calculating the local PU density around the true HS vertex
397 float localPUDensity = getLocalPUDensity(truthHSVtx, truthHSVertices, truthPUVertices);
398 fillHisto(m_vx_PUdensity, localPUDensity, weight);
399 fillHisto(m_vx_nTruth_vs_PUdensity, nTruthVertices, localPUDensity, weight);
400
401 fillHisto(m_vx_hs_sel_eff, localPUDensity, isHSVtx_vtx_matched, weight);
402 fillHisto(m_vx_hs_sel_eff_vs_ntruth, nTruthVertices, isHSVtx_vtx_matched, weight);
403
404 // add variables here so that they are in correct scope (outside loop over vertices)
405 std::map<int, std::map<InDetVertexTruthMatchUtils::VertexMatchType, float>> numbers;
406
407 // variables for delta z between the HS and the closest one
408 float vx_hs_mindz=9999.;
409
410 // Iterate over vertices:
411 for (const auto& vertex : vertexContainer.stdcont()) {
412
413 unsigned int nTrackPart = vertex->nTrackParticles();
414 InDetVertexTruthMatchUtils::VertexMatchType matchType = recoVtxMatchTypeInfo(*vertex);
415 breakdown[matchType] += 1;
416
417 // Skip dummy vertex (last one in the container)
418 if (vertex->vertexType() == xAOD::VxType::NoVtx) {
419 continue;
420 }
421
422 fill(*vertex);
423
424 const xAOD::TruthVertex *matchVertex = getTruthVertex(vertex);
425 if(matchVertex){
426
427 std::vector<float> residuals = {
428 matchVertex->x() - vertex->x(),
429 matchVertex->y() - vertex->y(),
430 matchVertex->z() - vertex->z() };
431
432 const AmgSymMatrix(3)& covariance = vertex->covariancePosition();
433
434 std::vector<float> pulls;
435 for(unsigned int i=0; i<3; i++){
436 float vtxerr = Amg::error(covariance, i);
437 float pull = std::abs(vtxerr) > 1e-7 ? residuals[i]/vtxerr : 1000.;
438 pulls.push_back(pull);
439 }
440
441 fillHisto(m_vx_all_x_pull, pulls[0], weight);
442 fillHisto(m_vx_all_y_pull, pulls[1], weight);
443 fillHisto(m_vx_all_z_pull, pulls[2], weight);
444
445 float localPUDensity = getLocalPUDensity(matchVertex, truthHSVertices, truthPUVertices);
446
447 fillHisto(m_vx_all_truth_x_res_vs_PU, localPUDensity, pulls[0], weight);
448 fillHisto(m_vx_all_truth_y_res_vs_PU, localPUDensity, pulls[1], weight);
449 fillHisto(m_vx_all_truth_z_res_vs_PU, localPUDensity, pulls[2], weight);
450
451 fillHisto(m_vx_all_x_res, residuals[0], weight);
452 fillHisto(m_vx_all_y_res, residuals[1], weight);
453 fillHisto(m_vx_all_z_res, residuals[2], weight);
454
455 fillHisto(m_vx_all_truth_x_pull_vs_PU, localPUDensity, pulls[0], weight);
456 fillHisto(m_vx_all_truth_y_pull_vs_PU, localPUDensity, pulls[1], weight);
457 fillHisto(m_vx_all_truth_z_pull_vs_PU, localPUDensity, pulls[2], weight);
458
459 fillHisto(m_vx_all_truth_x_res_vs_nTrk, nTrackPart, residuals[0], weight);
460 fillHisto(m_vx_all_truth_y_res_vs_nTrk, nTrackPart, residuals[1], weight);
461 fillHisto(m_vx_all_truth_z_res_vs_nTrk, nTrackPart, residuals[2], weight);
462
463 fillHisto(m_vx_all_truth_x_pull_vs_nTrk, nTrackPart, pulls[0], weight);
464 fillHisto(m_vx_all_truth_y_pull_vs_nTrk, nTrackPart, pulls[1], weight);
465 fillHisto(m_vx_all_truth_z_pull_vs_nTrk, nTrackPart, pulls[2], weight);
466 }
467
468 // New Expert histograms for observables for vertex classifications for HS and PU
469 // For each vertex, loop over all tracks and get sumpt and sum of charges
470 // also use this to get the z asymmetry around the vertex.
471
472 // Declaring variables for the observables
473 const xAOD::TrackParticle* trackTmp = nullptr;
474 float sumPt =0;
475 float minpt = 20000 ; // minimum sum pt required for the 'All' vertices plots - 20 GeV
476 float trackPt = 0;
477
478 // variables for calculation of delta Z asymmetry and delta d asymmetry
479 float z_asym = 0;
480 float sumDZ = 0;
481 float deltaZ =0;
482 float modsumDZ =0;
483 float weighted_sumDZ = 0;
484 float weighted_deltaZ = 0;
485 float weighted_modsumDZ = 0;
486 float weighted_z_asym =0;
487
488 // make vector
489 std::vector<float> track_deltaZ;
490 std::vector<float> track_deltaPt;
491 std::vector<float> track_deltaZ_weighted;
492
493 // loop over tracks
494 for (size_t i = 0; i < nTrackPart; i++) {
495 trackTmp = vertex->trackParticle(i);
496
497 if (trackTmp) {
498 trackPt = trackTmp->pt(); // MeV
499 sumPt = sumPt + trackPt; // in MeV
500 deltaZ = trackTmp->z0() + trackTmp->vz() - vertex->z();
501 track_deltaZ.push_back(deltaZ);
502 // get the track weight for each track to get the deltaZ/trk_weight
503 float trk_weight = vertex->trackWeight(i);
504 weighted_deltaZ = deltaZ*trk_weight;
505 // sum of delta z
506 sumDZ = sumDZ + deltaZ;
507 modsumDZ = modsumDZ + std::abs(deltaZ);
508 weighted_sumDZ = weighted_sumDZ + weighted_deltaZ;
509 weighted_modsumDZ = weighted_modsumDZ + std::abs(weighted_deltaZ);
510 }
511 } // end loop over tracks
512
513 if (modsumDZ >0) z_asym = sumDZ/modsumDZ;
514 if (weighted_modsumDZ >0) weighted_z_asym = weighted_sumDZ/weighted_modsumDZ;
515
516 double number_tracks = track_deltaZ.size(); // get number of tracks
517
518 // calculate average
519 double mean_Dz = !track_deltaZ.empty() ? sumDZ/number_tracks : 0.;
520
521 double z_sd = 0; // standard deviation
522 double z_skew = 0; // skewness of DeltaZ asymmetry
523 double z_kurt = 0; // Kurtosis of DeltaZ asymmetry
524 double z_var=0; // variance of DeltaZ
525 double z_zbar=0; // for use in calculation below
526
527 for (auto i : track_deltaZ) {
528 z_zbar = (i - mean_Dz);
529 z_var += std::pow(z_zbar,2);
530 z_skew += std::pow(z_zbar,3);
531 z_kurt += std::pow(z_zbar,4);
532 }
533
534 if (number_tracks>1) {
535 z_var = z_var / (number_tracks -1);
536 z_sd = std::sqrt(z_var);
537 if (z_sd>0) {
538 z_skew = z_skew / ((number_tracks -1)*std::pow(z_sd,3));
539 z_kurt = z_kurt / ((number_tracks -1)*std::pow(z_sd,4));
540 }
541 }
542
543 float ndf = vertex->numberDoF();
544 float chi2_per_ndf = ndf>0 ? vertex->chiSquared()/ndf : 0.;
545
546 std::vector<int> categories;
547 if(vertex == bestRecoHSVtx_truth) categories.push_back(1);
548 else categories.push_back(0);
549 // fill some histograms that contain both HS and PU above a min pt - say 20GeV
550 if (sumPt > minpt) categories.push_back(2);
551
552 for(const auto& cat : categories){
553 // Count the number of vertices for each type per event
554 numbers[cat][matchType]++;
555
559 fillHisto(m_vx_ntracks[cat][matchType], nTrackPart, weight);
560 fillHisto(m_vx_sumpT[cat][matchType], sumPt, weight);
561 fillHisto(m_vx_z_asym[cat][matchType], z_asym, weight);
562 fillHisto(m_vx_z_asym_weighted[cat][matchType], weighted_z_asym, weight);
563 fillHisto(m_vx_chi2Over_ndf[cat][matchType], chi2_per_ndf, weight);
564 fillHisto(m_vx_z0_skewness[cat][matchType], z_skew, weight);
565 fillHisto(m_vx_z0_kurtosis[cat][matchType], z_kurt, weight);
566
567 for (const float& trkWeight : vertex->trackWeights()) {
568 fillHisto(m_vx_track_weight[cat][matchType], trkWeight, weight);
569 float norm_track_weight = number_tracks>0. ? trkWeight/number_tracks : 0.;
570 fillHisto(m_vx_normalised_track_weight[cat][matchType], norm_track_weight, weight);
571 }
572 }
573 }
574
575 // delta z between HS and nearby vertices
576 if(bestRecoHSVtx_truth && bestRecoHSVtx_truth != vertex) {
577 float dz = bestRecoHSVtx_truth->z() - vertex->z();
578 if(std::abs(dz) < std::abs(vx_hs_mindz)) vx_hs_mindz = dz;
579 }
580
581 // loop over vertices again for dz of every vertices pair
582 for (const auto& vertex2 : vertexContainer.stdcont()) {
583 if (vertex2->vertexType() == xAOD::VxType::NoVtx) continue;
584 if(vertex2 == vertex) continue;
585 fillHisto(m_vx_all_dz, vertex->z() - vertex2->z(), 0.5*weight);
586 }
587
588 } // end loop over vertices
589
590 // new histos to count number of vertices per event
591 std::vector<int> categories = {0, 1, 2};
592 std::vector<InDetVertexTruthMatchUtils::VertexMatchType> types = {
597
598 for(const auto& cat : categories) {
599 for(const auto& type : types) {
600 fillHisto(m_vx_nVertices[cat][type], numbers[cat][type], weight);
601 }
602 }
603
604 // new histo to delta z between HS and the closest one
605 fillHisto(m_vx_hs_mindz, vx_hs_mindz, weight);
606
607 // Now fill plots relating to the reconstruction of our truth HS vertex (efficiency and resolutions)
608 if (!truthHSVertices.empty()) {
609 if (isHSVtx_reco) {
610 fillHisto(m_vx_hs_reco_eff, localPUDensity, 1, weight);
611 fillHisto(m_vx_hs_reco_sel_eff, localPUDensity, (recoHardScatter == bestRecoHSVtx_truth), weight);
612 fillHisto(m_vx_hs_reco_eff_vs_ntruth, nTruthVertices, 1, weight);
613 fillHisto(m_vx_hs_reco_sel_eff_vs_ntruth, nTruthVertices, (recoHardScatter == bestRecoHSVtx_truth), weight);
614
615 fillHisto(m_vx_hs_reco_long_reso, localPUDensity,
616 getRecoLongitudinalReso(bestRecoHSVtx_truth), weight);
617 fillHisto(m_vx_hs_reco_trans_reso, localPUDensity,
618 getRecoTransverseReso(bestRecoHSVtx_truth), weight);
619
620 float residual_x = truthHSVtx->x() - bestRecoHSVtx_truth->x();
621 float residual_y = truthHSVtx->y() - bestRecoHSVtx_truth->y();
622 float residual_r = std::hypot(residual_x, residual_y);
623
624 fillHisto(m_resHelper_PUdensity_hsVxTruthLong, localPUDensity, residual_z, weight);
625 fillHisto(m_resHelper_PUdensity_hsVxTruthTransv, localPUDensity, residual_r, weight);
626
627 std::vector<float> residuals = {residual_x, residual_y, residual_z};
628
629 const AmgSymMatrix(3)& covariance = bestRecoHSVtx_truth->covariancePosition();
630
631 std::vector<float> pulls;
632 for(unsigned int i=0; i<3; i++){
633 float vtxerr = Amg::error(covariance, i);
634 float pull = std::abs(vtxerr) > 1e-7 ? residuals[i]/vtxerr : 1000.;
635 pulls.push_back(pull);
636 }
637
638 fillHisto(m_vx_hs_x_pull, pulls[0], weight);
639 fillHisto(m_vx_hs_y_pull, pulls[1], weight);
640 fillHisto(m_vx_hs_z_pull, pulls[2], weight);
641
642 fillHisto(m_vx_hs_truth_x_res_vs_PU, localPUDensity, residuals[0], weight);
643 fillHisto(m_vx_hs_truth_y_res_vs_PU, localPUDensity, residuals[1], weight);
644 fillHisto(m_vx_hs_truth_z_res_vs_PU, localPUDensity, residuals[2], weight);
645
646 fillHisto(m_vx_hs_x_res, residuals[0], weight);
647 fillHisto(m_vx_hs_y_res, residuals[1], weight);
648 fillHisto(m_vx_hs_z_res, residuals[2], weight);
649
650 fillHisto(m_vx_hs_truth_x_pull_vs_PU, localPUDensity, pulls[0], weight);
651 fillHisto(m_vx_hs_truth_y_pull_vs_PU, localPUDensity, pulls[1], weight);
652 fillHisto(m_vx_hs_truth_z_pull_vs_PU, localPUDensity, pulls[2], weight);
653
654 int nTrackPart = bestRecoHSVtx_truth->nTrackParticles();
655 fillHisto(m_vx_hs_truth_x_res_vs_nTrk, nTrackPart, residuals[0], weight);
656 fillHisto(m_vx_hs_truth_y_res_vs_nTrk, nTrackPart, residuals[1], weight);
657 fillHisto(m_vx_hs_truth_z_res_vs_nTrk, nTrackPart, residuals[2], weight);
658
659 fillHisto(m_vx_hs_truth_x_pull_vs_nTrk, nTrackPart, pulls[0], weight);
660 fillHisto(m_vx_hs_truth_y_pull_vs_nTrk, nTrackPart, pulls[1], weight);
661 fillHisto(m_vx_hs_truth_z_pull_vs_nTrk, nTrackPart, pulls[2], weight);
662
663 } else {
664 fillHisto(m_vx_hs_reco_eff, localPUDensity, 0, weight);
665 fillHisto(m_vx_hs_reco_eff_vs_ntruth, nTruthVertices, 0, weight);
666 }
667 }
668
674
675 // And by hardscatter type:
676 switch (hsType) {
678 fillHisto(m_vx_nReco_vs_nTruth_clean, nTruthVertices, nRecoVertices, weight);
679 break;
680 }
682 fillHisto(m_vx_nReco_vs_nTruth_lowpu, nTruthVertices, nRecoVertices, weight);
683 break;
684 }
686 fillHisto(m_vx_nReco_vs_nTruth_highpu, nTruthVertices, nRecoVertices, weight);
687 break;
688 }
690 fillHisto(m_vx_nReco_vs_nTruth_hssplit, nTruthVertices, nRecoVertices, weight);
691 break;
692 }
694 fillHisto(m_vx_nReco_vs_nTruth_none, nTruthVertices, nRecoVertices, weight);
695 break;
696 }
697 default: {
698 break;
699 }
700 } // End of switch
701
702 } // end of Expert plots - (if (m_detailLevel >= 200))
703
704} // end InDetPerfPlot_VertexTruthMatching::fill(const xAOD::VertexContainer& vertexContainer, const std::vector<const xAOD::TruthVertex*>& truthHSVertices, const std::vector<const xAOD::TruthVertex*>& truthPUVertices)
705
706
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define AmgSymMatrix(dim)
static const std::vector< std::string > types
#define y
#define x
const PtrVector & stdcont() const
Return the underlying std::vector of the container.
size_type size() const noexcept
Returns the number of elements in the collection.
static const xAOD::Vertex * getHSRecoVertexSumPt2(const xAOD::VertexContainer &recoVertices)
void fill(const xAOD::Vertex &vertex, const xAOD::TruthVertex *tvrt=0, float weight=1.0)
TH1 * m_vx_hs_classification
hardscatter classification
static float getRecoLongitudinalReso(const xAOD::Vertex *recoVtx)
float getLocalPUDensity(const xAOD::TruthVertex *vtxOfInterest, const std::vector< const xAOD::TruthVertex * > &truthHSVertices, const std::vector< const xAOD::TruthVertex * > &truthPUVertices, const float radialWindow=2.0) const
TProfile * m_vx_nReco_vs_nTruth_inclusive
vertex reco efficiency
static float getRecoTransverseReso(const xAOD::Vertex *recoVtx)
float getRadialDiff2(const U *vtx1, const V *vtx2) const
const xAOD::TruthVertex * getTruthVertex(const xAOD::Vertex *recoVtx) const
InDetPerfPlot_VertexTruthMatching(InDetPlotBase *pParent, const std::string &dirName, const int detailLevel=10, bool isITk=false)
IDPVM::ResolutionHelper::methods m_resolutionMethod
static void fillHisto(TProfile *pTprofile, const float bin, const float weight, const float weight2=1.0)
InDetPlotBase(InDetPlotBase *pParent, const std::string &dirName)
Constructor taking parent node and directory name for plots.
void book(Htype *&pHisto, std::string_view histoIdentifier, std::string_view nameOverride="", std::string_view folder="default")
Helper method to book histograms using an identifier string.
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Exception — Attempt to retrieve nonexistent aux data item.
float z0() const
Returns the parameter.
float vz() const
The z origin for the parameters.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
float z() const
Vertex longitudinal distance along the beam line form the origin.
float y() const
Vertex y displacement.
float t() const
Vertex time.
float x() const
Vertex x displacement.
float z() const
Returns the z position.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
float y() const
Returns the y position.
float x() const
Returns the x position.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Class to retrieve associated truth from a track, implementing a cached response.
std::tuple< ElementLink< xAOD::TruthEventBaseContainer >, float, float > VertexTruthMatchInfo
const xAOD::Vertex * bestHardScatterMatch(const xAOD::VertexContainer &vxContainer)
HardScatterType classifyHardScatter(const xAOD::VertexContainer &vxContainer)
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.