Skip to content

Commit 372a0a9

Browse files
authored
[PWGJE] gammaJetTree changes to merged definition and event selection (#18135)
1 parent 7df39f5 commit 372a0a9

1 file changed

Lines changed: 40 additions & 34 deletions

File tree

‎PWGJE/Tasks/gammaJetTreeProducer.cxx‎

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ struct GammaJetTreeProducer {
410410
return false;
411411
}
412412
mHistograms.fill(HIST("eventQA"), 1);
413-
if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits)) {
413+
if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, true, true, rctLabel)) {
414414
return false;
415415
}
416416
mHistograms.fill(HIST("eventQA"), 2);
@@ -809,9 +809,10 @@ struct GammaJetTreeProducer {
809809
// return recursive list of all daughter IDs
810810
/// \brief Gets all daughter particle IDs in the decay chain
811811
/// \param particle The particle to start from
812+
/// \param mcParticles The MC particles collection
812813
/// \return Vector of daughter particle IDs
813-
template <typename T>
814-
void getDaughtersInChain(const T& particle, std::vector<int>& daughters, int depth = 0)
814+
template <typename T, typename U>
815+
void getDaughtersInChain(const T& particle, U const& mcParticles, std::vector<int>& daughters, int depth = 0)
815816
{
816817
// Limit recursion depth to avoid infinite loops
817818
if (depth > MaxRecursionDepth) { // 100 generations should be more than enough
@@ -822,10 +823,12 @@ struct GammaJetTreeProducer {
822823
return;
823824
}
824825

825-
const auto& daughterParticles = particle.template daughters_as<aod::JMcParticles>();
826-
for (const auto& daughter : daughterParticles) {
827-
daughters.push_back(daughter.globalIndex());
828-
getDaughtersInChain(daughter, daughters, depth + 1);
826+
// Daughter indices are a contiguous inclusive range. Resolve them on the full table
827+
// so the IDs match cluster MC labels.
828+
const auto daughterIds = particle.daughtersIds();
829+
for (int daughterId = daughterIds[0]; daughterId <= daughterIds[1]; ++daughterId) {
830+
daughters.push_back(daughterId);
831+
getDaughtersInChain(mcParticles.iteratorAt(daughterId), mcParticles, daughters, depth + 1);
829832
}
830833
}
831834
/// \brief Finds the first physical primary particle in the decay chain (upwards)
@@ -885,34 +888,37 @@ struct GammaJetTreeProducer {
885888
if (motherIndex != -1) {
886889
const auto& mother = mcParticles.iteratorAt(motherIndex);
887890

888-
// get daughters of pi0 mother
889-
auto daughtersMother = mother.template daughters_as<aod::JMcParticles>();
890-
// check if there are two daughters that are both photons
891-
if (daughtersMother.size() == 2) { // o2-linter: disable=magic-number (it is just counting number of daughters)
892-
const auto& daughter1 = daughtersMother.iteratorAt(0);
893-
const auto& daughter2 = daughtersMother.iteratorAt(1);
894-
if (daughter1.pdgCode() == PDG_t::kGamma && daughter2.pdgCode() == PDG_t::kGamma) {
895-
// get the full stack of particles that these daughters create
896-
std::vector<int> fullDecayChain1;
897-
std::vector<int> fullDecayChain2;
898-
getDaughtersInChain(daughter1, fullDecayChain1);
899-
getDaughtersInChain(daughter2, fullDecayChain2);
900-
bool photon1Found = false;
901-
bool photon2Found = false;
902-
903-
// check if any of the particles in the fullDecayChain are leading or subleading in the cluster
904-
for (const auto& particleID : fullDecayChain1) {
905-
if (particleID == inducerIDs[0] || particleID == inducerIDs[1]) {
906-
photon1Found = true;
891+
// Daughter indices are the inclusive [first, last] range stored on the mother.
892+
// Resolve them on the full MC table, same index space as the cluster labels.
893+
if (mother.has_daughters()) {
894+
const auto daughterIds = mother.daughtersIds();
895+
const bool hasTwoDaughters = daughterIds[1] == daughterIds[0] + 1; // o2-linter: disable=magic-number (two-body decay)
896+
if (hasTwoDaughters) {
897+
const auto& daughter1 = mcParticles.iteratorAt(daughterIds[0]);
898+
const auto& daughter2 = mcParticles.iteratorAt(daughterIds[1]);
899+
if (daughter1.pdgCode() == PDG_t::kGamma && daughter2.pdgCode() == PDG_t::kGamma) {
900+
// include the decay photons themselves, since unconverted photons are usually the cluster inducers
901+
std::vector<int> fullDecayChain1{daughterIds[0]};
902+
std::vector<int> fullDecayChain2{daughterIds[1]};
903+
getDaughtersInChain(daughter1, mcParticles, fullDecayChain1);
904+
getDaughtersInChain(daughter2, mcParticles, fullDecayChain2);
905+
bool photon1Found = false;
906+
bool photon2Found = false;
907+
908+
// check if any of the particles in the fullDecayChain are leading or subleading in the cluster
909+
for (const auto& particleID : fullDecayChain1) {
910+
if (particleID == inducerIDs[0] || particleID == inducerIDs[1]) {
911+
photon1Found = true;
912+
}
907913
}
908-
}
909-
for (const auto& particleID : fullDecayChain2) {
910-
if (particleID == inducerIDs[0] || particleID == inducerIDs[1]) {
911-
photon2Found = true;
914+
for (const auto& particleID : fullDecayChain2) {
915+
if (particleID == inducerIDs[0] || particleID == inducerIDs[1]) {
916+
photon2Found = true;
917+
}
918+
}
919+
if (photon1Found && photon2Found) {
920+
isMerged = true;
912921
}
913-
}
914-
if (photon1Found && photon2Found) {
915-
isMerged = true;
916922
}
917923
}
918924
}
@@ -1242,7 +1248,7 @@ struct GammaJetTreeProducer {
12421248
for (const auto& mcCluster : mcClusters) {
12431249
mHistograms.fill(HIST("clusterMC_E_All"), mcCluster.energy());
12441250
auto [origin, mcIndex] = getClusterOrigin(mcCluster, mcParticles);
1245-
float leadingEnergyFraction = mcCluster.amplitudeA()[0] / mcCluster.energy();
1251+
float leadingEnergyFraction = mcCluster.amplitudeA()[0]; // amplitudes are already stored as energy fractions
12461252
// Fill MC origin QA histograms
12471253
if (TESTBIT(origin, static_cast<uint16_t>(gjanalysis::ClusterOrigin::kPhoton))) {
12481254
mHistograms.fill(HIST("clusterMC_E_Photon"), mcCluster.energy());

0 commit comments

Comments
 (0)