Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "PWGCF/FemtoUniverse/Core/FemtoUniverseCollisionSelection.h"
#include "PWGCF/FemtoUniverse/Core/FemtoUniverseTrackSelection.h"
#include "PWGCF/FemtoUniverse/DataModel/FemtoDerived.h"
#include "PWGHF/Core/DecayChannels.h"
#include "PWGHF/DataModel/CandidateReconstructionTables.h"

#include "Common/CCDB/EventSelectionParams.h"
#include "Common/CCDB/RCTSelectionFlags.h"
Expand Down Expand Up @@ -87,19 +89,16 @@ struct FemtoUniverseProducerMCTruthTask {
// Tables being produced
Produces<aod::FdCollisions> outputCollision;
Produces<aod::FDParticles> outputParts;
// Produces<aod::FDMCLabels> outputPartsMCLabels;
// Produces<aod::FdMCParticles> outputPartsMC;

RCTFlagsChecker rctChecker;

static constexpr int kHadElasticScatt = 20; // kPHElastic - hadronic elastic scattering
static constexpr int kHadInelasticScatt = 23; // kPHInhelastic - hadronic inelastic scattering
static constexpr int HadElasticScatt = 20; // kPHElastic - hadronic elastic scattering
static constexpr int HadInelasticScatt = 23; // kPHInhelastic - hadronic inelastic scattering

// Analysis configs
Configurable<bool> confIsRun3{"confIsRun3", false, "Running on Run3 or pilot"};
Configurable<std::vector<int>> confPDGCodes{"confPDGCodes", std::vector<int>{211, -211, 2212, -2212, 333}, "PDG of particles to be stored"};
Configurable<bool> confAnalysisWithPID{"confAnalysisWithPID", true, "1: take only particles with specified PDG, 0: all particles"};
Configurable<bool> confStoreMotherPDG{"confStoreMotherPDG", false, "Store mother's PDG in tempFitVar."};

/// Event cuts
Configurable<float> confEvtZvtx{"confEvtZvtx", 10.f, "Evt sel: Max. z-Vertex (cm)"};
Expand All @@ -110,6 +109,9 @@ struct FemtoUniverseProducerMCTruthTask {
Configurable<float> confCentFT0Max{"confCentFT0Max", 200.f, "Max CentFT0 value for centrality selection"};
Configurable<bool> confDoSpher{"confDoSpher", false, "Calculate sphericity. If false sphericity will take value of 2."};
Configurable<bool> confIsCheckRCTFlags{"confIsCheckRCTFlags", true, "Use RCTFlags"};
Configurable<bool> confUseIsGoodZvtxFT0vsPV{"confUseIsGoodZvtxFT0vsPV", false, "Check consistency between PVz from central barrel with that from FT0 timing"};
Configurable<bool> confUseIsVertexITSTPC{"confUseIsVertexITSTPC", false, "At least one ITS-TPC track (reject vertices built from ITS-only tracks)"};
Configurable<bool> confUseNoSameBunchPileup{"confUseNoSameBunchPileup", false, "Exclude collisions in bunches with more than 1 reco. PV"};

// Track cuts
struct : o2::framework::ConfigurableGroup {
Expand All @@ -129,8 +131,8 @@ struct FemtoUniverseProducerMCTruthTask {

void init(InitContext&)
{
if (!doprocessTrackMC && !doprocessTrackMcOnlyRecoColl) {
LOGF(fatal, "Neither processTrackMC nor processTrackMcOnlyRecoColl enabled. Please choose one.");
if (!doprocessTrackMc && !doprocessTrackMcWithHf && !doprocessTrackMcOnlyRecoColl && !doprocessTrackMcOnlyRecoCollWithHf) {
LOGF(fatal, "No process enabled. Please choose one.");
}
rctChecker.init("CBT_hadronPID", false, true);
// MC Truth collisions
Expand Down Expand Up @@ -179,18 +181,23 @@ struct FemtoUniverseProducerMCTruthTask {
if (confIsCheckRCTFlags && !rctChecker(col)) {
return false;
}

// check whether the basic event selection criteria are fulfilled
// if the basic selection is NOT fulfilled MC Truth collision is rejected
if (!recoCollCuts.isSelected(col)) {
return false;
}
// additional checks on the reconstructed collisions
if (col.selection_bit(aod::evsel::kNoSameBunchPileup) && col.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV) && col.selection_bit(aod::evsel::kIsVertexITSTPC)) {
recoCollCuts.fillQA(col);
return true;
if (confUseNoSameBunchPileup && !col.selection_bit(aod::evsel::kNoSameBunchPileup)) {
return false;
}
if (confUseIsGoodZvtxFT0vsPV && !col.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV)) {
return false;
}
return false;
if (confUseIsVertexITSTPC && !col.selection_bit(aod::evsel::kIsVertexITSTPC)) {
return false;
}
recoCollCuts.fillQA(col);
return true;
}

template <typename ParticleType>
Expand All @@ -200,7 +207,7 @@ struct FemtoUniverseProducerMCTruthTask {
return 0;
}
if (particle.has_mothers()) {
if (particle.getProcess() == kHadElasticScatt || particle.getProcess() == kHadInelasticScatt) { // treat particles from hadronic scattering (20, 23) as primary
if (particle.getProcess() == HadElasticScatt || particle.getProcess() == HadInelasticScatt) { // treat particles from hadronic scattering (20, 23) as primary
return 0;
}
auto motherparticlesMC = particle.template mothers_as<aod::McParticles>();
Expand Down Expand Up @@ -241,33 +248,30 @@ struct FemtoUniverseProducerMCTruthTask {
continue;
}
}

// check if D0/D0bar mesons pass the rapidity cut
// if pass then saving the orgin of D0/D0bar
// check if tracks (besides D0/D0bar) pass pseudorapidity cut
int8_t origin = -99;
int8_t sign = 0;
if (std::abs(particle.pdgCode()) == Pdg::kD0) {
if (std::abs(particle.y()) > yD0CandGenMax) {
if (yD0CandGenMax >= 0. && std::abs(particle.y()) > yD0CandGenMax) {
continue;
}
/// check if we end-up with the correct final state using MC info
if (!RecoDecay::isMatchedMCGen(tracks, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 2)) {
/// check if we have D0(bar) → π± K∓
continue;
}
origin = RecoDecay::getCharmHadronOrigin(tracks, particle);
} else if (std::abs(particle.eta()) > ConfFilteringTracks.confEtaFilterCut) {
continue;
}

/// check if we end-up with the correct final state using MC info
int8_t sign = 0;
if (std::abs(pdgCode) == Pdg::kD0 && !RecoDecay::isMatchedMCGen(tracks, particle, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign)) {
/// check if we have D0(bar) → π± K∓
continue;
}
// Getting the PDG code of the mother particle
int motherPDG = confStoreMotherPDG ? getMotherPDG(particle) : particle.pdgCode();
int motherPDG = getMotherPDG(particle);
// we cannot use isSelectedMinimal since it takes Ncls
// if (!trackCuts.isSelectedMinimal(track)) {
// continue;
// }

// trackCuts.fillQA<aod::femtouniverseparticle::ParticleType::kTrack,
// aod::femtouniverseparticle::TrackType::kNoChild>(track);
// the bit-wise container of the systematic variations is obtained
Expand All @@ -289,7 +293,73 @@ struct FemtoUniverseProducerMCTruthTask {
}
}

void processTrackMC(aod::McCollision const&,
template <typename TrackType>
void fillParticlesWithHf(TrackType const& tracks)
{
std::vector<int> childIDs = {0, 0}; // these IDs are necessary to keep track of the children

for (const auto& particle : tracks) {
// check the pT range
if (particle.pt() < ConfFilteringTracks.confPtLowFilterCut || particle.pt() > ConfFilteringTracks.confPtHighFilterCut) {
continue;
}
// get the PDG code
int pdgCode = particle.pdgCode();

if (confAnalysisWithPID) {
bool pass = false;
std::vector<int> tmpPDGCodes = confPDGCodes; // necessary due to some features of the Configurable
for (auto const& pdg : tmpPDGCodes) {
if (pdgCode == Pdg::kPhi || // phi meson
std::abs(pdgCode) == Pdg::kD0 || // D0(bar) meson
pdgCode == Pdg::kDPlus || // D+ meson
(pdg == pdgCode && particle.isPhysicalPrimary())) {
pass = true;
break; // Exit early once a match is found
}
}
if (!pass) {
continue;
}
}
// check if D0/D0bar mesons pass the rapidity cut
// if pass then saving the orgin of D0/D0bar
// check if tracks (besides D0/D0bar) pass pseudorapidity cut
int8_t origin = -99;
const bool isD0 = std::abs(particle.pdgCode()) == Pdg::kD0;
const int decayChannel = static_cast<int>(hf_decay::hf_cand_2prong::DecayChannelMain::D0ToPiK);

if (isD0) {
if (particle.flagMcMatchGen() != (particle.pdgCode() == Pdg::kD0 ? decayChannel : -decayChannel)) {
continue;
}
if (yD0CandGenMax >= 0.0 && std::abs(RecoDecay::y(particle.pVector(), MassD0)) > yD0CandGenMax) {
continue;
}
origin = particle.originMcGen();
} else if (std::abs(particle.eta()) > ConfFilteringTracks.confEtaFilterCut) {
continue;
}
// Getting the PDG code of the mother particle
auto motherparticlesMC = particle.template mothers_as<soa::Join<aod::McParticles, aod::HfCand2ProngMcGen>>();
const auto& mcMotherPart = motherparticlesMC.front();

// filling the table with the selected paricles
outputParts(outputCollision.lastIndex(),
particle.pt(),
particle.eta(),
particle.phi(),
aod::femtouniverseparticle::ParticleType::kMCTruthTrack,
0,
pdgCode,
pdgCode,
childIDs,
origin,
mcMotherPart.pdgCode());
}
}

void processTrackMc(aod::McCollision const&,
soa::SmallGroups<soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::McCollisionLabels>> const& collisions,
aod::McParticles const& mcParticles,
aod::BCsWithTimestamps const&)
Expand All @@ -299,9 +369,22 @@ struct FemtoUniverseProducerMCTruthTask {
fillCollisions(collisions, mcParticles);
fillParticles(mcParticles);
}
PROCESS_SWITCH(FemtoUniverseProducerMCTruthTask, processTrackMC, "Provide MC data for track analysis", true);
PROCESS_SWITCH(FemtoUniverseProducerMCTruthTask, processTrackMc, "Provide MC data for track analysis", false);

void processTrackMcWithHf(aod::McCollision const&,
soa::SmallGroups<soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::McCollisionLabels>> const& collisions,
soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& mcParticles,
aod::BCsWithTimestamps const&)
{
// magnetic field for run not needed for mc truth
// fill the tables
fillCollisions(collisions, mcParticles);
fillParticlesWithHf(mcParticles);
}
PROCESS_SWITCH(FemtoUniverseProducerMCTruthTask, processTrackMcWithHf, "Provide MC data for track-HF analysis", true);

Preslice<aod::McParticles> perMCCollision = aod::mcparticle::mcCollisionId;
Preslice<soa::Join<aod::McParticles, aod::HfCand2ProngMcGen>> perMcCollHf = aod::mcparticle::mcCollisionId;
PresliceUnsorted<soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::McCollisionLabels>> recoCollsPerMCColl = aod::mcparticle::mcCollisionId;

void processTrackMcOnlyRecoColl(aod::McCollisions const& mccols,
Expand Down Expand Up @@ -333,6 +416,36 @@ struct FemtoUniverseProducerMCTruthTask {
}
}
PROCESS_SWITCH(FemtoUniverseProducerMCTruthTask, processTrackMcOnlyRecoColl, "Provide MC data for track analysis from truth coll which were recontructed ", false);

void processTrackMcOnlyRecoCollWithHf(aod::McCollisions const& mccols,
soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::McCollisionLabels> const& collisions,
soa::Join<aod::McParticles, aod::HfCand2ProngMcGen> const& mcParticles,
aod::BCsWithTimestamps const&)
{
// check on the reco collisions
static std::set<int> mcColIds;
mcColIds.clear();

for (const auto& col : collisions) {
const auto colcheck = checkMcRecoCollisions(col);
if (colcheck) {
mcColIds.insert(col.mcCollisionId());
}
}
// filling truth collisions and particles
for (const auto& mccol : mccols) {
if (!mcColIds.contains(mccol.globalIndex())) {
continue;
}
auto groupedMCParticles = mcParticles.sliceBy(perMcCollHf, mccol.globalIndex());
auto groupedCollisions = collisions.sliceBy(recoCollsPerMCColl, mccol.globalIndex());
// magnetic field for run not needed for mc truth
// fill the tables
fillCollisions(groupedCollisions, groupedMCParticles);
fillParticlesWithHf(groupedMCParticles);
}
}
PROCESS_SWITCH(FemtoUniverseProducerMCTruthTask, processTrackMcOnlyRecoCollWithHf, "Provide MC data for track-HF particle analysis from only reconstucted MC Truth collisions", false);
};

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
Expand Down
Loading
Loading