Skip to content

Commit ab3c8c5

Browse files
committed
Feat: finish mc processing for kinks
1 parent ef724c3 commit ab3c8c5

File tree

8 files changed

+654
-85
lines changed

8 files changed

+654
-85
lines changed

PWGCF/Femto/Core/kinkBuilder.h

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "Common/Core/RecoDecay.h"
2828

2929
#include "CommonConstants/MathConstants.h"
30-
#include "CommonConstants/PhysicsConstants.h"
3130
#include "Framework/AnalysisHelpers.h"
3231
#include "Framework/Configurable.h"
3332

@@ -435,7 +434,6 @@ class KinkBuilder
435434
int64_t daughterIndex = 0;
436435

437436
for (const auto& kink : kinks) {
438-
439437
// compute mother kinematics before checking filters
440438
mKinkSelection.computeKinkMotherKinematics(kink);
441439
if (!mKinkSelection.checkFilters(kink)) {
@@ -444,15 +442,15 @@ class KinkBuilder
444442
// compute qa variables before applying selections
445443
mKinkSelection.computeQaVariables(kink, tracks);
446444
mKinkSelection.applySelections(kink, tracks);
447-
448445
if (!mKinkSelection.passesAllRequiredSelections()) {
449446
continue;
450447
}
451448

452449
collisionBuilder.template fillCollision<system>(collisionProducts, col);
453450
// cleaner, but without ITS pid: auto daughter = kink.template trackDaug_as<T7>();
454451
int64_t idx = kink.trackDaugId() - tracksWithItsPid.offset();
455-
if (idx < 0 || idx > static_cast<int64_t>(tracksWithItsPid.size())) {
452+
// check for valid index
453+
if (idx < 0 || idx >= static_cast<int64_t>(tracksWithItsPid.size())) {
456454
return;
457455
}
458456
auto daughter = tracksWithItsPid.iteratorAt(idx);
@@ -466,6 +464,49 @@ class KinkBuilder
466464
}
467465
}
468466

467+
template <modes::System system, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
468+
void fillMcKinks(T1 const& col, T2& collisionBuilder, T3& collisionProducts, T4 const& mcCols, T5& trackProducts, T6& kinkProducts, T7 const& kinks, T8 const& tracks, T9 const& tracksWithItsPid, T10& trackBuilder, T11 const& mcParticles, T12& mcBuilder, T13& mcProducts)
469+
{
470+
471+
if (!mFillAnyTable) {
472+
return;
473+
}
474+
int64_t daughterIndex = 0;
475+
for (const auto& kink : kinks) {
476+
// compute mother kinematics before checking filters
477+
mKinkSelection.computeKinkMotherKinematics(kink);
478+
if (!mKinkSelection.checkFilters(kink)) {
479+
continue;
480+
}
481+
// compute qa variables before applying selections
482+
mKinkSelection.computeQaVariables(kink, tracks);
483+
mKinkSelection.applySelections(kink, tracks);
484+
if (!mKinkSelection.passesAllRequiredSelections()) {
485+
continue;
486+
}
487+
488+
collisionBuilder.template fillMcCollision<system>(collisionProducts, col, mcCols, mcProducts, mcBuilder);
489+
490+
int64_t idx = kink.trackDaugId() - tracks.offset();
491+
// check for valid index
492+
if (idx < 0 || idx >= static_cast<int64_t>(tracks.size())) {
493+
return;
494+
}
495+
auto daughter = tracks.iteratorAt(idx);
496+
auto daughterWithItsPid = tracksWithItsPid.iteratorAt(idx);
497+
daughterIndex = trackBuilder.template getDaughterIndex<system, modes::Track::kKinkDaughter>(col, collisionProducts, mcCols, daughter, daughterWithItsPid, trackProducts, mcParticles, mcBuilder, mcProducts);
498+
499+
if constexpr (modes::isEqual(kinkType, modes::Kink::kSigma)) {
500+
fillSigma(collisionProducts, kinkProducts, kink, daughterIndex);
501+
mcBuilder.template fillMcSigmaWithLabel<system>(col, mcCols, kink, daughter, mcParticles, mcProducts);
502+
}
503+
if constexpr (modes::isEqual(kinkType, modes::Kink::kSigmaPlus)) {
504+
fillSigmaPlus(collisionProducts, kinkProducts, kink, daughterIndex);
505+
mcBuilder.template fillMcSigmaPlusWithLabel<system>(col, mcCols, kink, daughter, mcParticles, mcProducts);
506+
}
507+
}
508+
}
509+
469510
template <typename T1, typename T2, typename T3>
470511
void fillSigma(T1& collisionProducts, T2& kinkProducts, T3 const& kink, int64_t daughterIndex)
471512
{

PWGCF/Femto/Core/kinkHistManager.h

Lines changed: 284 additions & 31 deletions
Large diffs are not rendered by default.

PWGCF/Femto/Core/mcBuilder.h

Lines changed: 217 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ struct McBuilderProducts : o2::framework::ProducesGroup {
5252
o2::framework::Produces<o2::aod::FTrackLabels> producedTrackLabels;
5353
o2::framework::Produces<o2::aod::FLambdaLabels> producedLambdaLabels;
5454
o2::framework::Produces<o2::aod::FK0shortLabels> producedK0shortLabels;
55+
o2::framework::Produces<o2::aod::FSigmaLabels> producedSigmaLabels;
56+
o2::framework::Produces<o2::aod::FSigmaPlusLabels> producedSigmaPlusLabels;
5557
};
5658

5759
struct ConfMcTables : o2::framework::ConfigurableGroup {
@@ -65,6 +67,8 @@ struct ConfMcTables : o2::framework::ConfigurableGroup {
6567
o2::framework::Configurable<int> producedTrackLabels{"producedTrackLabels", -1, "Produce track labels (-1: auto; 0 off; 1 on)"};
6668
o2::framework::Configurable<int> producedLambdaLabels{"producedLambdaLabels", -1, "Produce lambda labels (-1: auto; 0 off; 1 on)"};
6769
o2::framework::Configurable<int> producedK0shortLabels{"producedK0shortLabels", -1, "Produce k0short labels (-1: auto; 0 off; 1 on)"};
70+
o2::framework::Configurable<int> producedSigmaLabels{"producedSigmaLabels", -1, "Produce k0short labels (-1: auto; 0 off; 1 on)"};
71+
o2::framework::Configurable<int> producedSigmaPlusLabels{"producedSigmaPlusLabels", -1, "Produce k0short labels (-1: auto; 0 off; 1 on)"};
6872
};
6973

7074
class McBuilder
@@ -85,8 +89,10 @@ class McBuilder
8589

8690
mProduceCollisionLabels = utils::enableTable("FColLabels", table.producedCollisionLabels.value, initContext);
8791
mProduceTrackLabels = utils::enableTable("FTrackLabels", table.producedTrackLabels.value, initContext);
88-
mProduceLambdaLabels = utils::enableTable("FLambdaLabels", table.producedTrackLabels.value, initContext);
89-
mProduceK0shortLabels = utils::enableTable("FK0shortLabels", table.producedTrackLabels.value, initContext);
92+
mProduceLambdaLabels = utils::enableTable("FLambdaLabels", table.producedLambdaLabels.value, initContext);
93+
mProduceK0shortLabels = utils::enableTable("FK0shortLabels", table.producedK0shortLabels.value, initContext);
94+
mProduceSigmaLabels = utils::enableTable("FSigmaLabels", table.producedSigmaLabels.value, initContext);
95+
mProduceSigmaPlusLabels = utils::enableTable("FSigmaPlusLabels", table.producedSigmaPlusLabels.value, initContext);
9096

9197
if (mProduceMcCollisions || mProduceMcParticles || mProduceMcMothers || mProduceMcPartonicMothers || mProduceCollisionLabels || mProduceTrackLabels || mProduceLambdaLabels || mProduceK0shortLabels) {
9298
mFillAnyTable = true;
@@ -422,7 +428,195 @@ class McBuilder
422428
mK0shortToMcPartonicMap[k0shortIndex] = partonicRow;
423429
}
424430
}
425-
mcProducts.producedTrackLabels(mcParticleRow, mothersRow, partonicRow);
431+
mcProducts.producedK0shortLabels(mcParticleRow, mothersRow, partonicRow);
432+
}
433+
434+
template <modes::System system, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
435+
void fillMcSigmaWithLabel(T1 const& col, T2 const& mcCols, T3 const& sigma, T4 const& sigmaDaughter, T5 const& mcParticles, T6& mcProducts)
436+
{
437+
if (!mProduceSigmaLabels) {
438+
return;
439+
}
440+
441+
if (!sigmaDaughter.has_mcParticle()) {
442+
mcProducts.producedSigmaLabels(-1, -1, -1);
443+
return;
444+
}
445+
446+
auto mcKinkDaughter = sigmaDaughter.template mcParticle_as<T5>();
447+
auto mcKinkDaughterMothers = mcKinkDaughter.template mothers_as<T5>();
448+
449+
if (!mcKinkDaughter.has_mothers() && !mcKinkDaughterMothers.empty()) {
450+
mcProducts.producedSigmaLabels(-1, -1, -1);
451+
return;
452+
}
453+
454+
// we get the mc kink partilce via the mother of the kink daughter
455+
auto mcParticle = mcKinkDaughterMothers.front();
456+
auto mcCol = mcParticle.template mcCollision_as<T2>();
457+
458+
int64_t particleIndex = mcParticle.globalIndex();
459+
int64_t sigmaIndex = sigma.globalIndex();
460+
461+
int64_t mcParticleRow = -1;
462+
463+
// MC PARTICLE
464+
auto itP = mSigmaToMcParticleMap.find(particleIndex);
465+
if (itP != mSigmaToMcParticleMap.end()) {
466+
mcParticleRow = itP->second;
467+
} else {
468+
auto origin = this->getOrigin(col, mcCols, mcParticle);
469+
int64_t mcColId = this->getMcColId<system>(mcCol, mcProducts);
470+
471+
mcProducts.producedMcParticles(
472+
mcColId,
473+
static_cast<aod::femtodatatypes::McOriginType>(origin),
474+
mcParticle.pdgCode(),
475+
mcParticle.pt() * utils::signum(mcParticle.pdgCode()),
476+
mcParticle.eta(),
477+
mcParticle.phi());
478+
479+
mcParticleRow = mcProducts.producedMcParticles.lastIndex();
480+
mSigmaToMcParticleMap[particleIndex] = mcParticleRow;
481+
}
482+
483+
// mothers (fill only if exists)
484+
int64_t mothersRow = -1;
485+
auto itM = mSigmaToMcMotherMap.find(sigmaIndex);
486+
487+
if (itM != mSigmaToMcMotherMap.end()) {
488+
mothersRow = itM->second;
489+
} else {
490+
491+
auto mothers = mcParticle.template mothers_as<T5>();
492+
bool motherExists = mcParticle.has_mothers() && !mothers.empty();
493+
494+
if (motherExists) {
495+
int motherPdg = mothers.front().pdgCode(); // PDG code is ALWAYS valid if the mother exists
496+
497+
mcProducts.producedMothers(motherPdg);
498+
mothersRow = mcProducts.producedMothers.lastIndex();
499+
mSigmaToMcMotherMap[sigmaIndex] = mothersRow;
500+
}
501+
}
502+
503+
// partonic mother (fill only if exists)
504+
int64_t partonicRow = -1;
505+
auto itPM = mSigmaToMcPartonicMap.find(sigmaIndex);
506+
507+
if (itPM != mSigmaToMcPartonicMap.end()) {
508+
partonicRow = itPM->second;
509+
} else {
510+
int partIdx = -1;
511+
if (mcParticle.has_mothers()) {
512+
partIdx = this->findFirstPartonicMother(mcParticle, mcParticles);
513+
}
514+
515+
bool partonicExists = (partIdx >= 0);
516+
517+
if (partonicExists) {
518+
int partonicPdg = mcParticles.iteratorAt(partIdx).pdgCode();
519+
520+
mcProducts.producedPartonicMothers(partonicPdg);
521+
partonicRow = mcProducts.producedPartonicMothers.lastIndex();
522+
mSigmaToMcPartonicMap[sigmaIndex] = partonicRow;
523+
}
524+
}
525+
mcProducts.producedSigmaLabels(mcParticleRow, mothersRow, partonicRow);
526+
}
527+
528+
template <modes::System system, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
529+
void fillMcSigmaPlusWithLabel(T1 const& col, T2 const& mcCols, T3 const& sigmaPlus, T4 const& sigmaPlusDaughter, T5 const& mcParticles, T6& mcProducts)
530+
{
531+
if (!mProduceSigmaPlusLabels) {
532+
return;
533+
}
534+
535+
if (!sigmaPlusDaughter.has_mcParticle()) {
536+
mcProducts.producedSigmaPlusLabels(-1, -1, -1);
537+
return;
538+
}
539+
540+
auto mcKinkDaughter = sigmaPlusDaughter.template mcParticle_as<T5>();
541+
auto mcKinkDaughterMothers = mcKinkDaughter.template mothers_as<T5>();
542+
543+
if (!mcKinkDaughter.has_mothers() && !mcKinkDaughterMothers.empty()) {
544+
mcProducts.producedSigmaPlusLabels(-1, -1, -1);
545+
return;
546+
}
547+
548+
// we get the mc kink partilce via the mother of the kink daughter
549+
auto mcParticle = mcKinkDaughterMothers.front();
550+
auto mcCol = mcParticle.template mcCollision_as<T2>();
551+
552+
int64_t particleIndex = mcParticle.globalIndex();
553+
int64_t sigmaIndex = sigmaPlus.globalIndex();
554+
555+
int64_t mcParticleRow = -1;
556+
557+
// MC PARTICLE
558+
auto itP = mSigmaPlusToMcParticleMap.find(particleIndex);
559+
if (itP != mSigmaPlusToMcParticleMap.end()) {
560+
mcParticleRow = itP->second;
561+
} else {
562+
auto origin = this->getOrigin(col, mcCols, mcParticle);
563+
int64_t mcColId = this->getMcColId<system>(mcCol, mcProducts);
564+
565+
mcProducts.producedMcParticles(
566+
mcColId,
567+
static_cast<aod::femtodatatypes::McOriginType>(origin),
568+
mcParticle.pdgCode(),
569+
mcParticle.pt() * utils::signum(mcParticle.pdgCode()),
570+
mcParticle.eta(),
571+
mcParticle.phi());
572+
573+
mcParticleRow = mcProducts.producedMcParticles.lastIndex();
574+
mSigmaPlusToMcParticleMap[particleIndex] = mcParticleRow;
575+
}
576+
577+
// mothers (fill only if exists)
578+
int64_t mothersRow = -1;
579+
auto itM = mSigmaPlusToMcMotherMap.find(sigmaIndex);
580+
581+
if (itM != mSigmaPlusToMcMotherMap.end()) {
582+
mothersRow = itM->second;
583+
} else {
584+
585+
auto mothers = mcParticle.template mothers_as<T5>();
586+
bool motherExists = mcParticle.has_mothers() && !mothers.empty();
587+
588+
if (motherExists) {
589+
int motherPdg = mothers.front().pdgCode(); // PDG code is ALWAYS valid if the mother exists
590+
591+
mcProducts.producedMothers(motherPdg);
592+
mothersRow = mcProducts.producedMothers.lastIndex();
593+
mSigmaPlusToMcMotherMap[sigmaIndex] = mothersRow;
594+
}
595+
}
596+
597+
// partonic mother (fill only if exists)
598+
int64_t partonicRow = -1;
599+
auto itPM = mSigmaPlusToMcPartonicMap.find(sigmaIndex);
600+
601+
if (itPM != mSigmaPlusToMcPartonicMap.end()) {
602+
partonicRow = itPM->second;
603+
} else {
604+
int partIdx = -1;
605+
if (mcParticle.has_mothers()) {
606+
partIdx = this->findFirstPartonicMother(mcParticle, mcParticles);
607+
}
608+
609+
bool partonicExists = (partIdx >= 0);
610+
611+
if (partonicExists) {
612+
int partonicPdg = mcParticles.iteratorAt(partIdx).pdgCode();
613+
614+
mcProducts.producedPartonicMothers(partonicPdg);
615+
partonicRow = mcProducts.producedPartonicMothers.lastIndex();
616+
mSigmaPlusToMcPartonicMap[sigmaIndex] = partonicRow;
617+
}
618+
}
619+
mcProducts.producedSigmaPlusLabels(mcParticleRow, mothersRow, partonicRow);
426620
}
427621

428622
template <typename TParticle, typename TContainer>
@@ -488,8 +682,18 @@ class McBuilder
488682
mK0shortToMcParticleMap.clear();
489683
mK0shortToMcMotherMap.clear();
490684
mK0shortToMcPartonicMap.clear();
685+
686+
mSigmaToMcParticleMap.clear();
687+
mSigmaToMcMotherMap.clear();
688+
mSigmaToMcPartonicMap.clear();
689+
690+
mSigmaPlusToMcParticleMap.clear();
691+
mSigmaPlusToMcMotherMap.clear();
692+
mSigmaPlusToMcPartonicMap.clear();
491693
}
492694

