File indexing completed on 2025-01-18 09:14:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDG4/Geant4Context.h>
0018 #include <DDG4/Geant4Primary.h>
0019 #include <DDG4/Geant4ParticleGun.h>
0020 #include <DDG4/Geant4InputHandling.h>
0021 #include <CLHEP/Units/SystemOfUnits.h>
0022
0023
0024 #include <limits>
0025
0026 using namespace dd4hep::sim;
0027
0028
0029 Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const std::string& nam)
0030 : Geant4IsotropeGenerator(ctxt,nam), m_shotNo(0)
0031 {
0032 InstanceCount::increment(this);
0033 m_needsControl = true;
0034 declareProperty("Standalone", m_standalone = true);
0035 declareProperty("mask", m_mask);
0036 declareProperty("isotrop", m_isotrop = false);
0037 declareProperty("standalone", m_standalone);
0038
0039 declareProperty("position", m_position);
0040 declareProperty("distribution", m_distribution);
0041 declareProperty("direction", m_direction);
0042 declareProperty("particle", m_particleName);
0043 declareProperty("multiplicity", m_multiplicity);
0044 declareProperty("print", m_print = true);
0045 }
0046
0047
0048 Geant4ParticleGun::~Geant4ParticleGun() {
0049 InstanceCount::decrement(this);
0050 }
0051
0052
0053 void Geant4ParticleGun::getParticleDirection(int num, ROOT::Math::XYZVector& direction, double& momentum) const {
0054 ( m_isotrop )
0055 ? this->Geant4IsotropeGenerator::getParticleDirection(num, direction, momentum)
0056 : this->Geant4ParticleGenerator::getParticleDirection(num, direction, momentum);
0057 }
0058
0059
0060 void Geant4ParticleGun::operator()(G4Event* event) {
0061 double r = m_direction.R(), eps = std::numeric_limits<float>::epsilon();
0062 if ( r > eps ) {
0063 m_direction.SetXYZ(m_direction.X()/r, m_direction.Y()/r, m_direction.Z()/r);
0064 }
0065
0066 if ( m_standalone ) {
0067 generationInitialization(this,context());
0068 }
0069
0070
0071 if( m_energy != -1 ){
0072 m_momentumMin = m_energy;
0073 m_momentumMax = m_energy;
0074 }
0075
0076 print("Shoot [%d] [%.3f , %.3f] GeV %s pos:(%.3f %.3f %.3f)[mm] dir:(%6.3f %6.3f %6.3f)",
0077 m_shotNo, m_momentumMin/CLHEP::GeV, m_momentumMax/CLHEP::GeV, m_particleName.c_str(),
0078 m_position.X()/CLHEP::mm, m_position.Y()/CLHEP::mm, m_position.Z()/CLHEP::mm,
0079 m_direction.X(), m_direction.Y(), m_direction.Z());
0080 this->Geant4ParticleGenerator::operator()(event);
0081 if ( m_print ) {
0082 this->Geant4ParticleGenerator::printInteraction(m_mask);
0083 }
0084 ++m_shotNo;
0085 if ( m_standalone ) {
0086 mergeInteractions(this,context());
0087 generatePrimaries(this,context(),event);
0088 }
0089 }