Geant4-11
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
G4INCL::PhaseSpaceRauboldLynch Class Reference

Generate momenta using the RauboldLynch method. More...

#include <G4INCLPhaseSpaceRauboldLynch.hh>

Inheritance diagram for G4INCL::PhaseSpaceRauboldLynch:
G4INCL::IPhaseSpaceGenerator

Public Member Functions

void generate (const G4double sqrtS, ParticleList &particles)
 Generate momenta according to a uniform, Lorentz-invariant phase-space model. More...
 
G4double getMaxGeneratedWeight () const
 Return the largest generated weight. More...
 
PhaseSpaceRauboldLynchoperator= (PhaseSpaceRauboldLynch const &rhs)
 Dummy assignment operator to silence Coverity warning. More...
 
 PhaseSpaceRauboldLynch ()
 
 PhaseSpaceRauboldLynch (PhaseSpaceRauboldLynch const &other)
 Dummy copy constructor to silence Coverity warning. More...
 
virtual ~PhaseSpaceRauboldLynch ()
 

Private Member Functions

G4double computeMaximumWeightNaive ()
 Compute the maximum possible weight using a naive algorithm. More...
 
G4double computeMaximumWeightParam ()
 Compute the maximum possible weight using parametrizations. More...
 
G4double computeWeight ()
 Compute the maximum possible weight. More...
 
void generateEvent (ParticleList &particles)
 Generate an event. More...
 
void initialize (ParticleList &particles)
 Initialize internal structures (masses and sum of masses) More...
 

Private Attributes

G4double availableEnergy
 
std::vector< G4doubleinvariantMasses
 
std::vector< G4doublemasses
 
G4double maxGeneratedWeight
 
std::vector< G4doublemomentaCM
 
size_t nParticles
 
G4double prelog [wMaxNP]
 Precalculated coefficients: -ln(n) More...
 
std::vector< G4doublernd
 
G4double sqrtS
 
std::vector< G4doublesumMasses
 
InterpolationTablewMaxCorrection
 
InterpolationTablewMaxMassless
 

Static Private Attributes

static const size_t nMasslessParticlesTable = 13
 
static const G4double wMaxCorrectionX [wMaxNE]
 
static const G4double wMaxCorrectionY [wMaxNE]
 
static const G4double wMaxInterpolationMargin = std::log(1.5)
 
static const G4double wMaxMasslessX [wMaxNE]
 
static const G4double wMaxMasslessY [wMaxNE]
 
static const size_t wMaxNE = 30
 
static const size_t wMaxNP = 20
 

Detailed Description

Generate momenta using the RauboldLynch method.

Definition at line 49 of file G4INCLPhaseSpaceRauboldLynch.hh.

Constructor & Destructor Documentation

◆ PhaseSpaceRauboldLynch() [1/2]

G4INCL::PhaseSpaceRauboldLynch::PhaseSpaceRauboldLynch ( )

Definition at line 180 of file G4INCLPhaseSpaceRauboldLynch.cc.

180 :
181 nParticles(0),
182 sqrtS(0.),
183 availableEnergy(0.),
185 {
186 std::vector<G4double> wMaxMasslessXV(wMaxMasslessX, wMaxMasslessX + wMaxNE);
187 std::vector<G4double> wMaxMasslessYV(wMaxMasslessY, wMaxMasslessY + wMaxNE);
188 wMaxMassless = new InterpolationTable(wMaxMasslessXV, wMaxMasslessYV);
189 std::vector<G4double> wMaxCorrectionXV(wMaxCorrectionX, wMaxCorrectionX + wMaxNE);
190 std::vector<G4double> wMaxCorrectionYV(wMaxCorrectionY, wMaxCorrectionY + wMaxNE);
191 wMaxCorrection = new InterpolationTable(wMaxCorrectionXV, wMaxCorrectionYV);
192
193 // initialize the precalculated coefficients
194 prelog[0] = 0.;
195 for(size_t i=1; i<wMaxNP; ++i) {
196 prelog[i] = -std::log(G4double(i));
197 }
198 }
double G4double
Definition: G4Types.hh:83
G4double prelog[wMaxNP]
Precalculated coefficients: -ln(n)
static const G4double wMaxMasslessX[wMaxNE]
static const G4double wMaxMasslessY[wMaxNE]
static const G4double wMaxCorrectionY[wMaxNE]
static const G4double wMaxCorrectionX[wMaxNE]

References prelog, wMaxCorrection, wMaxCorrectionX, wMaxCorrectionY, wMaxMassless, wMaxMasslessX, wMaxMasslessY, wMaxNE, and wMaxNP.

