Skip to content

Commit 96d4af0

Browse files
committed
Moved functions to creator for 3 prong
1 parent 4eec5c4 commit 96d4af0

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
@@ -24,7 +24,6 @@
2424
#include <cstdio>
2525
#include <utility> // std::move
2626
#include <vector> // std::vector
27-
#include <iostream> // std::ostream
2827

2928
// ROOT includes
3029
#include <TMCProcess.h> // for VMC Particle Production Process
@@ -553,10 +552,8 @@ struct RecoDecay {
553552
while (!motherFound && arrayIds[-stage].size() > 0 && (depthMax < 0 || -stage < depthMax)) {
554553
// vector of mother indices for the current stage
555554
std::vector<int64_t> arrayIdsStage{};
556-
// std::cout << "[getMother] number of mothers at stage " << stage << ": " << arrayIds[-stage].size() << std::endl;
557555
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)
558556
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
559-
// std::cout << "[getMother] particleMother.pdgCode(): " << particleMother.pdgCode() << std::endl;
560557
if (particleMother.has_mothers()) {
561558
for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle
562559
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
@@ -565,9 +562,10 @@ struct RecoDecay {
565562
auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset());
566563
// Check mother's PDG code.
567564
auto pdgParticleIMother = mother.pdgCode(); // PDG code of the mother
568-
for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
569-
std::cout << " ";
570-
// std::cout << "[getMother] Stage: " << stage << " Mother PDG: " << pdgParticleIMother << ", Index: " << iMother << std::endl;
565+
// printf("getMother: ");
566+
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
567+
// printf(" ");
568+
// printf("Stage %d: Mother PDG: %d, Index: %d\n", stage, pdgParticleIMother, iMother);
571569
if (pdgParticleIMother == pdgMother) { // exact PDG match
572570
sgn = 1;
573571
indexMother = iMother;
@@ -628,15 +626,13 @@ struct RecoDecay {
628626
}
629627

630628
bool isFinal = false; // Flag to indicate the end of recursion
631-
// std::cout << "[getDaughters] Stage: " << static_cast<int>(stage) << ", Particle PDG: " << particle.pdgCode() << ", Index: " << particle.globalIndex() << ", depthMax: " << static_cast<int>(depthMax) << std::endl;
632629
if (depthMax > -1 && stage >= depthMax) { // Maximum depth has been reached (or exceeded).
633630
isFinal = true;
634631
}
635632
// Check whether there are any daughters.
636633
if (!isFinal && !particle.has_daughters()) {
637634
// If the original particle has no daughters, we do nothing and exit.
638635
if (stage == 0) {
639-
// std::cout << "[getDaughters] No daughters of the original particle " << particle.globalIndex() << std::endl;
640636
// Printf("getDaughters: No daughters of %d", index);
641637
return;
642638
}
@@ -648,10 +644,8 @@ struct RecoDecay {
648644
if (!isFinal && stage > 0) {
649645
// If the particle has daughters but is considered to be final, we label it as final.
650646
for (auto pdgI : arrPdgFinal) { // o2-linter: disable=const-ref-in-for-loop (int elements)
651-
// std::cout << "[getDaughters] Checking PDG code: " << pdgI << " with " << pdgParticle << std::endl;
652647
if (pdgParticle == std::abs(pdgI)) { // Accept antiparticles.
653648
isFinal = true;
654-
// std::cout << "[getDaughters] Particle " << particle.globalIndex() << " is final with PDG code " << pdgParticle << std::endl;
655649
break;
656650
}
657651
}
@@ -660,17 +654,14 @@ struct RecoDecay {
660654
if (isFinal) {
661655
// printf("getDaughters: ");
662656
// for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
663-
// std::cout << " ";
664-
// printf(" ");
657+
// printf(" ");
665658
// printf("Stage %d: Adding %d (PDG %d) as final daughter.\n", stage, index, pdgParticle);
666-
// std::cout << "[getDaughters] Adding particle " << particle.globalIndex() << " as final daughter with PDG code " << pdgParticle << std::endl;
667659
list->push_back(particle.globalIndex());
668660
return;
669661
}
670662
// If we are here, we have to follow the daughter tree.
671663
// printf("getDaughters: ");
672-
for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
673-
std::cout << " ";
664+
// for (int i = 0; i < stage; i++) // Indent to make the tree look nice.
674665
// printf(" ");
675666
// printf("Stage %d: %d (PDG %d) -> %d-%d\n", stage, index, pdgParticle, indexDaughterFirst, indexDaughterLast);
676667
// Call itself to get daughters of daughters recursively.
@@ -697,11 +688,11 @@ struct RecoDecay {
697688
/// \param nKaToPi number of kaon prongs decayed to a pion
698689
/// \param nInteractionsWithMaterial number of daughter particles that interacted with material
699690
/// \return index of the mother particle if the mother and daughters are correct, -1 otherwise
700-
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>
691+
template <bool acceptFlavourOscillation = false, bool checkProcess = false, bool acceptIncompleteReco = false, bool acceptTrackDecay = false, bool acceptTrackIntWithMaterial = false, std::size_t N, typename T, typename U>
701692
static int getMatchedMCRec(const T& particlesMC,
702-
const std::array<U, NDaug>& arrDaughters,
693+
const std::array<U, N>& arrDaughters,
703694
int pdgMother,
704-
std::array<int, NFinPartSpecies> arrPdgDaughters,
695+
std::array<int, N> arrPdgDaughters,
705696
bool acceptAntiParticles = false,
706697
int8_t* sign = nullptr,
707698
int depthMax = 1,
@@ -717,13 +708,13 @@ struct RecoDecay {
717708
int8_t nInteractionsWithMaterialLocal = 0; // number of interactions with material
718709
int indexMother = -1; // index of the mother particle
719710
std::vector<int> arrAllDaughtersIndex; // vector of indices of all daughters of the mother of the first provided daughter
720-
std::array<int, NFinPartSpecies> arrDaughtersIndex; // array of indices of provided daughters
711+
std::array<int, N> arrDaughtersIndex; // array of indices of provided daughters
721712
if (sign) {
722713
*sign = sgn;
723714
}
724715
if constexpr (acceptFlavourOscillation) {
725716
// Loop over decay candidate prongs to spot possible oscillation decay product
726-
for (std::size_t iProng = 0; iProng < NDaug; ++iProng) {
717+
for (std::size_t iProng = 0; iProng < N; ++iProng) {
727718
if (!arrDaughters[iProng].has_mcParticle()) {
728719
return -1;
729720
}
@@ -735,7 +726,7 @@ struct RecoDecay {
735726
}
736727
}
737728
// Loop over decay candidate prongs
738-
for (std::size_t iProng = 0; iProng < NDaug; ++iProng) {
729+
for (std::size_t iProng = 0; iProng < N; ++iProng) {
739730
if (!arrDaughters[iProng].has_mcParticle()) {
740731
return -1;
741732
}
@@ -785,78 +776,67 @@ struct RecoDecay {
785776
indexMother = getMother(particlesMC, particleI, pdgMother, acceptAntiParticles, &sgn, depthMax);
786777
// Check whether mother was found.
787778
if (indexMother <= -1) {
788-
// std::cout << "MC Rec: Rejected: bad mother index or PDG" << std::endl;
779+
// Printf("MC Rec: Rejected: bad mother index or PDG");
789780
return -1;
790781
}
791-
std::cout << "MC Rec: Good mother: " << indexMother << std::endl;
782+
// Printf("MC Rec: Good mother: %d", indexMother);
792783
auto particleMother = particlesMC.rawIteratorAt(indexMother - particlesMC.offset());
793784
// Check the daughter indices.
794785
if (!particleMother.has_daughters()) {
795-
// std::cout << "MC Rec: Rejected: bad daughter index range: " << particleMother.daughtersIds().front() << "-" << particleMother.daughtersIds().back() << std::endl;
786+
// Printf("MC Rec: Rejected: bad daughter index range: %d-%d", particleMother.daughtersIds().front(), particleMother.daughtersIds().back());
796787
return -1;
797788
}
798789
// Check that the number of direct daughters is not larger than the number of expected final daughters.
799790
if constexpr (!acceptIncompleteReco && !checkProcess) {
800-
if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast<int>(NDaug)) {
801-
std::cout << "MC Rec: Rejected: too many direct daughters: " << particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1
802-
<< " (expected " << NDaug << " final)" << std::endl;
803-
// Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, NDaug);
791+
if (particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1 > static_cast<int>(N)) {
792+
// Printf("MC Rec: Rejected: too many direct daughters: %d (expected %ld final)", particleMother.daughtersIds().back() - particleMother.daughtersIds().front() + 1, N);
804793
return -1;
805794
}
806795
}
807796
// Get the list of actual final daughters.
808797
getDaughters<checkProcess>(particleMother, &arrAllDaughtersIndex, arrPdgDaughters, depthMax);
809-
std::cout << "MC Rec: Mother " << indexMother << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl;
810-
for (auto i : arrAllDaughtersIndex) {
811-
std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , ";
812-
}
813-
// std::cout << " " << std::endl;
798+
// printf("MC Rec: Mother %d has %d final daughters:", indexMother, arrAllDaughtersIndex.size());
799+
// for (auto i : arrAllDaughtersIndex) {
800+
// printf(" %d", i);
801+
// }
802+
// printf("\n");
814803
// Check whether the number of actual final daughters is equal to the number of expected final daughters (i.e. the number of provided prongs).
815-
if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != NDaug) {
816-
std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")" << std::endl;
817-
// LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")";
818-
// Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug);
819-
return -1;
820-
}
821-
if (forceIncompleteReco && arrAllDaughtersIndex.size() == NDaug) {
822-
std::cout << "MC Rec: Number of final states " << arrAllDaughtersIndex.size() << "vs Number of daughters " << NDaug << ", expected incomplete reco" << std::endl;
823-
// LOG(info) << "MC Rec: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << NDaug << ")";
824-
// Printf("MC Rec: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), NDaug);
804+
if (!acceptIncompleteReco && arrAllDaughtersIndex.size() != N) {
805+
// Printf("MC Rec: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
825806
return -1;
826807
}
827808
}
828809
// Check that the daughter is in the list of final daughters.
829810
// (Check that the daughter is not a stepdaughter, i.e. particle pointing to the mother while not being its daughter.)
830811
bool isDaughterFound = false; // Is the index of this prong among the remaining expected indices of daughters?
831812
for (std::size_t iD = 0; iD < arrAllDaughtersIndex.size(); ++iD) {
832-
// std::cout << "MC Rec: Checking daughter " << iProng << " index: " << arrDaughtersIndex[iProng] << " against expected index: " << arrAllDaughtersIndex[iD] << std::endl;
833813
if (arrDaughtersIndex[iProng] == arrAllDaughtersIndex[iD]) {
834814
arrAllDaughtersIndex[iD] = -1; // Remove this index from the array of expected daughters. (Rejects twin daughters, i.e. particle considered twice as a daughter.)
835815
isDaughterFound = true;
836816
break;
837817
}
838818
}
839819
if (!isDaughterFound) {
840-
// std::cout << "MC Rec: Rejected: bad daughter index: " << arrDaughtersIndex[iProng] << " not in the list of final daughters" << std::endl;
820+
// Printf("MC Rec: Rejected: bad daughter index: %d not in the list of final daughters", arrDaughtersIndex[iProng]);
841821
return -1;
842822
}
843823
// Check daughter's PDG code.
844824
auto pdgParticleI = particleI.pdgCode(); // PDG code of the ith daughter
845-
// std::cout << "MC Rec: Daughter " << iProng << " PDG: " << pdgParticleI << std::endl;
825+
// Printf("MC Rec: Daughter %d PDG: %d", iProng, pdgParticleI);
846826
bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes?
847-
for (std::size_t iProngCp = 0; iProngCp < NDaug; ++iProngCp) {
827+
for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) {
848828
if (pdgParticleI == coefFlavourOscillation * sgn * arrPdgDaughters[iProngCp]) {
849829
arrPdgDaughters[iProngCp] = 0; // Remove this PDG code from the array of expected ones.
850830
isPdgFound = true;
851831
break;
852832
}
853833
}
854834
if (!isPdgFound) {
855-
// std::cout << "MC Rec: Rejected: bad daughter PDG: " << pdgParticleI << std::endl;
835+
// Printf("MC Rec: Rejected: bad daughter PDG: %d", pdgParticleI);
856836
return -1;
857837
}
858838
}
859-
std::cout << "MC Rec: Accepted: m: " << indexMother << std::endl;
839+
// Printf("MC Rec: Accepted: m: %d", indexMother);
860840
if (sign) {
861841
*sign = sgn;
862842
}
@@ -925,13 +905,11 @@ struct RecoDecay {
925905
// Check the PDG code of the particle.
926906
auto pdgCandidate = candidate.pdgCode();
927907
// Printf("MC Gen: Candidate PDG: %d", pdgCandidate);
928-
// std::cout << "MC Gen: Candidate PDG: " << pdgCandidate << std::endl;
929908
if (pdgCandidate == pdgParticle) { // exact PDG match
930909
sgn = 1;
931910
} else if (acceptAntiParticles && pdgCandidate == -pdgParticle) { // antiparticle PDG match
932911
sgn = -1;
933912
} else {
934-
// std::cout << "MC Gen: Rejected: bad particle PDG: " << (acceptAntiParticles ? "abs " : "") << pdgCandidate << " != " << pdgParticle << std::endl;
935913
// Printf("MC Gen: Rejected: bad particle PDG: %s%d != %d", acceptAntiParticles ? "abs " : "", pdgCandidate, std::abs(pdgParticle));
936914
return false;
937915
}
@@ -953,18 +931,14 @@ struct RecoDecay {
953931
}
954932
// Get the list of actual final daughters.
955933
getDaughters<checkProcess>(candidate, &arrAllDaughtersIndex, arrPdgDaughters, depthMax);
956-
957-
// printf("MC Gen: Mother %ld has %ld final states", candidate.globalIndex(), arrAllDaughtersIndex.size());
958-
// std::cout << "MC Gen: Mother " << candidate.globalIndex() << " has " << arrAllDaughtersIndex.size() << " final states" << std::endl;
934+
// printf("MC Gen: Mother %ld has %ld final daughters:", candidate.globalIndex(), arrAllDaughtersIndex.size());
959935
// for (auto i : arrAllDaughtersIndex) {
960-
// std::cout << " (" << i << " , pdg: " << particlesMC.rawIteratorAt(i - particlesMC.offset()).pdgCode() << ") , ";
936+
// printf(" %d", i);
961937
// }
962-
// std::cout << " " << std::endl;
963938
// printf("\n");
964939
// Check whether the number of final daughters is equal to the required number.
965940
if (arrAllDaughtersIndex.size() != N) {
966-
// std::cout << "MC Gen: Rejected: incorrect number of final states " << arrAllDaughtersIndex.size() << " (expected " << N << ")" << std::endl;
967-
// Printf("MC Gen: Rejected: incorrect number of final states %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
941+
// Printf("MC Gen: Rejected: incorrect number of final daughters: %ld (expected %ld)", arrAllDaughtersIndex.size(), N);
968942
return false;
969943
}
970944
if constexpr (acceptFlavourOscillation) {
@@ -981,7 +955,6 @@ struct RecoDecay {
981955
for (auto indexDaughterI : arrAllDaughtersIndex) { // o2-linter: disable=const-ref-in-for-loop (int elements)
982956
auto candidateDaughterI = particlesMC.rawIteratorAt(indexDaughterI - particlesMC.offset()); // ith daughter particle
983957
auto pdgCandidateDaughterI = candidateDaughterI.pdgCode(); // PDG code of the ith daughter
984-
// std::cout << "MC Gen: Daughter " << indexDaughterI << " PDG: " << pdgCandidateDaughterI << std::endl;
985958
// Printf("MC Gen: Daughter %d PDG: %d", indexDaughterI, pdgCandidateDaughterI);
986959
bool isPdgFound = false; // Is the PDG code of this daughter among the remaining expected PDG codes?
987960
for (std::size_t iProngCp = 0; iProngCp < N; ++iProngCp) {
@@ -992,7 +965,6 @@ struct RecoDecay {
992965
}
993966
}
994967
if (!isPdgFound) {
995-
// std::cout << "MC Gen: Rejected: bad daughter PDG: " << pdgCandidateDaughterI << std::endl;
996968
// Printf("MC Gen: Rejected: bad daughter PDG: %d", pdgCandidateDaughterI);
997969
return false;
998970
}
@@ -1001,7 +973,6 @@ struct RecoDecay {
1001973
*listIndexDaughters = arrAllDaughtersIndex;
1002974
}
1003975
}
1004-
std::cout << "MC Gen: Accepted: m: " << candidate.globalIndex() << std::endl;
1005976
// Printf("MC Gen: Accepted: m: %d", candidate.globalIndex());
1006977
if (sign) {
1007978
*sign = sgn;
@@ -1466,4 +1437,4 @@ struct RecoDecayPtEtaPhiBase {
14661437

14671438
using RecoDecayPtEtaPhi = RecoDecayPtEtaPhiBase<>; // alias for instance with default parameters
14681439

1469-
#endif // COMMON_CORE_RECODECAY_H_
1440+
#endif // COMMON_CORE_RECODECAY_H_

0 commit comments

Comments
 (0)