|
9 | 9 | #include <string> |
10 | 10 | #include <vector> |
11 | 11 |
|
| 12 | +#include "Math/Vector3D.h" |
| 13 | +#include "Math/Vector4D.h" |
| 14 | + |
12 | 15 | R__ADD_INCLUDE_PATH($O2DPG_MC_CONFIG_ROOT) |
13 | 16 | #include "MC/config/common/external/generator/CoalescencePythia8.h" |
14 | 17 |
|
@@ -240,6 +243,7 @@ class GeneratorPythia8HFEmbedCharmNuclei : public o2::eventgen::GeneratorPythia8 |
240 | 243 | // we try the coalescence here, if successful we copy particles in the pythia event and we move to the next charm nucleus |
241 | 244 | isCoalSuccess = CoalescencePythia8(mPythiaGun.event, std::vector<unsigned int>{1000010020}, mTrivialCoal, mCoalMomentum, dausToCoal[0], dausToCoal[1], 10.); |
242 | 245 | if (isCoalSuccess) { |
| 246 | + restoreEnergyConservation(mPythiaGun.event, idxCharmNucleus); |
243 | 247 | 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 |
244 | 248 | for (int iPart{0}; iPart<mPythiaGun.event.size(); ++iPart) { |
245 | 249 | auto part = mPythiaGun.event[iPart]; |
@@ -274,6 +278,32 @@ class GeneratorPythia8HFEmbedCharmNuclei : public o2::eventgen::GeneratorPythia8 |
274 | 278 |
|
275 | 279 |
|
276 | 280 | 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 | + |
277 | 307 | // Properties of selection |
278 | 308 | float mMassCharmNucleus; /// mass of the charmed nucleus |
279 | 309 | int mPdgCharmNucleus; /// pdg code of the charmed nucleus |
|
0 commit comments