Skip to content

Commit 61a7bb7

Browse files
authored
Apply correction for energy (non)conservation in coalescence for c-deuteron (#2372)
1 parent 1581890 commit 61a7bb7

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

MC/config/PWGHF/external/generator/generator_pythia8_embed_charmnuclei.C

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <string>
1010
#include <vector>
1111

12+
#include "Math/Vector3D.h"
13+
#include "Math/Vector4D.h"
14+
1215
R__ADD_INCLUDE_PATH($O2DPG_MC_CONFIG_ROOT)
1316
#include "MC/config/common/external/generator/CoalescencePythia8.h"
1417

@@ -240,6 +243,7 @@ class GeneratorPythia8HFEmbedCharmNuclei : public o2::eventgen::GeneratorPythia8
240243
// we try the coalescence here, if successful we copy particles in the pythia event and we move to the next charm nucleus
241244
isCoalSuccess = CoalescencePythia8(mPythiaGun.event, std::vector<unsigned int>{1000010020}, mTrivialCoal, mCoalMomentum, dausToCoal[0], dausToCoal[1], 10.);
242245
if (isCoalSuccess) {
246+
restoreEnergyConservation(mPythiaGun.event, idxCharmNucleus);
243247
int offset = mPythia.event.size(); // we need to rescale the indices of mothers and daughters, accounting for the particles that are already appended to the event
244248
for (int iPart{0}; iPart<mPythiaGun.event.size(); ++iPart) {
245249
auto part = mPythiaGun.event[iPart];
@@ -274,6 +278,32 @@ class GeneratorPythia8HFEmbedCharmNuclei : public o2::eventgen::GeneratorPythia8
274278

275279

276280
private:
281+
282+
void restoreEnergyConservation(Pythia8::Event& event, int idxCharmNucleus, float targetMassTolerance = 1e-5) {
283+
/// In the coalescence, the energy is not conserved, we rescale the momentum of the charmed nuclei daughters to restore it to avoid changes in the invariant mass of the charmed nucleus
284+
285+
float scale = 1.f;
286+
float invMass{0.f};
287+
while (abs(invMass - mMassCharmNucleus) > targetMassTolerance) {
288+
ROOT::Math::PxPyPzMVector fourVecCharmNucleus;
289+
for (int iDau{event[idxCharmNucleus].daughter1()}; iDau<=event[idxCharmNucleus].daughter2(); ++iDau) {
290+
auto dau = event[iDau];
291+
fourVecCharmNucleus += ROOT::Math::PxPyPzMVector(dau.px() * scale, dau.py() * scale, dau.pz() * scale, dau.m());
292+
}
293+
invMass = fourVecCharmNucleus.M();
294+
scale *= mMassCharmNucleus / invMass;
295+
}
296+
297+
for (int iDau{event[idxCharmNucleus].daughter1()}; iDau<=event[idxCharmNucleus].daughter2(); ++iDau) {
298+
event[iDau].px(event[iDau].px() * scale);
299+
event[iDau].py(event[iDau].py() * scale);
300+
event[iDau].pz(event[iDau].pz() * scale);
301+
}
302+
event[idxCharmNucleus].px(event[idxCharmNucleus].px() * scale);
303+
event[idxCharmNucleus].py(event[idxCharmNucleus].py() * scale);
304+
event[idxCharmNucleus].pz(event[idxCharmNucleus].pz() * scale);
305+
}
306+
277307
// Properties of selection
278308
float mMassCharmNucleus; /// mass of the charmed nucleus
279309
int mPdgCharmNucleus; /// pdg code of the charmed nucleus

0 commit comments

Comments
 (0)