Skip to content

Commit cb1072e

Browse files
committed
Moved functions to creator for 3 prong
1 parent 3d9adfe commit cb1072e

File tree

5 files changed

+353
-179
lines changed

5 files changed

+353
-179
lines changed

Common/Core/RecoDecay.h

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <tuple> // std::apply
2626
#include <utility> // std::move
2727
#include <vector> // std::vector
28-
#include <iostream> // std::ostream
2928

3029
// ROOT includes
3130
#include <TMCProcess.h> // for VMC Particle Production Process
@@ -567,10 +566,8 @@ struct RecoDecay {
567566
while (!motherFound && arrayIds[-stage].size() > 0 && (depthMax < 0 || -stage < depthMax)) {
568567
// vector of mother indices for the current stage
569568
std::vector<int64_t> arrayIdsStage{};
570-
// std::cout << "[getMother] number of mothers at stage " << stage << ": " << arrayIds[-stage].size() << std::endl;
571569
for (auto iPart : arrayIds[-stage]) { // check all the particles that were the mothers at the previous stage, o2-linter: disable=const-ref-in-for-loop (int elements)
572570
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
573-
// std::cout << "[getMother] particleMother.pdgCode(): " << particleMother.pdgCode() << std::endl;
574571
if (particleMother.has_mothers()) {
575572
for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle
576573
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
@@ -579,9 +576,10 @@ struct RecoDecay {
579576
auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset());
580577
// Check mother's PDG code.
581578
auto pdgParticleIMother = mother.pdgCode(); // PDG code of the mother
582-
for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
583-
std::cout << " ";
584-
// std::cout << "[getMother] Stage: " << stage << " Mother PDG: " << pdgParticleIMother << ", Index: " << iMother << std::endl;
579+
// printf("getMother: ");
580+
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
581+
// printf(" ");
582+
// printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, pdgParticleIMother, iMother);
585583
if (pdgParticleIMother == pdgMother) { // exact PDG match
586584
sgn = 1;
587585
indexMother = iMother;
@@ -642,15 +640,13 @@ struct RecoDecay {
642640
}
643641

644642
bool isFinal = false; // Flag to indicate the end of recursion
645-
// std::cout << "[getDaughters] Stage: " << static_cast<int>(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast<int>(depthMax) << std::endl;
646643
if (depthMax > -1 && stage >= depthMax) { // Maximum depth has been reached (or exceeded).
647644
isFinal = true;
648645
}
649646
// Check whether there are any daughters.
650647
if (!isFinal && !particle.has_daughters()) {
651648
// If the original particle has no daughters, we do nothing and exit.
652649
if (stage == 0) {
653-
// std::cout << "[getDaughters] No daughters of the original particle " << particle.globalIndex() << std::endl;
654650
// Printf("getDaughters: No daughters of %d", index);
655651
return;
656652
}
@@ -662,10 +658,8 @@ struct RecoDecay {
662658
if (!isFinal && stage > 0) {
663659
// If the particle has daughters but is considered to be final, we label it as final.
664660
for (auto pdgI : arrPdgFinal) { // o2-linter: disable=const-ref-in-for-loop (int elements)
665-
// std::cout << "[getDaughters] Checking PDG code: " << pdgI << " with " << pdgParticle << std::endl;
666661
if (pdgParticle == std::abs(pdgI)) { // Accept antiparticles.
667662
isFinal = true;
668-
// std::cout << "[getDaughters] Particle " << particle.globalIndex() << " is final with PDG code " << pdgParticle << std::endl;
669663
break;
670664
}
671665
}
@@ -674,17 +668,14 @@ struct RecoDecay {
674668
if (isFinal) {
675669
// printf("getDaughters: ");
676670
// for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
677-
// std::cout << " ";
678-
// printf(" ");
671+
// printf(" ");
679672
// printf("Stage %d: Adding %d (PDG %d) as final daughter.\n", stage, index, pdgParticle);
680-
// std::cout << "[getDaughters] Adding particle " << particle.globalIndex() << " as final daughter with PDG code " << pdgParticle << std::endl;
681673
list->push_back(particle.globalIndex());
682674
return;
683675
}
684676
// If we are here, we have to follow the daughter tree.
685677
// printf("getDaughters: ");
686-
for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
687-
std::cout << " ";
678+
// for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
688679
// printf(" ");
689680
// printf("Stage %d: %d (PDG %d) -> %d-%d\n", stage, index, pdgParticle, indexDaughterFirst, indexDaughterLast);
690681
// Call itself to get daughters of daughters recursively.
@@ -711,11 +702,11 @@ struct RecoDecay {
711702
/// \param nKaToPi number of kaon prongs decayed to a pion
712703
/// \param nInteractionsWithMaterial number of daughter particles that interacted with material
713704
/// \return index of the mother particle if the mother and daughters are correct, -1 otherwise
714-
template <bool acceptFlavourOscillation = false, bool checkProcess = false, bool acceptIncompleteReco = false, bool acceptTrackDecay = false, bool acceptTrackIntWithMaterial = false, bool forceIncompleteReco = false, std::size_t NDaug, std::size_t NFinPartSpecies, typename T, typename U>
705+
template <bool acceptFlavourOscillation = false, bool checkProcess = false, bool acceptIncompleteReco = false, bool acceptTrackDecay = false, bool acceptTrackIntWithMaterial = false, std::size_t N, typename T, typename U>
715706
static int getMatchedMCRec(const T& particlesMC,
716-
const std::array<U, NDaug>& arrDaughters,
707+
const std::array<U, N>& arrDaughters,
717708
int pdgMother,
718-
std::array<int, NFinPartSpecies> arrPdgDaughters,
709+
std::array<int, N> arrPdgDaughters,
719710
bool acceptAntiParticles = false,
720711
int8_t* sign = nullptr,
721712
int depthMax = 1,
@@ -731,13 +722,13 @@ struct RecoDecay {
731722
int8_t nInteractionsWithMaterialLocal = 0; // number of interactions with material
732723
int indexMother = -1; // index of the mother particle
733724
std::vector<int> arrAllDaughtersIndex; // vector of indices of all daughters of the mother of the first provided daughter
734-
std::array<int, NFinPartSpecies> arrDaughtersIndex; // array of indices of provided daughters
725+
std::array<int, N> arrDaughtersIndex; // array of indices of provided daughters
735726
if (sign) {
736727
*sign = sgn;
737728
}
738729
if constexpr (acceptFlavourOscillation) {
739730
// Loop over decay candidate prongs to spot possible oscillation decay product
740-
for (std::size_t iProng = 0; iProng < NDaug; ++iProng) {
731+
for (std::size_t iProng = 0; iProng < N; ++iProng) {
741732
if (!arrDaughters[iProng].has_mcParticle()) {
742733
return -1;
743734
}
@@ -749,7 +740,7 @@ struct RecoDecay {
749740
}
750741
}
751742
// Loop over decay candidate prongs
752-
for (std::size_t iProng = 0; iProng < NDaug; ++iProng) {
743+
for (std::size_t iProng = 0; iProng < N; ++iProng) {
753744
if (!arrDaughters[iProng].has_mcParticle()) {
754745
return -1;
755746
}
@@ -799,78 +790,67 @@ struct RecoDecay {
799790
indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax);
800791
// Check whether mother was found.
801792
if (indexMother <= -1) {
802-
// std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl;
793+
// Printf("MC Rec: Rejected: bad mother index or PDG");
803794
return -1;
804795
}
805-
std::cout << "MC Rec: Good mother: " << indexMother << std::endl;
796+
// Printf("MC Rec: Good mother: %d", indexMother);
806797
auto particleMother = particlesMC.rawIteratorAt(indexMother - particlesMC.offset());
807798
// Check the daughter indices.
808799
if (!particleMother.has_daughters()) {
809-
// std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl;
800+
// Printf("MC Rec: Rejected: bad daughter index range: %d-%d", particleMother.daughtersIds().front(), particleMother.daughtersIds().back());
810801
return -1;
811802
}
812803
// Check that the number of direct daughters is not larger than the number of expected final daughters.
813804
if constexpr (!acceptIncompleteReco && !checkProcess) {
814-
if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast<int>(NDaug)) {
815-
std::cout << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1
816-
<< " (expected " << NDaug << " final)" << std::endl;
817-
// Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, NDaug);
805+
if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast<int>(N)) {
806+
// Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, N);
818807
return -1;
819808
}
820809
}
821810
// Get the list of actual final daughters.
822811
getDaughters<checkProcess>(particleMother, &arrAllDaughtersIndex, arrPdgDaughters, depthMax);
823-
std::cout << "MC Rec: Mother " << indexMother << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl;
824-
for (auto i : arrAllDaughtersIndex) {
825-
std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , ";
826-
}
827-
// std::cout << " " << std::endl;
812+
// printf("MC Rec: Mother %d has %d final daughters:", indexMother, arrAllDaughtersIndex.size());
813+
// for (auto i : arrAllDaughtersIndex) {
814+
// printf(" %d", i);
815+
// }
816+
// printf("\n");
828817
// Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs).
829-
if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != NDaug) {
830-
std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")" << std::endl;
831-
// LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")";
832-
// Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug);
833-
return -1;
834-
}
835-
if (forceIncompleteReco && arrAllDaughtersIndex.size() == NDaug) {
836-
std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << "vs Number of daughters " << NDaug << ", expected incomplete reco" << std::endl;
837-
// LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")";
838-
// Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug);
818+
if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != N) {
819+
// Printf("MC Rec: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
839820
return -1;
840821
}
841822
}
842823
// Check that the daughter is in the list of final daughters.
843824
// (Check that the daughter is not a stepdaughter, i.e. particle pointing to the mother while not being its daughter.)
844825
bool isDaughterFound = false; // Is the index of this prong among the remaining expected indices of daughters?
845826
for (std::size_t iD = 0; iD < arrAllDaughtersIndex.size(); ++iD) {
846-
// std::cout << "MC Rec: Checking daughter " << iProng << " index: " << arrDaughtersIndex[iProng] << " against expected index: " << arrAllDaughtersIndex[iD] << std::endl;
847827
if (arrDaughtersIndex[iProng] == arrAllDaughtersIndex[iD]) {
848828
arrAllDaughtersIndex[iD] = -1; // Remove this index from the array of expected daughters. (Rejects twin daughters, i.e. particle considered twice as a daughter.)
849829
isDaughterFound = true;
850830
break;
851831
}
852832
}
853833
if (!isDaughterFound) {
854-
// std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl;
834+
// Printf("MC Rec: Rejected: bad daughter index: %d not in the list of final daughters", arrDaughtersIndex[iProng]);
855835
return -1;
856836
}
857837
// Check daughter's PDG code.
858838
auto pdgParticleI = particleI.pdgCode(); // PDG code of the ith daughter
859-
// std::cout << "MC Rec: Daughter " << iProng << " PDG: " << pdgParticleI << std::endl;
839+
// Printf("MC Rec: Daughter %d PDG: %d", iProng, pdgParticleI);
860840
bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes?
861-
for (std::size_t iProngCp = 0; iProngCp < NDaug; ++iProngCp) {
841+
for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) {
862842
if (pdgParticleI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) {
863843
arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones.
864844
isPdgFound = true;
865845
break;
866846
}
867847
}
868848
if (!isPdgFound) {
869-
// std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl;
849+
// Printf("MC Rec: Rejected: bad daughter PDG: %d", pdgParticleI);
870850
return -1;
871851
}
872852
}
873-
std::cout << "MC Rec: Accepted: m: " << indexMother << std::endl;
853+
// Printf("MC Rec: Accepted: m: %d", indexMother);
874854
if (sign) {
875855
*sign = sgn;
876856
}
@@ -939,13 +919,11 @@ struct RecoDecay {
939919
// Check the PDG code of the particle.
940920
auto pdgCandidate = candidate.pdgCode();
941921
// Printf("MC Gen: Candidate PDG: %d", pdgCandidate);
942-
// std::cout << "MC Gen: Candidate PDG: " << pdgCandidate << std::endl;
943922
if (pdgCandidate == pdgParticle) { // exact PDG match
944923
sgn = 1;
945924
} else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match
946925
sgn = -1;
947926
} else {
948-
// std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl;
949927
// Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle));
950928
return false;
951929
}
@@ -967,18 +945,14 @@ struct RecoDecay {
967945
}
968946
// Get the list of actual final daughters.
969947
getDaughters<checkProcess>(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax);
970-
971-
// printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size());
972-
// std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl;
948+
// printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size());
973949
// for (auto i : arrAllDaughtersIndex) {
974-
// std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , ";
950+
// printf(" %d", i);
975951
// }
976-
// std::cout << " " << std::endl;
977952
// printf("\n");
978953
// Check whether the number of final daughters is equal to the required number.
979954
if (arrAllDaughtersIndex.size() != N) {
980-
// std::cout << "MC Gen: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl;
981-
// Printf("MC Gen: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
955+
// Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
982956
return false;
983957
}
984958
if constexpr (acceptFlavourOscillation) {
@@ -995,7 +969,6 @@ struct RecoDecay {
995969
for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements)
996970
auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle
997971
auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter
998-
// std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl;
999972
// Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI);
1000973
bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes?
1001974
for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) {
@@ -1006,7 +979,6 @@ struct RecoDecay {
1006979
}
1007980
}
1008981
if (!isPdgFound) {
1009-
// std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl;
1010982
// Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI);
1011983
return false;
1012984
}
@@ -1015,7 +987,6 @@ struct RecoDecay {
1015987
*listIndexDaughters = arrAllDaughtersIndex;
1016988
}
1017989
}
1018-
std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl;
1019990
// Printf("MC Gen: Accepted: m: %d", candidate.globalIndex());
1020991
if (sign) {
1021992
*sign = sgn;
@@ -1480,4 +1451,4 @@ struct RecoDecayPtEtaPhiBase {
14801451

14811452
using RecoDecayPtEtaPhi = RecoDecayPtEtaPhiBase<>; // alias for instance with default parameters
14821453

1483-
#endif // COMMON_CORE_RECODECAY_H_
1454+
#endif // COMMON_CORE_RECODECAY_H_

0 commit comments

Comments
 (0)