◆ ~PhaseSpaceRauboldLynch()

G4INCL::PhaseSpaceRauboldLynch::~PhaseSpaceRauboldLynch ( )
virtual

Definition at line 200 of file G4INCLPhaseSpaceRauboldLynch.cc.

200 {
201 delete wMaxMassless;
202 delete wMaxCorrection;
203 }

References wMaxCorrection, and wMaxMassless.

◆ PhaseSpaceRauboldLynch() [2/2]

G4INCL::PhaseSpaceRauboldLynch::PhaseSpaceRauboldLynch ( PhaseSpaceRauboldLynch const &  other)

Dummy copy constructor to silence Coverity warning.

Member Function Documentation

◆ computeMaximumWeightNaive()

G4double G4INCL::PhaseSpaceRauboldLynch::computeMaximumWeightNaive ( )
private

Compute the maximum possible weight using a naive algorithm.

Definition at line 257 of file G4INCLPhaseSpaceRauboldLynch.cc.

257 {
258 // compute the maximum weight
259 G4double eMMax = sqrtS + masses[0];
260 G4double eMMin = 0.;
261 G4double wMax = 1.;
262 for(size_t i=1; i<nParticles; i++) {
263 eMMin += masses[i-1];
264 eMMax += masses[i];
265 wMax *= KinematicsUtils::momentumInCM(eMMax, eMMin, masses[i]);
266 }
267 return wMax;
268 }
G4double momentumInCM(Particle const *const p1, Particle const *const p2)
gives the momentum in the CM frame of two particles.

References masses, G4INCL::KinematicsUtils::momentumInCM(), nParticles, and sqrtS.

Referenced by computeMaximumWeightParam().

◆ computeMaximumWeightParam()

G4double G4INCL::PhaseSpaceRauboldLynch::computeMaximumWeightParam ( )
private

Compute the maximum possible weight using parametrizations.

Definition at line 270 of file G4INCLPhaseSpaceRauboldLynch.cc.

270 {
271#ifndef INCLXX_IN_GEANT4_MODE
272 if(nParticles>=wMaxNP) {
273 INCL_WARN("The requested number of particles (" << nParticles << ") requires extrapolation the tables in PhaseSpaceRauboldLynch. YMMV." << '\n');
274 }
275
277 INCL_WARN("The requested available energy (" << availableEnergy << " MeV) requires extrapolation the tables in PhaseSpaceRauboldLynch. YMMV." << '\n');
278 }
279#endif
280
281 // compute the maximum weight
282 const G4double logMassless = ((*wMaxMassless)(availableEnergy)+prelog[nParticles])*(nParticles-1);
283 const G4double reducedSqrtS = availableEnergy/sumMasses[nParticles-1];
284 const G4double correction = (*wMaxCorrection)(reducedSqrtS);
285 const G4double wMax = std::exp(correction*G4double(nParticles-1) + logMassless + wMaxInterpolationMargin);
286 if(wMax>0.)
287 return wMax;
288 else
290 }
#define INCL_WARN(x)
G4double computeMaximumWeightNaive()
Compute the maximum possible weight using a naive algorithm.

References availableEnergy, computeMaximumWeightNaive(), INCL_WARN, nParticles, prelog, sumMasses, wMaxInterpolationMargin, wMaxMasslessX, wMaxNE, and wMaxNP.

Referenced by generate().

◆ computeWeight()

G4double G4INCL::PhaseSpaceRauboldLynch::computeWeight ( )
private

Compute the maximum possible weight.

Definition at line 292 of file G4INCLPhaseSpaceRauboldLynch.cc.

292 {
293 // Generate nParticles-2 sorted random numbers, bracketed by 0 and 1
294 rnd[0] = 0.;
295 for(size_t i=1; i<nParticles-1; ++i)
296 rnd[i] = Random::shoot();
297 rnd[nParticles-1] = 1.;
298 std::sort(rnd.begin()+1, rnd.begin()+nParticles-1);
299
300 // invariant masses
301 for(size_t i=0; i<nParticles; ++i)
303
304 // compute the CM momenta and the weight for the current event
306 momentaCM[0] = weight;
307 for(size_t i=1; i<nParticles-1; ++i) {
308 G4double momentumCM;
309// assert(invariantMasses[i+1]-invariantMasses[i]-masses[i+1]> - 1.E-8);
310 if(invariantMasses[i+1]-invariantMasses[i]-masses[i+1] < 0.) momentumCM = 0.;
312 momentaCM[i] = momentumCM;
313 weight *= momentumCM;
314 }
315
316 return weight;
317 }
G4double shoot()
Definition: G4INCLRandom.cc:93

