Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 107 additions & 127 deletions PWGLF/TableProducer/Resonances/resonanceModuleInitializer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "PWGLF/Utils/collisionCuts.h"

#include "Common/CCDB/RCTSelectionFlags.h"
#include "Common/Core/RecoDecay.h"
#include "Common/DataModel/EventSelection.h"
#include "Common/DataModel/Multiplicity.h"
#include "Common/DataModel/PIDResponseTOF.h"
Expand All @@ -45,6 +46,7 @@

#include <TH1.h>
#include <THnSparse.h>
#include <TMCProcess.h>
#include <TPDGCode.h>

#include <algorithm>
Expand All @@ -65,6 +67,82 @@ using namespace o2::constants::physics;
using namespace o2::constants::math;
using namespace o2::aod::rctsel;

namespace
{
constexpr int PdgProton = PDG_t::kProton;
constexpr int PdgLambda0 = PDG_t::kLambda0;
constexpr int PdgXiMinus = PDG_t::kXiMinus;
constexpr int PdgXi0 = o2::constants::physics::Pdg::kXi0;
constexpr int PdgOmegaMinus = PDG_t::kOmegaMinus;

bool isSignalLossReference(int pdg)
{
const auto absPdg = std::abs(pdg);
return absPdg == PdgProton || absPdg == PdgLambda0 || absPdg == PdgXiMinus || absPdg == PdgXi0 || absPdg == PdgOmegaMinus;
}

struct ParentKinematics {
float rapidity;
float energy;
};

ParentKinematics getParentKinematics(aod::McParticle const& parent)
{
constexpr int MinDirectDaughters = 2;
const ParentKinematics generated{parent.y(), parent.e()};
if (isSignalLossReference(parent.pdgCode()) || !parent.has_daughters()) {
return generated;
}
const auto daughterIds = parent.daughtersIds();
if (daughterIds.front() >= daughterIds.back()) {
return generated;
}
std::array<double, 3> decayMomentum{};
double decayEnergy = 0.;
int nDirectDaughters = 0;
for (const auto& daughter : parent.daughters_as<aod::McParticles>()) {
// The stored interval can also contain descendants and material secondaries.
const auto motherIds = daughter.mothersIds();
if (daughter.globalIndex() == parent.globalIndex() ||
std::find(motherIds.begin(), motherIds.end(), parent.globalIndex()) == motherIds.end() ||
(!daughter.producedByGenerator() && daughter.getProcess() != TMCProcess::kPDecay)) {
continue;
}
decayMomentum[0] += daughter.px();
decayMomentum[1] += daughter.py();
decayMomentum[2] += daughter.pz();
decayEnergy += daughter.e();
++nDirectDaughters;
}
const double massSquared = RecoDecay::m2(decayMomentum, decayEnergy);
if (nDirectDaughters >= MinDirectDaughters && std::isfinite(decayEnergy) && std::isfinite(massSquared) &&
massSquared >= 0. && decayEnergy > std::abs(decayMomentum[2])) {
const double y = RecoDecay::y(decayMomentum, std::sqrt(massSquared));
if (std::isfinite(y)) {
return {static_cast<float>(y), static_cast<float>(decayEnergy)};
}
}
return generated;
}

struct TruthMotherInfo {
int id = -1;
int pdg = -1;
float pt = -1.f;
float rapidity = -1.f;
};

// The label tables store only the first mother, even for multi-parent records.
TruthMotherInfo firstMotherInfo(aod::McParticle const& particle)
{
if (!particle.has_mothers()) {
return {};
}
const auto mother = particle.mothers_first_as<aod::McParticles>();
return {static_cast<int>(mother.globalIndex()), mother.pdgCode(), mother.pt(), getParentKinematics(mother).rapidity};
}
} // namespace

