Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // G4ParticleGum 27 // 28 // Class description: 29 // 30 // This is a concrete class of G4VPrimaryGenerator. It shoots a particle of 31 // given type into a given direction with either a given kinetic energy or 32 // momentum. 33 // The position and time of the primary particle must be set by the 34 // corresponding set methods of the G4VPrimaryGenerator base class, otherwise 35 // zero will be set. 36 // 37 // The FAQ to this class is for randomizing position/direction/kinetic energy 38 // of the primary particle. But, G4ParticleGun does NOT have any way of 39 // randomization. Instead, the user's concrete implementation of 40 // G4VUserPrimaryGeneratorAction which transfer the G4Event object 41 // to this particle gun can randomize these quantities and set to this 42 // particle gun before invoking GeneratePrimaryVertex() method. 43 // Note that, even if the particle gun shoots more than one particles at one 44 // invokation of the GeneratePrimaryVertex() method, all particles have the 45 // same physical quantities. If the user wants to shoot two particles with 46 // different momentum, position, etc., should invoke GeneratePrimaryVertex() 47 // method twice and set quantities on demand to the particle gun. 48 49 // Author: Makoto Asai, 1997 50 // -------------------------------------------------------------------- 51 #ifndef G4ParticleGun_hh 52 #define G4ParticleGun_hh 1 53 54 #include "globals.hh" 55 #include "G4VPrimaryGenerator.hh" 56 #include "G4ThreeVector.hh" 57 #include "G4ParticleDefinition.hh" 58 #include "G4PrimaryVertex.hh" 59 #include "G4ParticleMomentum.hh" 60 61 class G4Event; 62 class G4ParticleGunMessenger; 63 64 class G4ParticleGun : public G4VPrimaryGenerator 65 { 66 public: 67 68 G4ParticleGun(); 69 explicit G4ParticleGun(G4int numberofparticles); 70 explicit G4ParticleGun(G4ParticleDefinition* particleDef, 71 G4int numberofparticles = 1); 72 // Costructors. "numberofparticles" is the number of particles to be 73 // shot at one invokation of GeneratePrimaryVertex() method. 74 // All particles are shot with the same physical quantities. 75 76 ~G4ParticleGun() override; 77 78 G4ParticleGun(const G4ParticleGun&) = delete; 79 const G4ParticleGun& operator=(const G4ParticleGun&) = delete; 80 G4bool operator==(const G4ParticleGun&) const = delete; 81 G4bool operator!=(const G4ParticleGun&) const = delete; 82 83 void GeneratePrimaryVertex(G4Event* evt) override; 84 // Creates a primary vertex at the given point 85 // and put primary particles to it. 86 87 // Followings are the Set methods for the particle properties. 88 // SetParticleDefinition() should be called first. 89 // By using SetParticleMomentum(), both particle_momentum_direction and 90 // particle_energy(Kinetic Energy) are set. 91 // 92 void SetParticleDefinition(G4ParticleDefinition* aParticleDefinition); 93 void SetParticleEnergy(G4double aKineticEnergy); 94 void SetParticleMomentum(G4double aMomentum); 95 void SetParticleMomentum(G4ParticleMomentum aMomentum); 96 inline void SetParticleMomentumDirection(G4ParticleMomentum aMomDirection) 97 { particle_momentum_direction = aMomDirection.unit(); } 98 inline void SetParticleCharge(G4double aCharge) 99 { particle_charge = aCharge; } 100 inline void SetParticlePolarization(G4ThreeVector aVal) 101 { particle_polarization = aVal; } 102 inline void SetNumberOfParticles(G4int i) 103 { NumberOfParticlesToBeGenerated = i; } 104 inline void SetParticleWeight(G4double w) 105 { particle_weight = w; } 106 107 inline G4ParticleDefinition* GetParticleDefinition() const 108 { return particle_definition; } 109 inline G4ParticleMomentum GetParticleMomentumDirection() const 110 { return particle_momentum_direction; } 111 inline G4double GetParticleEnergy() const 112 { return particle_energy; } 113 inline G4double GetParticleMomentum() const 114 { return particle_momentum; } 115 inline G4double GetParticleCharge() const 116 { return particle_charge; } 117 inline G4ThreeVector GetParticlePolarization() const 118 { return particle_polarization; } 119 inline G4int GetNumberOfParticles() const 120 { return NumberOfParticlesToBeGenerated; } 121 inline G4double GetParticleWeight() const 122 { return particle_weight; } 123 124 protected: 125 126 virtual void SetInitialValues(); 127 128 G4int NumberOfParticlesToBeGenerated = 0; 129 G4ParticleDefinition* particle_definition = nullptr; 130 G4ParticleMomentum particle_momentum_direction; 131 G4double particle_energy = 0.0; 132 G4double particle_momentum = 0.0; 133 G4double particle_charge = 0.0; 134 G4ThreeVector particle_polarization; 135 G4double particle_weight = 1.0; 136 137 private: 138 139 G4ParticleGunMessenger* theMessenger = nullptr; 140 }; 141 142 #endif 143 144 145