695+
bool fillAnyTable() const { return mFillAnyTable; }
696+
493697
private:
494698
bool mPassThrough = false;
495699
bool mFillAnyTable = false;
@@ -502,6 +706,8 @@ class McBuilder
502706
bool mProduceTrackLabels = false;
503707
bool mProduceLambdaLabels = false;
504708
bool mProduceK0shortLabels = false;
709+
bool mProduceSigmaLabels = false;
710+
bool mProduceSigmaPlusLabels = false;
505711

506712
std::unordered_map<int64_t, int64_t> mCollisionMap;
507713

@@ -516,6 +722,14 @@ class McBuilder
516722
std::unordered_map<int64_t, int64_t> mK0shortToMcParticleMap;
517723
std::unordered_map<int64_t, int64_t> mK0shortToMcMotherMap;
518724
std::unordered_map<int64_t, int64_t> mK0shortToMcPartonicMap;
725+
726+
std::unordered_map<int64_t, int64_t> mSigmaToMcParticleMap;
727+
std::unordered_map<int64_t, int64_t> mSigmaToMcMotherMap;
728+
std::unordered_map<int64_t, int64_t> mSigmaToMcPartonicMap;
729+
730+
std::unordered_map<int64_t, int64_t> mSigmaPlusToMcParticleMap;
731+
std::unordered_map<int64_t, int64_t> mSigmaPlusToMcMotherMap;
732+
std::unordered_map<int64_t, int64_t> mSigmaPlusToMcPartonicMap;
519733
};
520734