/**
* @brief Initializer for the event pool for resonance study
*
Expand Down Expand Up @@ -113,11 +191,6 @@ struct ResonanceModuleInitializer {
static constexpr int Xi1820MinusCode = o2::constants::physics::Pdg::kXi1820Minus;
static constexpr int Xi1820ZeroCode = o2::constants::physics::Pdg::kXi1820Zero;
static constexpr int Omega2012MinusCode = o2::constants::physics::Pdg::kOmega2012Minus;
static constexpr int PdgProton = PDG_t::kProton;
static constexpr int PdgLambda0 = PDG_t::kLambda0;
static constexpr int PdgXiMinus = PDG_t::kXiMinus;
static constexpr int PdgXi0 = o2::constants::physics::Pdg::kXi0;
static constexpr int PdgOmegaMinus = PDG_t::kOmegaMinus;

int mRunNumber = 0; ///< Run number for the current data
int multEstimator = CentralityFT0M; ///< Centrality estimator type
Expand Down Expand Up @@ -666,26 +739,27 @@ struct ResonanceModuleInitializer {
*
* The source MC-particle global index is persisted as a scalar in
* ResoMCParents_001; it is not a relation requiring McParticles at merge time.
* Resonance rapidity and energy are taken from the sum of the direct truth
* decay daughters when available; the other parent columns are unchanged.
*/
template <typename SelectedMCParticlesType, typename MCParticlesType>
void fillMCParents(int64_t reducedCollisionId,
SelectedMCParticlesType const& selectedParents,
MCParticlesType const& mcParticles)
{
for (auto const& mcPart : selectedParents) {
if (!GenCuts.cfgDoSignalLoss) {
const int absPdg = std::abs(mcPart.pdgCode());
if (absPdg == PdgProton || absPdg == PdgLambda0 || absPdg == PdgXiMinus || absPdg == PdgXi0 || absPdg == PdgOmegaMinus) {
continue;
}
if (!GenCuts.cfgDoSignalLoss && isSignalLossReference(mcPart.pdgCode())) {
continue;
}

std::array<int, 2> daughterPDGs{-1, -1};
if (mcPart.has_daughters()) {
const auto daughter1 = mcParticles.rawIteratorAt(mcPart.daughtersIds()[0] - mcParticles.offset());
const auto daughter2 = mcParticles.rawIteratorAt(mcPart.daughtersIds()[1] - mcParticles.offset());
daughterPDGs = {daughter1.pdgCode(), daughter2.pdgCode()};
const auto daughterIds = mcPart.daughtersIds();
const auto first = daughterIds.front() - mcParticles.offset();
const auto last = daughterIds.back() - mcParticles.offset();
daughterPDGs = {mcParticles.rawIteratorAt(first).pdgCode(), mcParticles.rawIteratorAt(last).pdgCode()};
}
const auto kinematics = getParentKinematics(mcParticles.rawIteratorAt(mcPart.globalIndex() - mcParticles.offset()));
reso2mcparents(reducedCollisionId,
mcPart.globalIndex(),
mcPart.pdgCode(),
Expand All @@ -697,8 +771,8 @@ struct ResonanceModuleInitializer {
mcPart.px(),
mcPart.py(),
mcPart.pz(),
mcPart.y(),
mcPart.e(),
kinematics.rapidity,
kinematics.energy,
mcPart.statusCode());
}
}
Expand Down Expand Up @@ -2535,39 +2609,6 @@ struct ResonanceDaughterInitializer {
template <typename V0Type>
void fillMCV0(V0Type const& v0)
{
// ------ Temporal lambda function to prevent error in build
auto getMothersIndeces = [&](auto const& theMcParticle) {
std::vector<int> lMothersIndeces{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother index lMother: %d", lMother.globalIndex());
lMothersIndeces.push_back(lMother.globalIndex());
}
return lMothersIndeces;
};
auto getMothersPDGCodes = [&](auto const& theMcParticle) {
std::vector<int> lMothersPDGs{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother pdgcode lMother: %d", lMother.pdgCode());
lMothersPDGs.push_back(lMother.pdgCode());
}
return lMothersPDGs;
};
auto getMothersPt = [&](auto const& theMcParticle) {
std::vector<float> lMothersPts{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother pt lMother: %f", lMother.pt());
lMothersPts.push_back(lMother.pt());
}
return lMothersPts;
};
auto getMothersRap = [&](auto const& theMcParticle) {
std::vector<float> lMothersRaps{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother rap lMother: %f", lMother.y());
lMothersRaps.push_back(lMother.y());
}
return lMothersRaps;
};
auto getDaughtersIndeces = [&](auto const& theMcParticle) {
std::vector<int> lDaughtersIndeces{};
for (auto const& lDaughter : theMcParticle.template daughters_as<aod::McParticles>()) {
Expand All @@ -2584,25 +2625,11 @@ struct ResonanceDaughterInitializer {
}
return lDaughtersPDGs;
};
// ------
std::vector<int> mothers = {-1, -1};
std::vector<int> motherPDGs = {-1, -1};
std::vector<float> mothersPts = {-1.0f, -1.0f};
std::vector<float> mothersRaps = {-1.0f, -1.0f};
std::vector<int> daughters = {-1, -1};
std::vector<int> daughterPDGs = {-1, -1};
if (v0.has_mcParticle()) {
auto v0mc = v0.mcParticle();
if (v0mc.has_mothers()) {
mothers = getMothersIndeces(v0mc);
motherPDGs = getMothersPDGCodes(v0mc);
mothersPts = getMothersPt(v0mc);
mothersRaps = getMothersRap(v0mc);
}
mothers.resize(StoredMCRelationCount, -1);
motherPDGs.resize(StoredMCRelationCount, -1);
mothersPts.resize(StoredMCRelationCount, -1.0f);
mothersRaps.resize(StoredMCRelationCount, -1.0f);
const auto mother = firstMotherInfo(v0mc);
if (v0mc.has_daughters()) {
daughters = getDaughtersIndeces(v0mc);
daughterPDGs = getDaughtersPDGCodes(v0mc);
Expand All @@ -2613,10 +2640,10 @@ struct ResonanceDaughterInitializer {
daughters.resize(StoredMCRelationCount, -1);
daughterPDGs.resize(StoredMCRelationCount, -1);
reso2mcv0s(v0mc.pdgCode(),
mothers[0],
motherPDGs[0],
mothersPts[0],
mothersRaps[0],
mother.id,
mother.pdg,
mother.pt,
mother.rapidity,
daughters[0],
daughters[1],
daughterPDGs[0],
Expand All @@ -2625,10 +2652,10 @@ struct ResonanceDaughterInitializer {
v0mc.producedByGenerator());
} else {
reso2mcv0s(0,
mothers[0],
motherPDGs[0],
mothersPts[0],
mothersRaps[0],
-1,
-1,
-1.f,
-1.f,
daughters[0],
daughters[1],
daughterPDGs[0],
Expand Down Expand Up @@ -2719,39 +2746,6 @@ struct ResonanceDaughterInitializer {
template <typename CascType>
void fillMCCascade(CascType const& casc)
{
// ------ Temporal lambda function to prevent error in build
auto getMothersIndeces = [&](auto const& theMcParticle) {
std::vector<int> lMothersIndeces{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother index lMother: %d", lMother.globalIndex());
lMothersIndeces.push_back(lMother.globalIndex());
}
return lMothersIndeces;
};
auto getMothersPDGCodes = [&](auto const& theMcParticle) {
std::vector<int> lMothersPDGs{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother pdgcode lMother: %d", lMother.pdgCode());
lMothersPDGs.push_back(lMother.pdgCode());
}
return lMothersPDGs;
};
auto getMothersPt = [&](auto const& theMcParticle) {
std::vector<float> lMothersPts{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother pt lMother: %f", lMother.pt());
lMothersPts.push_back(lMother.pt());
}
return lMothersPts;
};
auto getMothersRap = [&](auto const& theMcParticle) {
std::vector<float> lMothersRaps{};
for (auto const& lMother : theMcParticle.template mothers_as<aod::McParticles>()) {
LOGF(debug, " mother rap lMother: %f", lMother.y());
lMothersRaps.push_back(lMother.y());
}
return lMothersRaps;
};
auto getDaughtersIndeces = [&](auto const& theMcParticle) {
std::vector<int> lDaughtersIndeces{};
for (auto const& lDaughter : theMcParticle.template daughters_as<aod::McParticles>()) {
Expand All @@ -2768,25 +2762,11 @@ struct ResonanceDaughterInitializer {
}
return lDaughtersPDGs;
};
// ------
std::vector<int> mothers = {-1, -1};
std::vector<int> motherPDGs = {-1, -1};
std::vector<int> daughters = {-1, -1};
std::vector<int> daughterPDGs = {-1, -1};
std::vector<float> mothersPts = {-1.0f, -1.0f};
std::vector<float> mothersRaps = {-1.0f, -1.0f};
if (casc.has_mcParticle()) {
auto cascmc = casc.mcParticle();
if (cascmc.has_mothers()) {
mothers = getMothersIndeces(cascmc);
motherPDGs = getMothersPDGCodes(cascmc);
mothersPts = getMothersPt(cascmc);
mothersRaps = getMothersRap(cascmc);
}
mothers.resize(StoredMCRelationCount, -1);
motherPDGs.resize(StoredMCRelationCount, -1);
mothersPts.resize(StoredMCRelationCount, -1.0f);
mothersRaps.resize(StoredMCRelationCount, -1.0f);
const auto mother = firstMotherInfo(cascmc);
if (cascmc.has_daughters()) {
daughters = getDaughtersIndeces(cascmc);
daughterPDGs = getDaughtersPDGCodes(cascmc);
Expand All @@ -2797,10 +2777,10 @@ struct ResonanceDaughterInitializer {
daughters.resize(StoredMCRelationCount, -1);
daughterPDGs.resize(StoredMCRelationCount, -1);
reso2mccascades(cascmc.pdgCode(),
mothers[0],
motherPDGs[0],
mothersPts[0],
mothersRaps[0],
mother.id,
mother.pdg,
mother.pt,
mother.rapidity,
daughters[0],
daughters[1],
daughterPDGs[0],
Expand All @@ -2809,10 +2789,10 @@ struct ResonanceDaughterInitializer {
cascmc.producedByGenerator());
} else {
reso2mccascades(0,
mothers[0],
motherPDGs[0],
mothersPts[0],
mothersRaps[0],
-1,
-1,
-1.f,
-1.f,
daughters[0],
daughters[1],
daughterPDGs[0],
Expand Down
Loading