198 std::vector<int64_t>&
201 std::vector<int64_t>& top_reco_indices,
203 std::vector<int64_t>& w_reco_indices,
205 float& top_reco_score,
210 if (hyperGraph.
nHyperEdges() !=
static_cast<int>(hyperedge_scores.size()))
211 throw std::runtime_error(
212 "Number of defined hyperedges does not match with the ones from model "
214 if (hyperGraph.
nEdges() !=
static_cast<int>(edge_scores.size()))
215 throw std::runtime_error(
216 "Number of defined graph edges does not match with the ones from model "
219 for (std::size_t i = 0; i < hyperedge_scores.size(); i++) {
220 if (hyperedge_masks.at(i) == 0)
223 if (hyperedge_scores.at(i).at(0) > top_reco_score) {
224 top_reco_score = hyperedge_scores.at(i).at(0);
229 w_reco_indices = {-1, -1};
231 std::vector<std::vector<int64_t>> w_candidates =
233 for (std::size_t j = 0; j < w_candidates.size(); j++) {
235 float bi_directional_sum = 0;
236 for (std::size_t k = 0; k < edge_scores.size(); k++) {
237 if (w_candidates.at(j).at(0) ==
239 w_candidates.at(j).at(1) ==
241 bi_directional_sum += edge_scores.at(k).at(0);
243 if (w_candidates.at(j).at(1) ==
245 w_candidates.at(j).at(0) ==
247 bi_directional_sum += edge_scores.at(k).at(0);
250 if (bi_directional_sum / 2 > w_reco_score) {
251 w_reco_score = bi_directional_sum / 2;
252 w_reco_indices = w_candidates.at(j);
268 std::vector<int64_t>&
271 std::vector<int64_t>&
274 std::vector<int64_t>&
277 float& top_reco_score,
280 std::vector<int64_t>& top_reco_ids,
282 const std::vector<std::vector<int64_t>>&
283 allowed_decay_modes) {
285 if (hyperGraph.
nHyperEdges() !=
static_cast<int>(hyperedge_scores.size()))
286 throw std::runtime_error(
287 "Number of defined hyperedges does not match with the ones from model "
289 if (hyperGraph.
nEdges() !=
static_cast<int>(edge_scores.size()))
290 throw std::runtime_error(
291 "Number of defined graph edges does not match with the ones from model "
293 if (allowed_decay_modes.empty())
294 throw std::runtime_error(
"No allowed decay modes available!");
296 for (std::size_t i = 0; i < hyperedge_scores.size(); i++) {
297 if (hyperedge_masks.at(i) == 0)
299 if (hyperedge_scores.at(i).at(0) > top_reco_score) {
301 std::vector<int64_t> top_candidate_indices = {
309 std::size_t beforeLastPosition = hyperGraph.
getNodeFeats(0).size() - 2;
312 .at(beforeLastPosition));
315 .at(beforeLastPosition));
318 .at(beforeLastPosition));
319 std::vector<int64_t> top_candidate_ids = {
static_cast<int64_t
>(id_1),
320 static_cast<int64_t
>(id_2),
321 static_cast<int64_t
>(id_3)};
325 top_reco_score = hyperedge_scores.at(i).at(0);
326 top_reco_ids = top_candidate_ids;
327 top_reco_indices = top_candidate_indices;
329 w_reco_indices = {-1, -1};
332 std::vector<std::vector<int64_t>> w_candidates =
334 for (std::size_t j = 0; j < w_candidates.size(); j++) {
336 float bi_directional_sum = 0;
337 for (std::size_t k = 0; k < edge_scores.size(); k++) {
338 if (w_candidates.at(j).at(0) ==
340 w_candidates.at(j).at(1) ==
342 bi_directional_sum += edge_scores.at(k).at(0);
344 if (w_candidates.at(j).at(1) ==
346 w_candidates.at(j).at(0) ==
348 bi_directional_sum += edge_scores.at(k).at(0);
351 if (bi_directional_sum / 2 > w_reco_score) {
352 w_reco_score = bi_directional_sum / 2;
353 w_reco_indices = w_candidates.at(j);
357 w_reco_indices =
findWInTopLep(top_reco_indices, top_reco_ids);
358 float bi_directional_sum = 0;
359 for (std::size_t k = 0; k < edge_scores.size(); k++) {
360 if (w_reco_indices.at(0) ==
362 w_reco_indices.at(1) ==
364 bi_directional_sum += edge_scores.at(k).at(0);
366 if (w_reco_indices.at(0) ==
368 w_reco_indices.at(1) ==
370 bi_directional_sum += edge_scores.at(k).at(0);
373 w_reco_score = bi_directional_sum / 2;
383 const scores& edge_scores,
385 std::vector<float>& reco_scores,
386 std::vector<std::string>& reco_labels) {
388 std::vector<int64_t> top1_reco_indices(3, -1);
389 std::vector<int64_t> top2_reco_indices(3, -1);
390 std::vector<int64_t> w1_reco_indices(2, -1);
391 std::vector<int64_t> w2_reco_indices(2, -1);
393 float top1_reco_score = 0;
394 float top2_reco_score = 0;
395 float w1_reco_score = 0;
396 float w2_reco_score = 0;
399 std::vector<int64_t> top1_masks(hyperedge_scores.size(), 1);
401 top1_reco_indices, w1_reco_indices, top1_reco_score,
405 if (top1_reco_indices == std::vector<int64_t>(3, -1)) {
406 reco_labels.push_back(
"HyPER_Reco_Top1");
407 reco_indices.push_back(top1_reco_indices);
408 reco_scores.push_back(top1_reco_score);
409 reco_labels.push_back(
"HyPER_Reco_Top2");
410 reco_indices.push_back(top2_reco_indices);
411 reco_scores.push_back(top2_reco_score);
412 reco_labels.push_back(
"HyPER_Reco_W1");
413 reco_indices.push_back(w1_reco_indices);
414 reco_scores.push_back(w1_reco_score);
415 reco_labels.push_back(
"HyPER_Reco_W2");
416 reco_indices.push_back(w2_reco_indices);
417 reco_scores.push_back(w2_reco_score);
422 std::vector<int64_t> top2_masks;
423 for (std::size_t i = 0;
424 i < static_cast<std::size_t>(hyperGraph.
nHyperEdges()); i++) {
426 top2_masks.push_back(0);
428 top2_masks.push_back(1);
433 top2_reco_indices, w2_reco_indices, top2_reco_score,
437 reco_labels.push_back(
"HyPER_Reco_Top1");
438 reco_indices.push_back(top1_reco_indices);
439 reco_scores.push_back(top1_reco_score);
440 reco_labels.push_back(
"HyPER_Reco_Top2");
441 reco_indices.push_back(top2_reco_indices);
442 reco_scores.push_back(top2_reco_score);
443 reco_labels.push_back(
"HyPER_Reco_W1");
444 reco_indices.push_back(w1_reco_indices);
445 reco_scores.push_back(w1_reco_score);
446 reco_labels.push_back(
"HyPER_Reco_W2");
447 reco_indices.push_back(w2_reco_indices);
448 reco_scores.push_back(w2_reco_score);
455 const scores& hyperedge_scores,
457 std::vector<float>& reco_scores,
458 std::vector<std::string>& reco_labels,
459 std::vector<std::vector<int64_t>>& reco_ids,
460 float& reco_classification_score) {
461 using namespace asg::msgUserCode;
463 std::vector<int64_t> top1_reco_indices(3, -1);
464 std::vector<int64_t> top2_reco_indices(3, -1);
465 std::vector<int64_t> w1_reco_indices(2, -1);
466 std::vector<int64_t> w2_reco_indices(2, -1);
468 float top1_reco_score = 0;
469 float top2_reco_score = 0;
470 float w1_reco_score = 0;
471 float w2_reco_score = 0;
473 std::vector<int64_t> top1_reco_ids(3, -1);
474 std::vector<int64_t> top2_reco_ids(3, -1);
477 setMsgLevel(MSG::INFO);
478 ANA_MSG_INFO(
"Reconstructing TtbarSingleLepton top quarks...");
480 for (
const auto& he_score : hyperedge_scores) {
484 for (
const auto& e_score : edge_scores) {
487 ANA_MSG_INFO(
"Working with this classification score:");
492 reco_classification_score = classification_score.at(0).at(0);
495 std::vector<std::vector<int64_t>> allowed_decays = {
504 std::vector<int64_t> top1_masks(hyperedge_scores.size(), 1);
505 RecoTop(hyperGraph, edge_scores, hyperedge_scores, top1_masks,
506 top1_reco_indices, w1_reco_indices, top1_reco_score, w1_reco_score,
507 top1_reco_ids, allowed_decays);
509 ANA_MSG_INFO(
"Top1 reco indices: " << top1_reco_indices.at(0) <<
" "
510 << top1_reco_indices.at(1) <<
" "
511 << top1_reco_indices.at(2));
513 ANA_MSG_INFO(
"W1 reco indices: " << w1_reco_indices.at(0) <<
" "
514 << w1_reco_indices.at(1));
519 if (top1_reco_indices == std::vector<int64_t>(3, -1)) {
521 reco_labels.push_back(
"HyPER_Reco_TopHad");
522 reco_indices.push_back(top1_reco_indices);
523 reco_scores.push_back(top1_reco_score);
524 reco_ids.push_back(top1_reco_ids);
525 reco_labels.push_back(
"HyPER_Reco_TopLep");
526 reco_indices.push_back(top2_reco_indices);
527 reco_scores.push_back(top2_reco_score);
528 reco_ids.push_back(top2_reco_ids);
529 reco_labels.push_back(
"HyPER_Reco_WHad");
530 reco_indices.push_back(w1_reco_indices);
531 reco_scores.push_back(w1_reco_score);
532 reco_labels.push_back(
"HyPER_Reco_WLep");
533 reco_indices.push_back(w2_reco_indices);
534 reco_scores.push_back(w2_reco_score);
539 std::vector<int64_t> top2_masks;
540 for (std::size_t i = 0;
541 i < static_cast<std::size_t>(hyperGraph.
nHyperEdges()); i++) {
543 top2_masks.push_back(0);
545 top2_masks.push_back(1);
549 bool top1_is_hadronic =
false;
553 top1_is_hadronic =
true;
566 RecoTop(hyperGraph, edge_scores, hyperedge_scores, top2_masks,
567 top2_reco_indices, w2_reco_indices, top2_reco_score, w2_reco_score,
568 top2_reco_ids, allowed_decays);
570 ANA_MSG_INFO(
"Top2 reco indices: " << top2_reco_indices.at(0) <<
" "
571 << top2_reco_indices.at(1) <<
" "
572 << top2_reco_indices.at(2));
574 ANA_MSG_INFO(
"W2 reco indices: " << w2_reco_indices.at(0) <<
" "
575 << w2_reco_indices.at(1));
580 bool both_tops_reco =
true;
581 if (top2_reco_indices == std::vector<int64_t>(3, -1))
582 both_tops_reco =
false;
586 if (top1_is_hadronic && both_tops_reco) {
590 if (!top1_is_hadronic) {
597 ANA_MSG_INFO(
"Top1 reco indices: " << top1_reco_indices.at(0) <<
" "
598 << top1_reco_indices.at(1) <<
" "
599 << top1_reco_indices.at(2));
600 ANA_MSG_INFO(
"Top2 reco indices: " << top2_reco_indices.at(0) <<
" "
601 << top2_reco_indices.at(1) <<
" "
602 << top2_reco_indices.at(2));
603 ANA_MSG_INFO(
"W1 reco indices: " << w1_reco_indices.at(0) <<
" "
604 << w1_reco_indices.at(1));
605 ANA_MSG_INFO(
"W2 reco indices: " << w2_reco_indices.at(0) <<
" "
606 << w2_reco_indices.at(1));
613 ANA_MSG_INFO(
"Top1 reco IDs: " << top1_reco_ids.at(0) <<
" "
614 << top1_reco_ids.at(1) <<
" "
615 << top1_reco_ids.at(2));
616 ANA_MSG_INFO(
"Top2 reco IDs: " << top2_reco_ids.at(0) <<
" "
617 << top2_reco_ids.at(1) <<
" "
618 << top2_reco_ids.at(2));
622 if (top1_is_hadronic) {
623 reco_labels.push_back(
"HyPER_Reco_TopHad");
624 reco_indices.push_back(top1_reco_indices);
625 reco_scores.push_back(top1_reco_score);
626 reco_ids.push_back(top1_reco_ids);
627 reco_labels.push_back(
"HyPER_Reco_TopLep");
628 reco_indices.push_back(top2_reco_indices);
629 reco_scores.push_back(top2_reco_score);
630 reco_ids.push_back(top2_reco_ids);
631 reco_labels.push_back(
"HyPER_Reco_WHad");
632 reco_indices.push_back(w1_reco_indices);
633 reco_scores.push_back(w1_reco_score);
634 reco_labels.push_back(
"HyPER_Reco_WLep");
635 reco_indices.push_back(w2_reco_indices);
636 reco_scores.push_back(w2_reco_score);
638 reco_labels.push_back(
"HyPER_Reco_TopHad");
639 reco_indices.push_back(top2_reco_indices);
640 reco_scores.push_back(top2_reco_score);
641 reco_ids.push_back(top2_reco_ids);
642 reco_labels.push_back(
"HyPER_Reco_TopLep");
643 reco_indices.push_back(top1_reco_indices);
644 reco_scores.push_back(top1_reco_score);
645 reco_ids.push_back(top1_reco_ids);
646 reco_labels.push_back(
"HyPER_Reco_WHad");
647 reco_indices.push_back(w2_reco_indices);
648 reco_scores.push_back(w2_reco_score);
649 reco_labels.push_back(
"HyPER_Reco_WLep");
650 reco_indices.push_back(w1_reco_indices);
651 reco_scores.push_back(w1_reco_score);
664 std::vector<int64_t>& edge_masks,
666 std::vector<int64_t>& top_reco_indices,
668 float& top_reco_score,
670 std::vector<int64_t>& top_reco_ids,
672 const std::vector<std::vector<int64_t>>&
673 allowed_decay_modes) {
676 using namespace asg::msgUserCode;
678 if (hyperGraph.
nEdges() !=
static_cast<int>(edge_scores.size()))
679 throw std::runtime_error(
680 "Number of defined graph edges does not match with the ones from model "
682 if (allowed_decay_modes.empty())
683 throw std::runtime_error(
"No allowed decay modes available!");
685 for (std::size_t i = 0; i < edge_scores.size(); i++) {
686 if (edge_masks.at(i) == 0) {
693 std::vector<int64_t> top_candidate_indices = {
701 std::size_t beforeLastPosition = hyperGraph.
getNodeFeats(0).size() - 2;
703 2 * hyperGraph.
getNodeFeats(top_candidate_indices.at(0))
704 .at(beforeLastPosition));
706 2 * hyperGraph.
getNodeFeats(top_candidate_indices.at(1))
707 .at(beforeLastPosition));
708 std::vector<int64_t> top_candidate_ids = {
static_cast<int64_t
>(id_1),
709 static_cast<int64_t
>(id_2)};
718 if (edge_scores.at(i).at(0) > top_reco_score) {
719 top_reco_score = edge_scores.at(i).at(0);
720 top_reco_indices = top_candidate_indices;
721 top_reco_ids = top_candidate_ids;
730 const scores& hyperedge_scores,
731 const scores& classification_score,
732 indices& reco_indices, std::vector<float>& reco_scores,
733 std::vector<std::string>& reco_labels,
734 std::vector<std::vector<int64_t>>& reco_ids,
735 float& reco_classification_score) {
736 using namespace asg::msgUserCode;
738 std::vector<int64_t> top1_reco_indices(2, -1);
739 std::vector<int64_t> top2_reco_indices(2, -1);
741 float top1_reco_score = 0;
742 float top2_reco_score = 0;
744 std::vector<int64_t> top1_reco_ids(2, -1);
745 std::vector<int64_t> top2_reco_ids(2, -1);
748 setMsgLevel(MSG::INFO);
749 ANA_MSG_INFO(
"Reconstructing TtbarDiLepton top quarks...");
751 for (
const auto& he_score : hyperedge_scores) {
755 for (
const auto& e_score : edge_scores) {
758 ANA_MSG_INFO(
"Working with this classification score:");
763 reco_classification_score = classification_score.at(0).at(0);
766 std::vector<std::vector<int64_t>> allowed_decays = {
771 std::vector<int64_t> top1_masks(edge_scores.size(), 1);
773 top1_reco_score, top1_reco_ids, allowed_decays);
777 << top1_reco_indices.at(0) <<
" " << top1_reco_indices.at(1));
778 ANA_MSG_INFO(
"Top1 reco IDs: " << top1_reco_ids.at(0) <<
" "
779 << top1_reco_ids.at(1));
783 if (top1_reco_indices == std::vector<int64_t>(2, -1)) {
785 reco_labels.push_back(
"HyPER_Reco_Top1");
786 reco_indices.push_back(top1_reco_indices);
787 reco_scores.push_back(top1_reco_score);
788 reco_ids.push_back(top1_reco_ids);
789 reco_labels.push_back(
"HyPER_Reco_Top2");
790 reco_indices.push_back(top2_reco_indices);
791 reco_scores.push_back(top2_reco_score);
792 reco_ids.push_back(top2_reco_ids);
793 reco_labels.push_back(
"HyPER_Reco_HE");
794 reco_scores.push_back(-1.0);
800 std::vector<int64_t> top2_masks(edge_scores.size(), 1);
801 for (std::size_t i = 0; i < static_cast<std::size_t>(edge_scores.size());
806 top2_masks.at(i) = 0;
810 top2_reco_score, top2_reco_ids, allowed_decays);
814 << top2_reco_indices.at(0) <<
" " << top2_reco_indices.at(1));
815 ANA_MSG_INFO(
"Top2 reco IDs: " << top2_reco_ids.at(0) <<
" "
816 << top2_reco_ids.at(1));
820 bool both_tops_reco =
true;
821 if (top2_reco_indices == std::vector<int64_t>(2, -1))
822 both_tops_reco =
false;
826 float HE_reco_score = -1.0;
827 if (both_tops_reco) {
828 for (std::size_t i = 0;
829 i < static_cast<std::size_t>(hyperGraph.
nHyperEdges()); i++) {
833 std::find(he_indices.begin(), he_indices.end(),
834 top1_reco_indices.at(0)) != he_indices.end() &&
835 std::find(he_indices.begin(), he_indices.end(),
836 top1_reco_indices.at(1)) != he_indices.end();
838 std::find(he_indices.begin(), he_indices.end(),
839 top2_reco_indices.at(0)) != he_indices.end() &&
840 std::find(he_indices.begin(), he_indices.end(),
841 top2_reco_indices.at(1)) != he_indices.end();
842 if (top1_in_he && top2_in_he) {
843 HE_reco_score = hyperedge_scores.at(i).at(0);
851 if (both_tops_reco) {
860 << top1_reco_indices.at(0) <<
" " << top1_reco_indices.at(1));
862 << top2_reco_indices.at(0) <<
" " << top2_reco_indices.at(1));
866 reco_labels.push_back(
"HyPER_Reco_Top1");
867 reco_indices.push_back(top1_reco_indices);
868 reco_scores.push_back(top1_reco_score);
869 reco_ids.push_back(top1_reco_ids);
870 reco_labels.push_back(
"HyPER_Reco_Top2");
871 reco_indices.push_back(top2_reco_indices);
872 reco_scores.push_back(top2_reco_score);
873 reco_ids.push_back(top2_reco_ids);
874 reco_labels.push_back(
"HyPER_Reco_HE");
875 reco_scores.push_back(HE_reco_score);