Skip to content

Commit 366ec57

Browse files
authored
[Common,PWGJE] Add getParticleOrigin and modified init problem (#8438)
1 parent 6485462 commit 366ec57

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

Common/Core/RecoDecay.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,119 @@ struct RecoDecay {
10351035
}
10361036
return OriginType::None;
10371037
}
1038+
1039+
/// based on getCharmHardronOrigin in order to extend general particle
1040+
/// Finding the origin (from charm hadronisation or beauty-hadron decay) of paritcle (b, c and others)
1041+
/// \param particlesMC table with MC particles
1042+
/// \param particle MC particle
1043+
/// \param searchUpToQuark if true tag origin based on charm/beauty quark otherwise on the presence of a b-hadron or c-hadron
1044+
/// \param idxBhadMothers optional vector of b-hadron indices (might be more than one in case of searchUpToQuark in case of beauty resonances)
1045+
/// \return an integer corresponding to the origin (0: none(others), 1: charm, 2: beauty) as in OriginType
1046+
template <typename T>
1047+
static int getParticleOrigin(const T& particlesMC,
1048+
const typename T::iterator& particle,
1049+
const bool searchUpToQuark = false,
1050+
std::vector<int>* idxBhadMothers = nullptr)
1051+
{
1052+
int stage = 0; // mother tree level (just for debugging)
1053+
1054+
// vector of vectors with mother indices; each line corresponds to a "stage"
1055+
std::vector<std::vector<int64_t>> arrayIds{};
1056+
std::vector<int64_t> initVec{particle.globalIndex()};
1057+
arrayIds.push_back(initVec); // the first vector contains the index of the original particle
1058+
auto PDGParticle = std::abs(particle.pdgCode());
1059+
bool couldBeCharm = false;
1060+
if (PDGParticle / 100 == 4 || PDGParticle / 1000 == 4) {
1061+
couldBeCharm = true;
1062+
}
1063+
while (arrayIds[-stage].size() > 0) {
1064+
// vector of mother indices for the current stage
1065+
std::vector<int64_t> arrayIdsStage{};
1066+
for (auto& iPart : arrayIds[-stage]) { // check all the particles that were the mothers at the previous stage
1067+
auto particleMother = particlesMC.rawIteratorAt(iPart - particlesMC.offset());
1068+
if (particleMother.has_mothers()) {
1069+
1070+
// we break immediately if searchUpToQuark is false and the first mother is a parton (an hadron should never be the mother of a parton)
1071+
if (!searchUpToQuark) {
1072+
auto mother = particlesMC.rawIteratorAt(particleMother.mothersIds().front() - particlesMC.offset());
1073+
auto PDGParticleIMother = std::abs(mother.pdgCode()); // PDG code of the mother
1074+
if (PDGParticleIMother < 9 || (PDGParticleIMother > 20 && PDGParticleIMother < 38)) {
1075+
auto PDGPaticle = std::abs(particleMother.pdgCode());
1076+
if (
1077+
(PDGParticleIMother / 100 == 5 || // b mesons
1078+
PDGParticleIMother / 1000 == 5) // b baryons
1079+
) {
1080+
return OriginType::NonPrompt; // beauty
1081+
}
1082+
if (
1083+
(PDGParticleIMother / 100 == 4 || // c mesons
1084+
PDGParticleIMother / 1000 == 4) // c baryons
1085+
) {
1086+
return OriginType::Prompt; // charm
1087+
}
1088+
break;
1089+
}
1090+
}
1091+
1092+
for (auto iMother = particleMother.mothersIds().front(); iMother <= particleMother.mothersIds().back(); ++iMother) { // loop over the mother particles of the analysed particle
1093+
if (std::find(arrayIdsStage.begin(), arrayIdsStage.end(), iMother) != arrayIdsStage.end()) { // if a mother is still present in the vector, do not check it again
1094+
continue;
1095+
}
1096+
auto mother = particlesMC.rawIteratorAt(iMother - particlesMC.offset());
1097+
// Check status code
1098+
auto motherStatusCode = std::abs(mother.getGenStatusCode());
1099+
auto PDGParticleIMother = std::abs(mother.pdgCode()); // PDG code of the mother
1100+
// Check mother's PDG code.
1101+
// printf("getMother: ");
1102+
// for (int i = stage; i < 0; i++) // Indent to make the tree look nice.
1103+
// printf(" ");
1104+
// printf("Stage %d: Mother PDG: %d, status: %d, Index: %d\n", stage, PDGParticleIMother, motherStatusCode, iMother);
1105+
1106+
if (searchUpToQuark) {
1107+
if (idxBhadMothers) {
1108+
if (PDGParticleIMother / 100 == 5 || // b mesons
1109+
PDGParticleIMother / 1000 == 5) // b baryons
1110+
{
1111+
idxBhadMothers->push_back(iMother);
1112+
}
1113+
}
1114+
if (PDGParticleIMother == 5) { // b quark
1115+
return OriginType::NonPrompt; // beauty
1116+
}
1117+
if (PDGParticleIMother == 4) { // c quark
1118+
return OriginType::Prompt; // charm
1119+
}
1120+
} else {
1121+
if (
1122+
(PDGParticleIMother / 100 == 5 || // b mesons
1123+
PDGParticleIMother / 1000 == 5) // b baryons
1124+
) {
1125+
if (idxBhadMothers) {
1126+
idxBhadMothers->push_back(iMother);
1127+
}
1128+
return OriginType::NonPrompt; // beauty
1129+
}
1130+
if (
1131+
(PDGParticleIMother / 100 == 4 || // c mesons
1132+
PDGParticleIMother / 1000 == 4) // c baryons
1133+
) {
1134+
couldBeCharm = true;
1135+
}
1136+
}
1137+
// add mother index in the vector for the current stage
1138+
arrayIdsStage.push_back(iMother);
1139+
}
1140+
}
1141+
}
1142+
// add vector of mother indices for the current stage
1143+
arrayIds.push_back(arrayIdsStage);
1144+
stage--;
1145+
}
1146+
if (couldBeCharm) {
1147+
return OriginType::Prompt; // charm
1148+
}
1149+
return OriginType::None;
1150+
}
10381151
};
10391152

