Skip to content

Commit 429d545

Browse files
authored
[PWGLF] Refactor weight assignment: use first ancestor to avoid branching logic (#13309)
1 parent c8733a8 commit 429d545

File tree

1 file changed

+66
-45
lines changed

1 file changed

+66
-45
lines changed

PWGLF/Tasks/Nuspex/antinucleiInJets.cxx

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,22 @@ struct AntinucleiInJets {
500500
LOGP(info, "Successfully loaded reweighting histograms from CCDB path");
501501
}
502502

503+
// Get first ancestor
504+
aod::McParticle getFirstAncestor(aod::McParticle const& particle, aod::McParticles const& mcParticles)
505+
{
506+
auto current = particle;
507+
508+
while (current.has_mothers()) {
509+
auto motherId = current.mothersIds()[0];
510+
if (motherId < 0 || motherId >= mcParticles.size()) {
511+
break;
512+
}
513+
current = mcParticles.iteratorAt(motherId);
514+
}
515+
516+
return current;
517+
}
518+
503519
// Compute two unit vectors perpendicular to p
504520
void getPerpendicularAxis(const TVector3& p, TVector3& u, double sign)
505521
{
@@ -1428,56 +1444,61 @@ struct AntinucleiInJets {
14281444
registryMC.fill(HIST("antip_prim_low"), track.pt(), wPrimLow);
14291445
}
14301446

1431-
// Secondary antiprotons from week decays
1447+
// Secondary antiprotons from material
1448+
if (!particle.isPhysicalPrimary() && !particle.has_mothers()) {
1449+
1450+
// Fill histograms
1451+
registryMC.fill(HIST("antip_sec_pythia"), track.pt());
1452+
registryMC.fill(HIST("antip_sec_std"), track.pt());
1453+
registryMC.fill(HIST("antip_sec_up"), track.pt());
1454+
registryMC.fill(HIST("antip_sec_low"), track.pt());
1455+
}
1456+
1457+
// Secondary antiprotons from weak decays
14321458
if (!particle.isPhysicalPrimary() && particle.has_mothers()) {
14331459

1434-
// Initialize weights
1460+
// Get first ancestor
1461+
auto ancestor = getFirstAncestor(particle, mcParticles);
14351462
double wSecStd(1.0), wSecUp(1.0), wSecLow(1.0);
1436-
auto mother = mcParticles.iteratorAt(particle.mothersIds()[0]);
1437-
1438-
// Antiprotons from sigma
1439-
if (std::abs(mother.pdgCode()) == PDG_t::kSigmaBarMinus) {
1440-
if (mother.pt() < primaryAntiSigma->GetXaxis()->GetXmax()) {
1441-
int ipt = primaryAntiSigma->FindBin(mother.pt());
1442-
wSecStd = primaryAntiSigma->GetBinContent(ipt);
1443-
wSecUp = wSecStd + primaryAntiSigma->GetBinError(ipt);
1444-
wSecLow = wSecStd - primaryAntiSigma->GetBinError(ipt);
1445-
}
1463+
1464+
// Antiprotons from antiSigma
1465+
if (ancestor.pdgCode() == PDG_t::kSigmaBarMinus && ancestor.pt() < primaryAntiSigma->GetXaxis()->GetXmax()) {
1466+
int ipt = primaryAntiSigma->FindBin(ancestor.pt());
1467+
wSecStd = primaryAntiSigma->GetBinContent(ipt);
1468+
wSecUp = wSecStd + primaryAntiSigma->GetBinError(ipt);
1469+
wSecLow = wSecStd - primaryAntiSigma->GetBinError(ipt);
1470+
}
1471+
1472+
// Antiprotons from antiLambda0
1473+
if (ancestor.pdgCode() == PDG_t::kLambda0Bar && ancestor.pt() < primaryAntiLambda->GetXaxis()->GetXmax()) {
1474+
int ipt = primaryAntiLambda->FindBin(ancestor.pt());
1475+
wSecStd = primaryAntiLambda->GetBinContent(ipt);
1476+
wSecUp = wSecStd + primaryAntiLambda->GetBinError(ipt);
1477+
wSecLow = wSecStd - primaryAntiLambda->GetBinError(ipt);
1478+
}
1479+
1480+
// Antiprotons from antiXi
1481+
if (ancestor.pdgCode() == PDG_t::kXiPlusBar && ancestor.pt() < primaryAntiXi->GetXaxis()->GetXmax()) {
1482+
int ipt = primaryAntiXi->FindBin(ancestor.pt());
1483+
wSecStd = primaryAntiXi->GetBinContent(ipt);
1484+
wSecUp = wSecStd + primaryAntiXi->GetBinError(ipt);
1485+
wSecLow = wSecStd - primaryAntiXi->GetBinError(ipt);
1486+
}
1487+
1488+
// Antiprotons from antiXi0
1489+
if (ancestor.pdgCode() == -o2::constants::physics::Pdg::kXi0 && ancestor.pt() < primaryAntiXi->GetXaxis()->GetXmax()) {
1490+
int ipt = primaryAntiXi->FindBin(ancestor.pt());
1491+
wSecStd = primaryAntiXi->GetBinContent(ipt);
1492+
wSecUp = wSecStd + primaryAntiXi->GetBinError(ipt);
1493+
wSecLow = wSecStd - primaryAntiXi->GetBinError(ipt);
14461494
}
14471495

1448-
// Antiprotons from primary Lambda0
1449-
if (std::abs(mother.pdgCode()) == kLambda0Bar) {
1450-
if (mother.isPhysicalPrimary()) {
1451-
if (mother.pt() < primaryAntiLambda->GetXaxis()->GetXmax()) {
1452-
int ipt = primaryAntiLambda->FindBin(mother.pt());
1453-
wSecStd = primaryAntiLambda->GetBinContent(ipt);
1454-
wSecUp = wSecStd + primaryAntiLambda->GetBinError(ipt);
1455-
wSecLow = wSecStd - primaryAntiLambda->GetBinError(ipt);
1456-
}
1457-
}
1458-
1459-
// Antiprotons from secondary Lambda0 (Xi -> Lambda0)
1460-
if (!mother.isPhysicalPrimary()) {
1461-
auto grandmother = mcParticles.iteratorAt(mother.mothersIds()[0]);
1462-
if (std::abs(grandmother.pdgCode()) == kXiMinus) {
1463-
if (grandmother.pt() < primaryAntiXi->GetXaxis()->GetXmax()) {
1464-
int ipt = primaryAntiXi->FindBin(grandmother.pt());
1465-
wSecStd = primaryAntiXi->GetBinContent(ipt);
1466-
wSecUp = wSecStd + primaryAntiXi->GetBinError(ipt);
1467-
wSecLow = wSecStd - primaryAntiXi->GetBinError(ipt);
1468-
}
1469-
}
1470-
1471-
// Antiprotons from secondary Lambda0 (Omega -> Lambda0)
1472-
if (std::abs(grandmother.pdgCode()) == kOmegaMinus) {
1473-
if (grandmother.pt() < primaryAntiOmega->GetXaxis()->GetXmax()) {
1474-
int ipt = primaryAntiOmega->FindBin(grandmother.pt());
1475-
wSecStd = primaryAntiOmega->GetBinContent(ipt);
1476-
wSecUp = wSecStd + primaryAntiOmega->GetBinError(ipt);
1477-
wSecLow = wSecStd - primaryAntiOmega->GetBinError(ipt);
1478-
}
1479-
}
1480-
}
1496+
// Antiprotons from antiOmega
1497+
if (ancestor.pdgCode() == PDG_t::kOmegaPlusBar && ancestor.pt() < primaryAntiOmega->GetXaxis()->GetXmax()) {
1498+
int ipt = primaryAntiOmega->FindBin(ancestor.pt());
1499+
wSecStd = primaryAntiOmega->GetBinContent(ipt);
1500+
wSecUp = wSecStd + primaryAntiOmega->GetBinError(ipt);
1501+
wSecLow = wSecStd - primaryAntiOmega->GetBinError(ipt);
14811502
}
14821503

14831504
// Fill histograms

0 commit comments

Comments
 (0)