521735
} // namespace mcbuilder

PWGCF/Femto/Core/trackHistManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ struct ConfTrackMcBinning : o2::framework::ConfigurableGroup {
269269
constexpr const char PrefixTrackMcBinning1[] = "TrackMcBinning1";
270270
constexpr const char PrefixV0PosDauMcBinning[] = "V0PosDauMcBinning";
271271
constexpr const char PrefixV0NegDauMcBinning[] = "V0NegDauMcBinning";
272+
constexpr const char PrefixKinkChaDauMcBinning[] = "KinkChaDauMcBinning";
272273

273274
using ConfTrackMcBinning1 = ConfTrackMcBinning<PrefixTrackMcBinning1>;
274275
using ConfV0PosDauMcBinning = ConfTrackMcBinning<PrefixV0PosDauMcBinning>;
275276
using ConfV0NegDauMcBinning = ConfTrackMcBinning<PrefixV0NegDauMcBinning>;
277+
using ConfKinkChaDauMcBinning = ConfTrackMcBinning<PrefixKinkChaDauMcBinning>;
276278

277279
// must be in sync with enum TrackVariables
278280
// the enum gives the correct index in the array

PWGCF/Femto/Core/v0HistManager.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ constexpr std::array<histmanager::HistInfo<V0Hist>, kV0HistLast> HistTable = {
177177
{kK0shortMassVsAntiLambdaMass, o2::framework::kTH2F, "hK0shortMassVsAntiLambdaMass", "K^{0}_{S} mass vs #bar{#Lambda} mass; m_{#pi^{+}#pi^{-}} (GeV/#it{c}^{2}); m_{#bar{p}#pi^{+}} (GeV/#it{c}^{2})"},
178178
{kLambdaMassVsAntiLambdaMass, o2::framework::kTH2F, "hLambdaMassVsAntiLambdaMass", "#Lambda mass vs #bar{#Lambda}; m_{p#pi^{-}} (GeV/#it{c}^{2}); m_{#bar{p}#pi^{+}} (GeV/#it{c}^{2})"},
179179
{kOrigin, o2::framework::kTH1F, "hOrigin", "Status Codes (=Origin); Status Code; Entries"},
180-
{kPdg, o2::framework::kTH1F, "hPdg", "PDG Codes of selected tracks; PDG Code; Entries"},
181-
{kPdgMother, o2::framework::kTH1F, "hPdgMother", "PDG Codes of mother of selected tracks; PDG Code; Entries"},
182-
{kPdgPartonicMother, o2::framework::kTH1F, "hPdgPartonicMother", "PDG Codes of partonic mother selected tracks; PDG Code; Entries"},
180+
{kPdg, o2::framework::kTH1F, "hPdg", "PDG Codes of reconstructed v0; PDG Code; Entries"},
181+
{kPdgMother, o2::framework::kTH1F, "hPdgMother", "PDG Codes of mother of reconstructed v0; PDG Code; Entries"},
182+
{kPdgPartonicMother, o2::framework::kTH1F, "hPdgPartonicMother", "PDG Codes of partonic mother of reconstructed v0; PDG Code; Entries"},
183183
{kTruePt, o2::framework::kTH1F, "hTruePt", "True transverse momentum; p_{T} (GeV/#it{c}); Entries"},
184184
{kTrueEta, o2::framework::kTH1F, "hTrueEta", "True pseudorapdity; #eta; Entries"},
185185
{kTruePhi, o2::framework::kTH1F, "hTruePhi", "True azimuthal angle; #varphi; Entries"},
@@ -407,6 +407,7 @@ class V0HistManager
407407
}
408408

409409
private:
410+
410411
// for qa
411412
template <typename T1>
412413
void enableOptionalHistograms(T1 const& V0ConfBinningQa)
@@ -418,7 +419,7 @@ class V0HistManager
418419
template <typename T1, typename T2>
419420
void enableOptionalHistograms(T1 const& V0ConfBinningQa, T2 const& V0ConfBinningMc)
420421
{
421-
mPlot2d = V0ConfBinningQa.plot2d.value;
422+
this->enableOptionalHistograms(V0ConfBinningQa);
422423

423424
mPlotOrigins = V0ConfBinningMc.plotOrigins.value;
424425
mPlotNSecondaries = V0ConfBinningMc.pdgCodesForMothersOfSecondary.value.size();

0 commit comments

Comments
 (0)