 |
DD4hep
1.36.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file.
55 num = num * base + (index % base);
58 return static_cast<double>(num) /
static_cast<double>(denom);
63 static constexpr std::array<int,3> bases = {2, 3, 5};
64 if ( dim >= bases.size() ) {
65 except(
"haltonScrambled: dimension %u out of range [0,%zu].", dim, bases.size()-1);
75 return [
this, idx](
unsigned int dim) {
return haltonScrambled(idx, dim); };
77 return [&rnd](
unsigned int) {
return rnd.
rndm(); };
94 ROOT::Math::XYZVector& direction,
double& momentum)
const {
97 direction.SetXYZ(std::sin(theta)*std::cos(phi), std::sin(theta)*std::sin(phi), std::cos(theta));
103 ROOT::Math::XYZVector& direction,
double& momentum)
const {
106 double sin_theta = std::sqrt(1.0 - cos_theta*cos_theta);
107 direction.SetXYZ(sin_theta*std::cos(phi), sin_theta*std::sin(phi), cos_theta);
113 ROOT::Math::XYZVector& direction,
double& momentum)
const {
114 struct Distribution {
115 static double eta(
double x) {
return -1.0*std::log(std::tan(x/2.0)); }
121 double eta = eta_min + (eta_max - eta_min) * sample(1);
122 double x1 = std::cos(phi);
123 double x2 = std::sin(phi);
124 double x3 = std::sinh(eta);
125 double r = std::sqrt(1.0+x3*x3);
126 direction.SetXYZ(x1/r,x2/r,x3/r);
132 struct Distribution {
133 static double ffbar(
double x) {
double c = std::cos(x);
return 1 + c*c; }
143 double vmax = std::max(v1,v2);
145 double dice = rnd.
rndm()*vmax;
147 if ( dice <= Distribution::ffbar(theta) ) {
148 direction.SetXYZ(std::sin(theta)*std::cos(phi), std::sin(theta)*std::sin(phi), std::cos(theta));
158 except(
"Halton mode is incompatible with the 'ffbar' distribution: "
159 "acceptance-rejection cannot be driven by a fixed per-particle Halton point. "
160 "Use distribution='uniform', 'cos(theta)', or 'eta' with Halton mode.");
179 except(
"Unknown distribution density: %s. Cannot generate primaries.",
virtual ~Geant4IsotropeGenerator()
Default destructor.
double rndm(int i=0)
Create flat distributed random numbers in the interval ]0,1].
double m_phiMax
Property: Maximal phi angular value.
std::string m_distribution
Property: Distribution name. Default: "uniform". Allowed: "uniform", "cos(theta)",...
uint64_t m_haltonIndex
Current Halton sequence index (incremented per generated particle)
double m_momentumMin
Property: Minimal momentum value.
static void increment(T *)
Increment count according to type information.
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Geant4Random & random() const
Access the random number generator.
double m_phiMin
Property: Minimal phi angular value.
double m_thetaMax
Property: Maximal theta angular value.
uint64_t m_haltonOffset
Property: Starting index in the Halton sequence (use for parallel-job partitioning)
double m_energy
Property: Fixed momentum value, overwrites momentumMin and momentumMax if set.
double m_thetaMin
Property: Minimal theta angular value.
std::function< double(unsigned int)> makeSampler(Geant4Random &rnd) const
Build a per-particle sampler: PRNG or Halton depending on m_halton.
double haltonScrambled(uint64_t index, unsigned int dim) const
Return the scrambled Halton sample for dimension dim (0=phi,1=theta,2=momentum)
void sampleMomentum(double h, double &momentum) const
Sample momentum from [m_momentumMin, m_momentumMax] using a pre-computed [0,1) value h.
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
void initHalton(Geant4Random &rnd) const
Initialize Cranley-Patterson shifts using rnd; set m_haltonIndex = m_haltonOffset.
double m_momentumMax
Property: Maximal momentum value.
void getParticleDirectionFFbar(int num, ROOT::Math::XYZVector &direction, double &momentum) const
e+e- --> ffbar particle distribution ~ 1 + cos^2(theta) (PRNG only; incompatible with Halton)
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
static void decrement(T *)
Decrement count according to type information.
Geant4IsotropeGenerator()=delete
Inhibit default constructor.
std::once_flag m_haltonOnce
Ensures initHalton() runs exactly once across all events.
Mini interface to THE random generator of the application.
Generate particles isotrop in space around origine (0,0,0)
static double haltonValue(uint64_t index, int base)
Compute the radical inverse of index in the given base (standard Halton value)
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
virtual void getParticleDirection(int num, ROOT::Math::XYZVector &direction, double &momentum) const override
Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = [m_momentumM...
void getParticleDirectionEta(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Flat pseudorapidity (eta) distribution.
void getParticleDirectionCosTheta(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Particle distribution ~ cos(theta)
User event context for DDG4.
void getParticleDirectionUniform(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Uniform particle distribution.
Generic context to extend user, run and event information.
std::array< double, 3 > m_haltonShift
Per-dimension additive scramble shifts in [0,1), sampled from Geant4Random on first use.
Geant4Context * context() const
Access the context.
bool m_halton
Property: Enable scrambled Halton sequence sampling (RQMC mode)