Skip to content

Commit b1010a8

Browse files
author
Francesco Mazzaschi
committed
Fix MC generated information
1 parent 9fc053f commit b1010a8

File tree

1 file changed

+59
-30
lines changed

1 file changed

+59
-30
lines changed

PWGLF/Tasks/Strangeness/sigmaminustask.cxx

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace o2::framework::expressions;
2828

2929
using TracksFull = soa::Join<aod::TracksIU, aod::TracksExtra, aod::TracksCovIU, aod::pidTPCPi>;
3030
using CollisionsFull = soa::Join<aod::Collisions, aod::EvSel>;
31-
using CollisionsFullMC = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::EvSels>;
31+
using CollisionsFullMC = soa::Join<aod::Collisions, aod::McCollisionLabels, aod::EvSel>;
3232

3333
struct sigmaminustask {
3434
// Histograms are defined with HistogramRegistry
@@ -39,6 +39,9 @@ struct sigmaminustask {
3939
Configurable<float> cutzvertex{"cutzvertex", 10.0f, "Accepted z-vertex range (cm)"};
4040
Configurable<float> cutNSigmaPi{"cutNSigmaPi", 4, "NSigmaTPCPion"};
4141

42+
Preslice<aod::KinkCands> mPerCol = aod::track::collisionId;
43+
44+
4245
void init(InitContext const&)
4346
{
4447
// Axes
@@ -58,7 +61,8 @@ struct sigmaminustask {
5861

5962
if (doprocessMC) {
6063
// Add MC histograms if needed
61-
rSigmaMinus.add("h2MassSigmaMinusPtMC", "h2MassSigmaMinusPtMC", {HistType::kTH2F, {ptAxis, sigmaMassAxis}});
64+
rSigmaMinus.add("h2MassPtMCRec", "h2MassPtMCRec", {HistType::kTH2F, {ptAxis, sigmaMassAxis}});
65+
rSigmaMinus.add("h2MassPtMCGen", "h2MassPtMCGen", {HistType::kTH2F, {ptAxis, sigmaMassAxis}});
6266
}
6367
}
6468

@@ -80,46 +84,71 @@ struct sigmaminustask {
8084
}
8185
PROCESS_SWITCH(sigmaminustask, processData, "Data processing", true);
8286

83-
void processMC(CollisionsFullMC::iterator const& collision, aod::KinkCands const& KinkCands, aod::McTrackLabels const& trackLabelsMC, aod::McParticles const&, TracksFull const&)
87+
void processMC(CollisionsFullMC const& collisions, aod::KinkCands const& KinkCands, aod::McTrackLabels const& trackLabelsMC, aod::McParticles const& particlesMC, TracksFull const&)
8488
{
85-
if (std::abs(collision.posZ()) > cutzvertex || !collision.sel8()) {
86-
return;
87-
}
88-
rEventSelection.fill(HIST("hVertexZRec"), collision.posZ());
89-
for (const auto& kinkCand : KinkCands) {
90-
auto dauTrack = kinkCand.trackDaug_as<TracksFull>();
91-
auto mothTrack = kinkCand.trackMoth_as<TracksFull>();
92-
if (dauTrack.sign() != mothTrack.sign()) {
93-
LOG(info) << "Skipping kink candidate with opposite sign daughter and mother: " << kinkCand.globalIndex();
94-
continue; // Skip if the daughter has the opposite sign as the mother
95-
}
96-
if (abs(dauTrack.tpcNSigmaPi()) > cutNSigmaPi) {
89+
for (const auto& collision : collisions) {
90+
if (std::abs(collision.posZ()) > cutzvertex || !collision.sel8()) {
9791
continue;
9892
}
9993

100-
rSigmaMinus.fill(HIST("h2MassSigmaMinusPt"), kinkCand.mothSign() * kinkCand.ptMoth(), kinkCand.mSigmaMinus());
101-
rSigmaMinus.fill(HIST("h2SigmaMassVsXiMass"), kinkCand.mXiMinus(), kinkCand.mSigmaMinus());
102-
rSigmaMinus.fill(HIST("h2NSigmaPiPt"), kinkCand.mothSign() * kinkCand.ptMoth(), dauTrack.tpcNSigmaPi());
103-
// do MC association
104-
auto mcLabSigma = trackLabelsMC.rawIteratorAt(mothTrack.globalIndex());
105-
auto mcLabPiDau = trackLabelsMC.rawIteratorAt(dauTrack.globalIndex());
106-
if (mcLabSigma.has_mcParticle() && mcLabPiDau.has_mcParticle()) {
107-
auto mcTrackSigma = mcLabSigma.mcParticle_as<aod::McParticles>();
108-
auto mcTrackPiDau = mcLabPiDau.mcParticle_as<aod::McParticles>();
109-
if (!mcTrackPiDau.has_mothers()) {
94+
rEventSelection.fill(HIST("hVertexZRec"), collision.posZ());
95+
auto kinkCandPerColl = KinkCands.sliceBy(mPerCol, collision.globalIndex());
96+
for (const auto& kinkCand : kinkCandPerColl) {
97+
auto dauTrack = kinkCand.trackDaug_as<TracksFull>();
98+
auto mothTrack = kinkCand.trackMoth_as<TracksFull>();
99+
if (dauTrack.sign() != mothTrack.sign()) {
100+
LOG(info) << "Skipping kink candidate with opposite sign daughter and mother: " << kinkCand.globalIndex();
101+
continue; // Skip if the daughter has the opposite sign as the mother
102+
}
103+
if (abs(dauTrack.tpcNSigmaPi()) > cutNSigmaPi) {
110104
continue;
111105
}
112-
for (auto& piMother : mcTrackPiDau.mothers_as<aod::McParticles>()) {
113-
if (piMother.globalIndex() != mcTrackSigma.globalIndex()) {
106+
107+
rSigmaMinus.fill(HIST("h2MassSigmaMinusPt"), kinkCand.mothSign() * kinkCand.ptMoth(), kinkCand.mSigmaMinus());
108+
rSigmaMinus.fill(HIST("h2SigmaMassVsXiMass"), kinkCand.mXiMinus(), kinkCand.mSigmaMinus());
109+
rSigmaMinus.fill(HIST("h2NSigmaPiPt"), kinkCand.mothSign() * kinkCand.ptMoth(), dauTrack.tpcNSigmaPi());
110+
// do MC association
111+
auto mcLabSigma = trackLabelsMC.rawIteratorAt(mothTrack.globalIndex());
112+
auto mcLabPiDau = trackLabelsMC.rawIteratorAt(dauTrack.globalIndex());
113+
if (mcLabSigma.has_mcParticle() && mcLabPiDau.has_mcParticle()) {
114+
auto mcTrackSigma = mcLabSigma.mcParticle_as<aod::McParticles>();
115+
auto mcTrackPiDau = mcLabPiDau.mcParticle_as<aod::McParticles>();
116+
if (!mcTrackPiDau.has_mothers()) {
114117
continue;
115118
}
116-
if (std::abs(mcTrackSigma.pdgCode()) != 3112 || std::abs(mcTrackPiDau.pdgCode()) != 211) {
117-
continue;
119+
for (auto& piMother : mcTrackPiDau.mothers_as<aod::McParticles>()) {
120+
if (piMother.globalIndex() != mcTrackSigma.globalIndex()) {
121+
continue;
122+
}
123+
if (std::abs(mcTrackSigma.pdgCode()) != 3112 || std::abs(mcTrackPiDau.pdgCode()) != 211) {
124+
continue;
125+
}
126+
rSigmaMinus.fill(HIST("h2MassPtMCRec"), kinkCand.mothSign() * kinkCand.ptMoth(), kinkCand.mSigmaMinus());
118127
}
119-
rSigmaMinus.fill(HIST("h2MassSigmaMinusPtMC"), kinkCand.mothSign() * kinkCand.ptMoth(), kinkCand.mSigmaMinus());
120128
}
121129
}
122130
}
131+
for (const auto& mcPart : particlesMC) {
132+
if (std::abs(mcPart.pdgCode()) != 3112 || std::abs(mcPart.y()) > 0.5) {
133+
continue;
134+
}
135+
if (!mcPart.has_daughters()) {
136+
continue; // Skip if no daughters
137+
}
138+
bool hasSigmaDaughter = false;
139+
for (const auto& daughter : mcPart.daughters_as<aod::McParticles>()) {
140+
if (std::abs(daughter.pdgCode()) == 211) { // Sigma PDG code
141+
hasSigmaDaughter = true;
142+
break; // Found a pi daughter, exit loop
143+
}
144+
}
145+
if (!hasSigmaDaughter) {
146+
continue; // Skip if no pi daughter found
147+
}
148+
float mcMass = std::sqrt(mcPart.e() * mcPart.e() - mcPart.p() * mcPart.p());
149+
int sigmaSign = mcPart.pdgCode() > 0 ? 1 : -1; // Determine the sign of the Sigma
150+
rSigmaMinus.fill(HIST("h2MassPtMCGen"), sigmaSign * mcPart.pt(), mcMass);
151+
}
123152
}
124153
PROCESS_SWITCH(sigmaminustask, processMC, "MC processing", false);
125154
};

0 commit comments

Comments
 (0)