333 const std::vector<const xAOD::TruthVertex*>& truthHSVertices,
334 const std::vector<const xAOD::TruthVertex*>& truthPUVertices,
335 float actualMu,
float weight) {
341 int nRecoVertices =
static_cast<int>(vertexContainer.
size()-1);
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.");
351 truthHSVtx = truthHSVertices.at(0);
354 ATH_MSG_WARNING(
"Size of truth HS vertex vector is 0 -- assuming truth HS vertex to NOT be reconstructed.");
358 ATH_MSG_INFO(
"No truthHSVtx vertex - not filling vertex truth matching.");
368 bool isHSVtx_vtx_matched = bestRecoHSVtx_truth && (recoHardScatter == bestRecoHSVtx_truth);
376 float residual_z = isHSVtx_reco ? truthHSVtx->
z() - bestRecoHSVtx_truth->
z() : -9999.;
381 int nTruthVertices =
static_cast<int>(truthHSVertices.size() + truthPUVertices.size());
386 const static xAOD::Vertex::Decorator<InDetVertexTruthMatchUtils::VertexMatchType> recoVtxMatchTypeInfo(
"VertexMatchType");
387 std::map<InDetVertexTruthMatchUtils::VertexMatchType, int> breakdown = {};
397 float localPUDensity =
getLocalPUDensity(truthHSVtx, truthHSVertices, truthPUVertices);
405 std::map<int, std::map<InDetVertexTruthMatchUtils::VertexMatchType, float>> numbers;
408 float vx_hs_mindz=9999.;
411 for (
const auto& vertex : vertexContainer.
stdcont()) {
413 unsigned int nTrackPart = vertex->nTrackParticles();
415 breakdown[matchType] += 1;
427 std::vector<float> residuals = {
428 matchVertex->
x() - vertex->x(),
429 matchVertex->
y() - vertex->y(),
430 matchVertex->
z() - vertex->z() };
432 const AmgSymMatrix(3)& covariance = vertex->covariancePosition();
434 std::vector<float> pulls;
435 for(
unsigned int i=0; i<3; i++){
437 float pull = std::abs(vtxerr) > 1e-7 ? residuals[i]/vtxerr : 1000.;
438 pulls.push_back(pull);
445 float localPUDensity =
getLocalPUDensity(matchVertex, truthHSVertices, truthPUVertices);
475 float minpt = 20000 ;
483 float weighted_sumDZ = 0;
484 float weighted_deltaZ = 0;
485 float weighted_modsumDZ = 0;
486 float weighted_z_asym =0;
489 std::vector<float> track_deltaZ;
490 std::vector<float> track_deltaPt;
491 std::vector<float> track_deltaZ_weighted;
494 for (
size_t i = 0; i < nTrackPart; i++) {
495 trackTmp = vertex->trackParticle(i);
498 trackPt = trackTmp->
pt();
499 sumPt = sumPt + trackPt;
500 deltaZ = trackTmp->
z0() + trackTmp->
vz() - vertex->z();
501 track_deltaZ.push_back(deltaZ);
503 float trk_weight = vertex->trackWeight(i);
504 weighted_deltaZ = deltaZ*trk_weight;
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);
513 if (modsumDZ >0) z_asym = sumDZ/modsumDZ;
514 if (weighted_modsumDZ >0) weighted_z_asym = weighted_sumDZ/weighted_modsumDZ;
516 double number_tracks = track_deltaZ.size();
519 double mean_Dz = !track_deltaZ.empty() ? sumDZ/number_tracks : 0.;
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);
534 if (number_tracks>1) {
535 z_var = z_var / (number_tracks -1);
536 z_sd = std::sqrt(z_var);
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));
543 float ndf = vertex->numberDoF();
544 float chi2_per_ndf = ndf>0 ? vertex->chiSquared()/ndf : 0.;
546 std::vector<int> categories;
547 if(vertex == bestRecoHSVtx_truth) categories.push_back(1);
548 else categories.push_back(0);
550 if (sumPt > minpt) categories.push_back(2);
552 for(
const auto& cat : categories){
554 numbers[cat][matchType]++;
567 for (
const float& trkWeight : vertex->trackWeights()) {
569 float norm_track_weight = number_tracks>0. ? trkWeight/number_tracks : 0.;
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;
582 for (
const auto& vertex2 : vertexContainer.
stdcont()) {
584 if(vertex2 == vertex)
continue;
591 std::vector<int> categories = {0, 1, 2};
592 std::vector<InDetVertexTruthMatchUtils::VertexMatchType>
types = {
598 for(
const auto& cat : categories) {
608 if (!truthHSVertices.empty()) {
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);
627 std::vector<float> residuals = {residual_x, residual_y, residual_z};
629 const AmgSymMatrix(3)& covariance = bestRecoHSVtx_truth->covariancePosition();
631 std::vector<float> pulls;
632 for(
unsigned int i=0; i<3; i++){
634 float pull = std::abs(vtxerr) > 1e-7 ? residuals[i]/vtxerr : 1000.;
635 pulls.push_back(pull);