Skip to content

Commit cc9bc73

Browse files
author
Francesco Mazzaschi
committed
Add trivial coalescence + feed-down index reassignment
1 parent 21ec6c2 commit cc9bc73

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

Generators/include/Generators/NuclCoalescencePythia8.h

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum NucleiBits {
4040
std::vector<unsigned int> pdgList = {10010010, 1000010030, 1000020030, 1010010030, 1000020040};
4141
std::vector<float> massList = {1.875612, 2.80892113298, 2.808391, 2.991134, 3.727379};
4242

43-
bool coalPythia8(Pythia8::Event& event, int charge, int pdgCode, float mass, double coalescenceRadius, int iD1, int iD2, int iD3 = -1, int iD4 = -1)
43+
bool coalPythia8(Pythia8::Event& event, int charge, int pdgCode, float mass, bool trivialCoal, double coalescenceRadius, bool nuclFromDecay, int iD1, int iD2, int iD3 = -1, int iD4 = -1)
4444
{
4545
std::vector<int> nucleonIDs = std::vector<int>{iD1, iD2};
4646
// add A=3 and A=4 nuclei if enabled
@@ -50,10 +50,10 @@ bool coalPythia8(Pythia8::Event& event, int charge, int pdgCode, float mass, dou
5050
if (iD4 > 0) {
5151
nucleonIDs.push_back(iD4);
5252
}
53-
// coalescence afterburner
5453
Pythia8::Vec4 p;
5554
for (auto nID : nucleonIDs) {
5655
if (event[nID].status() < 0) {
56+
// nucleon already used in coalescence
5757
return false;
5858
}
5959
p += event[nID].p();
@@ -62,7 +62,8 @@ bool coalPythia8(Pythia8::Event& event, int charge, int pdgCode, float mass, dou
6262
for (auto nID : nucleonIDs) {
6363
auto pN = event[nID].p();
6464
pN.bstback(p);
65-
if (pN.pAbs() > coalescenceRadius) {
65+
// trivial coal does not check the distance of the nucleons
66+
if (pN.pAbs() > coalescenceRadius && !trivialCoal) {
6667
isCoalescence = false;
6768
break;
6869
}
@@ -71,22 +72,49 @@ bool coalPythia8(Pythia8::Event& event, int charge, int pdgCode, float mass, dou
7172
return false;
7273
}
7374
p.e(std::hypot(p.pAbs(), mass));
74-
/// In order to avoid the transport of the mother particles, but to still keep them in the stack, we set the status to negative and we mark the nucleus status as 94 (decay product)
75-
event.append((charge * 2 - 1) * pdgCode, 94, 0, 0, 0, 0, 0, 0, p.px(), p.py(), p.pz(), p.e(), mass);
76-
for (auto nID : nucleonIDs) {
77-
event[nID].statusNeg();
78-
event[nID].daughter1(event.size() - 1);
75+
76+
if (!nuclFromDecay) {
77+
/// keep the original nucleons with negative status, store the mother with status 94
78+
event.append((charge * 2 - 1) * pdgCode, 94, 0, 0, 0, 0, 0, 0, p.px(), p.py(), p.pz(), p.e(), mass);
79+
for (auto nID : nucleonIDs) {
80+
event[nID].statusNeg();
81+
event[nID].daughter1(event.size() - 1);
82+
}
83+
} else {
84+
// first nucleon will be replaced by the nucleus, the others will be removed
85+
bool swap = true;
86+
int nRemoved = 0;
87+
for (auto iPart{0}; iPart < event.size(); ++iPart) {
88+
for (auto nID : nucleonIDs) {
89+
if (iPart == nID && swap) {
90+
// replace the nucleon with the nucleus
91+
LOG(debug) << "Replacing nucleon with index " << iPart << " and pdg code " << event[iPart].id() << " with nucleus with pdg code " << (charge * 2 - 1) * pdgCode;
92+
event[iPart].id((charge * 2 - 1) * pdgCode);
93+
event[iPart].status(94);
94+
event[iPart].px(p.px());
95+
event[iPart].py(p.py());
96+
event[iPart].pz(p.pz());
97+
event[iPart].e(std::hypot(p.pAbs(), mass));
98+
event[iPart].m(mass);
99+
swap = false;
100+
} else if (iPart == nID - nRemoved && !swap) {
101+
LOG(debug) << "Removing nucleon with index " << iPart << " and pdg code " << event[iPart].id();
102+
event.remove(iPart, iPart, true);
103+
nRemoved++;
104+
}
105+
}
106+
}
79107
}
80-
fmt::printf(">> Adding a %i with p = %f, %f, %f, E = %f\n", (charge * 2 - 1) * pdgCode, p.px(), p.py(), p.pz(), p.e());
108+
LOG(debug) "Adding a " << (charge * 2 - 1) * pdgCode << " with p = " << p.px() << ", " << p.py() << ", " << p.pz() << ", E = " << p.e();
81109
return true;
82110
}
83111

84-
bool CoalAfterburner(Pythia8::Event& event, std::vector<unsigned int> inputPdgList = {}, double coalMomentum = 0.4, int firstDauID = -1, int lastDauId = -1)
112+
bool CoalAfterburner(Pythia8::Event& event, std::vector<unsigned int> inputPdgList = {}, bool trivialCoal = false, double coalMomentum = 0.4, int firstDauID = -1, int lastDauId = -1)
85113
{
86114
const double coalescenceRadius{0.5 * 1.122462 * coalMomentum};
87115
// if coalescence from a heavy hadron, loop only between firstDauID and lastDauID
88-
int loopStart = firstDauID > 0 ? firstDauID : 0;
89-
int loopEnd = lastDauId > 0 ? lastDauId : event.size() - 1;
116+
int loopStart = firstDauID > -1 ? firstDauID : 0;
117+
int loopEnd = lastDauId > -1 ? lastDauId : event.size() - 1;
90118
// fill the nuclear mask
91119
uint8_t nuclearMask = 0;
92120
for (auto nuclPdg : inputPdgList) {
@@ -121,32 +149,34 @@ bool CoalAfterburner(Pythia8::Event& event, std::vector<unsigned int> inputPdgLi
121149
}
122150
}
123151
// run coalescence
152+
bool nuclFromDecay = firstDauID > -1;
124153
bool coalHappened = false;
154+
125155
for (int iC{0}; iC < 2; ++iC) {
126156
for (int iP{0}; iP < protons[iC].size(); ++iP) {
127157
for (int iN{0}; iN < neutrons[iC].size(); ++iN) {
128158
if (nuclearMask & (1 << kDeuteron)) {
129-
coalHappened |= coalPythia8(event, iC, pdgList[kDeuteron], massList[kDeuteron], coalescenceRadius, protons[iC][iP], neutrons[iC][iN]);
159+
coalHappened |= coalPythia8(event, iC, pdgList[kDeuteron], massList[kDeuteron], trivialCoal, coalescenceRadius, nuclFromDecay, protons[iC][iP], neutrons[iC][iN]);
130160
}
131161
if (nuclearMask & (1 << kTriton)) {
132162
for (int iN2{iN + 1}; iN2 < neutrons[iC].size(); ++iN2) {
133-
coalHappened |= coalPythia8(event, iC, pdgList[kTriton], massList[kTriton], coalescenceRadius, protons[iC][iP], neutrons[iC][iN], neutrons[iC][iN2]);
163+
coalHappened |= coalPythia8(event, iC, pdgList[kTriton], massList[kTriton], trivialCoal, coalescenceRadius, nuclFromDecay, protons[iC][iP], neutrons[iC][iN], neutrons[iC][iN2]);
134164
}
135165
}
136166
if (nuclearMask & (1 << kHe3)) {
137167
for (int iP2{iP + 1}; iP2 < protons[iC].size(); ++iP2) {
138-
coalHappened |= coalPythia8(event, iC, pdgList[kHe3], massList[kHe3], coalescenceRadius, protons[iC][iP], protons[iC][iP2], neutrons[iC][iN]);
168+
coalHappened |= coalPythia8(event, iC, pdgList[kHe3], massList[kHe3], trivialCoal, coalescenceRadius, nuclFromDecay, protons[iC][iP], protons[iC][iP2], neutrons[iC][iN]);
139169
}
140170
}
141171
if (nuclearMask & (1 << kHyperTriton)) {
142172
for (int iL{0}; iL < lambdas[iC].size(); ++iL) {
143-
coalHappened |= coalPythia8(event, iC, pdgList[kHyperTriton], massList[kHyperTriton], coalescenceRadius, protons[iC][iP], neutrons[iC][iN], lambdas[iC][iL]);
173+
coalHappened |= coalPythia8(event, iC, pdgList[kHyperTriton], massList[kHyperTriton], trivialCoal, coalescenceRadius, nuclFromDecay, protons[iC][iP], neutrons[iC][iN], lambdas[iC][iL]);
144174
}
145175
}
146176
if (nuclearMask & (1 << kHe4)) {
147177
for (int iP2{iP + 1}; iP2 < protons[iC].size(); ++iP2) {
148178
for (int iN2{iN + 1}; iN2 < neutrons[iC].size(); ++iN2) {
149-
coalHappened |= coalPythia8(event, iC, pdgList[kHe4], massList[kHe4], coalescenceRadius, protons[iC][iP], protons[iC][iP2], neutrons[iC][iN], neutrons[iC][iN2]);
179+
coalHappened |= coalPythia8(event, iC, pdgList[kHe4], massList[kHe4], trivialCoal, coalescenceRadius, nuclFromDecay, protons[iC][iP], protons[iC][iP2], neutrons[iC][iN], neutrons[iC][iN2]);
150180
}
151181
}
152182
}

0 commit comments

Comments
 (0)