Skip to content

Commit 470b2b0

Browse files
authored
Fix px/py bug in generator_pythia8_gun.C (#1683)
This fixes a very old bug in which a random uniform number is chosen for py and then px is calculated accordingly, which is not a valid manner of randomly emitting particles uniformly in azimuth and will lead to a modulation versus azimuthal angle. Not sure if this is relevant for anyone at all but it's best fixed for posterity. Note that the relevant generation is still done in p (total momentum) and not pT (transverse momentum): this remains unchanged.
1 parent 26e3f65 commit 470b2b0

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

MC/config/PWGHF/pythia8_gun/generator_pythia8_gun.C

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class GeneratorPythia8Gun : public o2::eventgen::GeneratorPythia8
135135
/// generate uniform eta and uniform momentum
136136
void genUniformMomentumEta(double minP, double maxP, double minEta, double maxEta)
137137
{
138+
// Warning: this generator samples randomly in p and not in pT. Care is advised
139+
138140
// random generator
139141
std::unique_ptr<TRandom3> ranGenerator{new TRandom3()};
140142
ranGenerator->SetSeed(0);
@@ -146,15 +148,11 @@ class GeneratorPythia8Gun : public o2::eventgen::GeneratorPythia8
146148
// z-component momentum from eta
147149
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
148150
const double gen_pz = gen_p * cosTheta;
149-
// y-component: random uniform
150-
const double maxVal = sqrt(gen_p * gen_p - gen_pz * gen_pz);
151-
double sign_py = ranGenerator->Uniform(0, 1);
152-
sign_py = (sign_py > 0.5) ? 1. : -1.;
153-
const double gen_py = ranGenerator->Uniform(0., maxVal) * sign_py;
154-
// x-component momentum
155-
double sign_px = ranGenerator->Uniform(0, 1);
156-
sign_px = (sign_px > 0.5) ? 1. : -1.;
157-
const double gen_px = sqrt(gen_p * gen_p - gen_pz * gen_pz - gen_py * gen_py) * sign_px;
151+
// phi: random uniform, X, Y conform
152+
const double pT = sqrt(gen_p * gen_p - gen_pz * gen_pz);
153+
double phi = ranGenerator->Uniform(0., 2.0f*TMath::Pi());
154+
const double gen_px = pT*TMath::Cos(phi);
155+
const double gen_py = pT*TMath::Sin(phi);
158156

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

290288
return myGen;
291-
}
289+
}

0 commit comments

Comments
 (0)