10401153
/// Calculations using (pT, η, φ) coordinates, aka (transverse momentum, pseudorapidity, azimuth)

PWGJE/Core/JetTaggingUtilities.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ int jetTrackFromHFShower(T const& jet, U const& /*tracks*/, V const& particles,
137137
bool hasMcParticle = false;
138138
int origin = -1;
139139
for (auto& track : jet.template tracks_as<U>()) {
140+
hftrack = track; // for init if origin is 1 or 2, the track is not hftrack
140141
if (!track.has_mcParticle()) {
141142
continue;
142143
}
143144
hasMcParticle = true;
144145
auto const& particle = track.template mcParticle_as<V>();
145-
origin = RecoDecay::getCharmHadronOrigin(particles, particle, searchUpToQuark);
146+
origin = RecoDecay::getParticleOrigin(particles, particle, searchUpToQuark);
146147
if (origin == 1 || origin == 2) { // 1=charm , 2=beauty
147148
hftrack = track;
148149
if (origin == 1) {
@@ -153,6 +154,7 @@ int jetTrackFromHFShower(T const& jet, U const& /*tracks*/, V const& particles,
153154
}
154155
}
155156
}
157+
156158
if (hasMcParticle) {
157159
return JetTaggingSpecies::lightflavour;
158160
} else {
@@ -173,7 +175,8 @@ int jetParticleFromHFShower(T const& jet, U const& particles, typename U::iterat
173175

174176
int origin = -1;
175177
for (const auto& particle : jet.template tracks_as<U>()) {
176-
origin = RecoDecay::getCharmHadronOrigin(particles, particle, searchUpToQuark);
178+
hfparticle = particle; // for init if origin is 1 or 2, the particle is not hfparticle
179+
origin = RecoDecay::getParticleOrigin(particles, particle, searchUpToQuark);
177180
if (origin == 1 || origin == 2) { // 1=charm , 2=beauty
178181
hfparticle = particle;
179182
if (origin == 1) {

0 commit comments

Comments
 (0)