References availableEnergy, invariantMasses, masses, momentaCM, G4INCL::KinematicsUtils::momentumInCM(), nParticles, rnd, G4INCL::Random::shoot(), and sumMasses.

Referenced by generate().

◆ generate()

void G4INCL::PhaseSpaceRauboldLynch::generate ( const G4double  sqrtS,
ParticleList particles 
)
virtual

Generate momenta according to a uniform, Lorentz-invariant phase-space model.

This function will assign momenta to the particles in the list that is passed as an argument. The event is generated in the CM frame.

Parameters
sqrtStotal centre-of-mass energy of the system
particleslist of particles

Implements G4INCL::IPhaseSpaceGenerator.

Definition at line 205 of file G4INCLPhaseSpaceRauboldLynch.cc.

205 {
207
208 sqrtS = sqs;
209
210 // initialize the structures containing the particle masses
211 initialize(particles);
212
213 // initialize the maximum weight
214 const G4double weightMax = computeMaximumWeightParam();
215
216 const G4int maxIter = 500;
217 G4int iter = 0;
218 G4double weight, r;
219 do {
220 weight = computeWeight();
222// assert(weight<=weightMax);
223 r = Random::shoot();
224 } while(++iter<maxIter && r*weightMax>weight); /* Loop checking, 10.07.2015, D.Mancusi */
225
226#ifndef INCLXX_IN_GEANT4_MODE
227 if(iter>=maxIter) {
228 INCL_WARN("Number of tries exceeded in PhaseSpaceRauboldLynch::generate()\n"
229 << "nParticles=" << nParticles << ", sqrtS=" << sqrtS << '\n');
230 }
231#endif
232
233 generateEvent(particles);
234 }
int G4int
Definition: G4Types.hh:85
void initialize(ParticleList &particles)
Initialize internal structures (masses and sum of masses)
void generateEvent(ParticleList &particles)
Generate an event.
G4double computeMaximumWeightParam()
Compute the maximum possible weight using parametrizations.
G4double computeWeight()
Compute the maximum possible weight.
T max(const T t1, const T t2)
brief Return the largest of the two arguments

References computeMaximumWeightParam(), computeWeight(), generateEvent(), INCL_WARN, initialize(), G4INCL::Math::max(), maxGeneratedWeight, nParticles, G4INCL::Random::shoot(), and sqrtS.

◆ generateEvent()

void G4INCL::PhaseSpaceRauboldLynch::generateEvent ( ParticleList particles)
private

Generate an event.

Definition at line 319 of file G4INCLPhaseSpaceRauboldLynch.cc.

319 {
320 Particle *p = particles[0];
321 ThreeVector momentum = Random::normVector(momentaCM[0]);
322 p->setMomentum(momentum);
323 p->adjustEnergyFromMomentum();
324
325 ThreeVector boostV;
326
327 for(size_t i=1; i<nParticles; ++i) {
328 p = particles[i];
329 p->setMomentum(-momentum);
330 p->adjustEnergyFromMomentum();
331
332 if(i==nParticles-1)
333 break;
334
335 momentum = Random::normVector(momentaCM[i]);
336
337 const G4double iM = invariantMasses[i];
338 const G4double recoilE = std::sqrt(momentum.mag2() + iM*iM);
339 boostV = -momentum/recoilE;
340 for(size_t j=0; j<=i; ++j)
341 particles[j]->boost(boostV);
342 }
343 }
ThreeVector normVector(G4double norm=1.)

References G4INCL::Particle::adjustEnergyFromMomentum(), invariantMasses, G4INCL::ThreeVector::mag2(), momentaCM, G4INCL::Random::normVector(), nParticles, and G4INCL::Particle::setMomentum().

Referenced by generate().

◆ getMaxGeneratedWeight()

G4double G4INCL::PhaseSpaceRauboldLynch::getMaxGeneratedWeight ( ) const

Return the largest generated weight.

Definition at line 345 of file G4INCLPhaseSpaceRauboldLynch.cc.

345 {
346 return maxGeneratedWeight;
347 }

References maxGeneratedWeight.

◆ initialize()

void G4INCL::PhaseSpaceRauboldLynch::initialize ( ParticleList particles)
private

Initialize internal structures (masses and sum of masses)

Definition at line 236 of file G4INCLPhaseSpaceRauboldLynch.cc.

