Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix px/py bug in generator_pythia8_gun.C #1683

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions MC/config/PWGHF/pythia8_gun/generator_pythia8_gun.C
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class GeneratorPythia8Gun : public o2::eventgen::GeneratorPythia8
/// generate uniform eta and uniform momentum
void genUniformMomentumEta(double minP, double maxP, double minEta, double maxEta)
{
// Warning: this generator samples randomly in p and not in pT. Care is advised

// random generator
std::unique_ptr<TRandom3> ranGenerator{new TRandom3()};
ranGenerator->SetSeed(0);
Expand All @@ -146,15 +148,11 @@ class GeneratorPythia8Gun : public o2::eventgen::GeneratorPythia8
// z-component momentum from eta
const double cosTheta = (exp(2 * gen_eta) - 1) / (exp(2 * gen_eta) + 1); // starting from eta = -ln(tan(theta/2)) = 1/2*ln( (1+cos(theta))/(1-cos(theta)) ) ---> NB: valid for cos(theta)!=1
const double gen_pz = gen_p * cosTheta;
// y-component: random uniform
const double maxVal = sqrt(gen_p * gen_p - gen_pz * gen_pz);
double sign_py = ranGenerator->Uniform(0, 1);
sign_py = (sign_py > 0.5) ? 1. : -1.;
const double gen_py = ranGenerator->Uniform(0., maxVal) * sign_py;
// x-component momentum
double sign_px = ranGenerator->Uniform(0, 1);
sign_px = (sign_px > 0.5) ? 1. : -1.;
const double gen_px = sqrt(gen_p * gen_p - gen_pz * gen_pz - gen_py * gen_py) * sign_px;
// phi: random uniform, X, Y conform
const double pT = sqrt(gen_p * gen_p - gen_pz * gen_pz);
double phi = ranGenerator->Uniform(0., 2.0f*TMath::Pi());
const double gen_px = pT*TMath::Cos(phi);
const double gen_py = pT*TMath::Sin(phi);

set4momentum(gen_px, gen_py, gen_pz);
}
Expand Down Expand Up @@ -288,4 +286,4 @@ FairGenerator* generateOmegaAndPions_RandomCharge(const int nPions)
myGen->setAddFurtherPrimaries(-211, nPions / 2); // pi-

return myGen;
}
}