DD4hep  1.36.0
Detector Description Toolkit for High Energy Physics
Geant4IsotropeGenerator.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DDG4_GEANT4ISOTROPEGENERATOR_H
15 #define DDG4_GEANT4ISOTROPEGENERATOR_H
16 
17 // Framework include files
19 
20 // C/C++ include files
21 #include <array>
22 #include <cstdint>
23 #include <functional>
24 #include <mutex>
25 
27 namespace dd4hep {
28 
30  namespace sim {
31 
32  // Forward declarations
33  class Geant4Random;
34 
36 
55  protected:
57  std::string m_distribution;
59  double m_phiMin;
61  double m_phiMax;
63  double m_thetaMin;
65  double m_thetaMax;
67  bool m_halton;
69  uint64_t m_haltonOffset;
71  mutable uint64_t m_haltonIndex;
73  mutable std::array<double,3> m_haltonShift;
75  mutable std::once_flag m_haltonOnce;
76 
78  void initHalton(Geant4Random& rnd) const;
80  static double haltonValue(uint64_t index, int base);
82  double haltonScrambled(uint64_t index, unsigned int dim) const;
85  std::function<double(unsigned int)> makeSampler(Geant4Random& rnd) const;
87  void sampleMomentum(double h, double& momentum) const;
88 
90 
93  virtual void getParticleDirection(int num, ROOT::Math::XYZVector& direction, double& momentum) const override;
95  void getParticleDirectionFFbar(int num, ROOT::Math::XYZVector& direction, double& momentum) const;
97  void getParticleDirectionEta(int num, const std::function<double(unsigned int)>& sample, ROOT::Math::XYZVector& direction, double& momentum) const;
99  void getParticleDirectionCosTheta(int num, const std::function<double(unsigned int)>& sample, ROOT::Math::XYZVector& direction, double& momentum) const;
101  void getParticleDirectionUniform(int num, const std::function<double(unsigned int)>& sample, ROOT::Math::XYZVector& direction, double& momentum) const;
102 
103  public:
109  Geant4IsotropeGenerator(Geant4Context* context, const std::string& name);
111  virtual ~Geant4IsotropeGenerator();
112  };
113  } // End namespace sim
114 } // End namespace dd4hep
115 #endif // DDG4_GEANT4ISOTROPEGENERATOR_H
dd4hep::sim::Geant4IsotropeGenerator::~Geant4IsotropeGenerator
virtual ~Geant4IsotropeGenerator()
Default destructor.
Definition: Geant4IsotropeGenerator.cpp:39
dd4hep::sim::Geant4IsotropeGenerator::m_phiMax
double m_phiMax
Property: Maximal phi angular value.
Definition: Geant4IsotropeGenerator.h:61
Geant4ParticleGenerator.h
dd4hep::sim::Geant4IsotropeGenerator::m_distribution
std::string m_distribution
Property: Distribution name. Default: "uniform". Allowed: "uniform", "cos(theta)",...
Definition: Geant4IsotropeGenerator.h:57
dd4hep::sim::Geant4IsotropeGenerator::m_haltonIndex
uint64_t m_haltonIndex
Current Halton sequence index (incremented per generated particle)
Definition: Geant4IsotropeGenerator.h:71
dd4hep::sim::Geant4IsotropeGenerator::m_phiMin
double m_phiMin
Property: Minimal phi angular value.
Definition: Geant4IsotropeGenerator.h:59
dd4hep::sim::Geant4IsotropeGenerator::m_thetaMax
double m_thetaMax
Property: Maximal theta angular value.
Definition: Geant4IsotropeGenerator.h:65
dd4hep::sim::Geant4IsotropeGenerator::m_haltonOffset
uint64_t m_haltonOffset
Property: Starting index in the Halton sequence (use for parallel-job partitioning)
Definition: Geant4IsotropeGenerator.h:69
dd4hep::sim::Geant4IsotropeGenerator::m_thetaMin
double m_thetaMin
Property: Minimal theta angular value.
Definition: Geant4IsotropeGenerator.h:63
dd4hep::sim::Geant4IsotropeGenerator::makeSampler
std::function< double(unsigned int)> makeSampler(Geant4Random &rnd) const
Build a per-particle sampler: PRNG or Halton depending on m_halton.
Definition: Geant4IsotropeGenerator.cpp:71
dd4hep::sim::Geant4IsotropeGenerator::haltonScrambled
double haltonScrambled(uint64_t index, unsigned int dim) const
Return the scrambled Halton sample for dimension dim (0=phi,1=theta,2=momentum)
Definition: Geant4IsotropeGenerator.cpp:62
dd4hep::sim::Geant4IsotropeGenerator::Geant4IsotropeGenerator
Geant4IsotropeGenerator(const Geant4IsotropeGenerator &copy)=delete
Inhibit copy constructor.
dd4hep::sim::Geant4IsotropeGenerator::sampleMomentum
void sampleMomentum(double h, double &momentum) const
Sample momentum from [m_momentumMin, m_momentumMax] using a pre-computed [0,1) value h.
Definition: Geant4IsotropeGenerator.cpp:81
dd4hep::sim::Geant4IsotropeGenerator::initHalton
void initHalton(Geant4Random &rnd) const
Initialize Cranley-Patterson shifts using rnd; set m_haltonIndex = m_haltonOffset.
Definition: Geant4IsotropeGenerator.cpp:44
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirectionFFbar
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)
Definition: Geant4IsotropeGenerator.cpp:131
dd4hep::sim::Geant4IsotropeGenerator::Geant4IsotropeGenerator
Geant4IsotropeGenerator()=delete
Inhibit default constructor.
dd4hep::sim::Geant4IsotropeGenerator::m_haltonOnce
std::once_flag m_haltonOnce
Ensures initHalton() runs exactly once across all events.
Definition: Geant4IsotropeGenerator.h:75
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4ParticleGenerator
Generate particles isotrop in space around origine (0,0,0)
Definition: Geant4ParticleGenerator.h:38
dd4hep::sim::Geant4IsotropeGenerator::haltonValue
static double haltonValue(uint64_t index, int base)
Compute the radical inverse of index in the given base (standard Halton value)
Definition: Geant4IsotropeGenerator.cpp:50
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirection
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...
Definition: Geant4IsotropeGenerator.cpp:156
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirectionEta
void getParticleDirectionEta(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Flat pseudorapidity (eta) distribution.
Definition: Geant4IsotropeGenerator.cpp:112
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirectionCosTheta
void getParticleDirectionCosTheta(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Particle distribution ~ cos(theta)
Definition: Geant4IsotropeGenerator.cpp:102
dd4hep::sim::Geant4IsotropeGenerator::getParticleDirectionUniform
void getParticleDirectionUniform(int num, const std::function< double(unsigned int)> &sample, ROOT::Math::XYZVector &direction, double &momentum) const
Uniform particle distribution.
Definition: Geant4IsotropeGenerator.cpp:93
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4IsotropeGenerator
Generate particles isotrop in space around origine (0,0,0)
Definition: Geant4IsotropeGenerator.h:54
dd4hep::sim::Geant4IsotropeGenerator::m_haltonShift
std::array< double, 3 > m_haltonShift
Per-dimension additive scramble shifts in [0,1), sampled from Geant4Random on first use.
Definition: Geant4IsotropeGenerator.h:73
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4IsotropeGenerator::m_halton
bool m_halton
Property: Enable scrambled Halton sequence sampling (RQMC mode)
Definition: Geant4IsotropeGenerator.h:67