236 {
237 nParticles = particles.size();
238// assert(nParticles>2);
239
240 // masses and sum of masses
241 masses.resize(nParticles);
242 sumMasses.resize(nParticles);
243 std::transform(particles.begin(), particles.end(), masses.begin(), std::mem_fn(&Particle::getMass));
244 std::partial_sum(masses.begin(), masses.end(), sumMasses.begin());
245
246 // sanity check
248// assert(availableEnergy>-1.e-5);
249 if(availableEnergy<0.)
250 availableEnergy = 0.;
251
252 rnd.resize(nParticles);
254 momentaCM.resize(nParticles-1);
255 }
G4double getMass() const
Get the cached particle mass.
G4bool transform(G4String &input, const G4String &type)

References availableEnergy, G4INCL::Particle::getMass(), invariantMasses, masses, momentaCM, nParticles, rnd, sqrtS, sumMasses, and G4coutFormatters::anonymous_namespace{G4coutFormatters.cc}::transform().

Referenced by generate().

◆ operator=()

PhaseSpaceRauboldLynch & G4INCL::PhaseSpaceRauboldLynch::operator= ( PhaseSpaceRauboldLynch const &  rhs)

Dummy assignment operator to silence Coverity warning.

Field Documentation

◆ availableEnergy

G4double G4INCL::PhaseSpaceRauboldLynch::availableEnergy
private

◆ invariantMasses

std::vector<G4double> G4INCL::PhaseSpaceRauboldLynch::invariantMasses
private

Definition at line 78 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeWeight(), generateEvent(), and initialize().

◆ masses

std::vector<G4double> G4INCL::PhaseSpaceRauboldLynch::masses
private

◆ maxGeneratedWeight

G4double G4INCL::PhaseSpaceRauboldLynch::maxGeneratedWeight
private

Definition at line 83 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by generate(), and getMaxGeneratedWeight().

◆ momentaCM

std::vector<G4double> G4INCL::PhaseSpaceRauboldLynch::momentaCM
private

Definition at line 79 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeWeight(), generateEvent(), and initialize().

◆ nMasslessParticlesTable

const size_t G4INCL::PhaseSpaceRauboldLynch::nMasslessParticlesTable = 13
staticprivate

Definition at line 85 of file G4INCLPhaseSpaceRauboldLynch.hh.

◆ nParticles

size_t G4INCL::PhaseSpaceRauboldLynch::nParticles
private

◆ prelog

G4double G4INCL::PhaseSpaceRauboldLynch::prelog[wMaxNP]
private

Precalculated coefficients: -ln(n)

Definition at line 99 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeMaximumWeightParam(), and PhaseSpaceRauboldLynch().

◆ rnd

std::vector<G4double> G4INCL::PhaseSpaceRauboldLynch::rnd
private

Definition at line 77 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeWeight(), and initialize().

◆ sqrtS

G4double G4INCL::PhaseSpaceRauboldLynch::sqrtS
private

Definition at line 81 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeMaximumWeightNaive(), generate(), and initialize().

◆ sumMasses

std::vector<G4double> G4INCL::PhaseSpaceRauboldLynch::sumMasses
private

◆ wMaxCorrection

InterpolationTable* G4INCL::PhaseSpaceRauboldLynch::wMaxCorrection
private

◆ wMaxCorrectionX

const G4double G4INCL::PhaseSpaceRauboldLynch::wMaxCorrectionX
staticprivate

Definition at line 89 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by PhaseSpaceRauboldLynch().

◆ wMaxCorrectionY

const G4double G4INCL::PhaseSpaceRauboldLynch::wMaxCorrectionY
staticprivate

Definition at line 90 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by PhaseSpaceRauboldLynch().

◆ wMaxInterpolationMargin

const G4double G4INCL::PhaseSpaceRauboldLynch::wMaxInterpolationMargin = std::log(1.5)
staticprivate

Definition at line 91 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by computeMaximumWeightParam().

◆ wMaxMassless

InterpolationTable* G4INCL::PhaseSpaceRauboldLynch::wMaxMassless
private

◆ wMaxMasslessX

const G4double G4INCL::PhaseSpaceRauboldLynch::wMaxMasslessX
staticprivate

◆ wMaxMasslessY

const G4double G4INCL::PhaseSpaceRauboldLynch::wMaxMasslessY
staticprivate

Definition at line 88 of file G4INCLPhaseSpaceRauboldLynch.hh.

Referenced by PhaseSpaceRauboldLynch().

◆ wMaxNE

const size_t G4INCL::PhaseSpaceRauboldLynch::wMaxNE = 30
staticprivate

◆ wMaxNP

const size_t G4INCL::PhaseSpaceRauboldLynch::wMaxNP = 20
staticprivate

The documentation for this class was generated from the following files: