Skip to content

Commit 5ede46a

Browse files
committed
Improve code clarity
1 parent 4f59117 commit 5ede46a

File tree

5 files changed

+472
-286
lines changed

5 files changed

+472
-286
lines changed

Common/Core/RecoDecay.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cstdio>
2525
#include <utility> // std::move
2626
#include <vector> // std::vector
27+
#include <iostream>
2728

2829
// ROOT includes
2930
#include <TMCProcess.h> // for VMC Particle Production Process
@@ -904,12 +905,20 @@ struct RecoDecay {
904905
}
905906
// Check the PDG code of the particle.
906907
auto pdgCandidate = candidate.pdgCode();
908+
bool debugPrint = false; // Set to true to enable debug printing.
909+
if (std::abs(pdgCandidate) == 413) {
910+
// Printf("MC Gen: Candidate PDG: %d", pdgCandidate);
911+
debugPrint = true; // Enable debug printing for D*.
912+
}
907913
// Printf("MC Gen: Candidate PDG: %d", pdgCandidate);
908914
if (pdgCandidate == pdgParticle) { // exact PDG match
909915
sgn = 1;
910916
} else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match
911917
sgn = -1;
912918
} else {
919+
if (debugPrint) {
920+
std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl;
921+
}
913922
// Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle));
914923
return false;
915924
}
@@ -919,25 +928,42 @@ struct RecoDecay {
919928
std::vector<int> arrAllDaughtersIndex; // vector of indices of all daughters
920929
// Check the daughter indices.
921930
if (!candidate.has_daughters()) {
931+
if (debugPrint) {
932+
std::cout << "MC Gen: Rejected: bad daughter index range: " << candidate.daughtersIds().front() << "-" << candidate.daughtersIds().back() << std::endl;
933+
}
922934
// Printf("MC Gen: Rejected: bad daughter index range: %d-%d", candidate.daughtersIds().front(), candidate.daughtersIds().back());
923935
return false;
924936
}
925937
// Check that the number of direct daughters is not larger than the number of expected final daughters.
926938
if constexpr (!checkProcess) {
927939
if (candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1 > static_cast<int>(N)) {
940+
if (debugPrint) {
941+
std::cout << "MC Gen: Rejected: too many direct daughters: " << candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1
942+
<< " (expected " << N << " final)" << std::endl;
943+
}
928944
// Printf("MC Gen: Rejected: too many direct daughters: %d (expected %ld final)", candidate.daughtersIds().back() - candidate.daughtersIds().front() + 1, N);
929945
return false;
930946
}
931947
}
932948
// Get the list of actual final daughters.
933949
getDaughters<checkProcess>(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax);
950+
if (debugPrint) {
951+
std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final daughters:";
952+
for (auto i : arrAllDaughtersIndex) {
953+
std::cout << " " << i;
954+
}
955+
std::cout << std::endl;
956+
}
934957
// printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size());
935958
// for (auto i : arrAllDaughtersIndex) {
936959
// printf(" %d", i);
937960
// }
938961
// printf("\n");
939962
// Check whether the number of final daughters is equal to the required number.
940963
if (arrAllDaughtersIndex.size() != N) {
964+
if (debugPrint) {
965+
std::cout << "MC Gen: Rejected: incorrect number of final daughters: " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl;
966+
}
941967
// Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
942968
return false;
943969
}
@@ -955,16 +981,25 @@ struct RecoDecay {
955981
for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements)
956982
auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle
957983
auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter
984+
if (debugPrint) {
985+
std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl;
986+
}
958987
// Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI);
959988
bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes?
960989
for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) {
990+
if (debugPrint) {
991+
std::cout << "MC Gen: Checking against expected PDG: " << coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp] << std::endl;
992+
}
961993
if (pdgCandidateDaughterI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) {
962994
arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones.
963995
isPdgFound = true;
964996
break;
965997
}
966998
}
967999
if (!isPdgFound) {
1000+
if (debugPrint) {
1001+
std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl;
1002+
}
9681003
// Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI);
9691004
return false;
9701005
}
@@ -973,6 +1008,9 @@ struct RecoDecay {
9731008
*listIndexDaughters = arrAllDaughtersIndex;
9741009
}
9751010
}
1011+
if (debugPrint) {
1012+
std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl;
1013+
}
9761014
// Printf("MC Gen: Accepted: m: %d", candidate.globalIndex());
9771015
if (sign) {
9781016
*sign = sgn;

0 commit comments

Comments
 (0)