diff --git a/MC/config/common/external/generator/GeneratorHGPythia8.C b/MC/config/common/external/generator/GeneratorHGPythia8.C index 1e2a1d5c1..f81158933 100644 --- a/MC/config/common/external/generator/GeneratorHGPythia8.C +++ b/MC/config/common/external/generator/GeneratorHGPythia8.C @@ -116,6 +116,14 @@ class GeneratorHGPythia8 : public GeneratorPythia8 } mDensity[0].reset(makeNucleonDensity(mA, "HGPythia8A")); mDensity[1].reset(makeNucleonDensity(mB, "HGPythia8B")); + // Build the cumulative tables of the 1D densities here: TF1::GetRandom integrates on its first call, + // and the default integrator is created through Cling, which is not thread safe. + // In hybrid mode Init() runs on the main thread while events are generated on TBB workers. + for (auto& density : mDensity) { + if (density && !dynamic_cast(density.get())) { + density->GetRandom(mRandom.get()); + } + } for (int j = 0; j < 2; ++j) { mX[j].resize(j == 0 ? mA : mB); mY[j].resize(j == 0 ? mA : mB);