[966] | 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 | // |
---|
| 27 | // $Id: Tst01ParticleGun.cc,v 1.6 2008/10/24 15:24:16 kurasige Exp $ |
---|
[1196] | 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
[966] | 29 | // |
---|
| 30 | |
---|
| 31 | // G4ParticleGun |
---|
| 32 | #include "Tst01ParticleGun.hh" |
---|
| 33 | #include "Tst01ParticleGunMessenger.hh" |
---|
| 34 | #include "G4Event.hh" |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | Tst01ParticleGun::Tst01ParticleGun() |
---|
| 39 | :G4ParticleGun() |
---|
| 40 | { |
---|
| 41 | SetInitialValues(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | Tst01ParticleGun::Tst01ParticleGun(G4int ) |
---|
| 46 | :G4ParticleGun(1) |
---|
| 47 | { |
---|
| 48 | SetInitialValues(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | Tst01ParticleGun::Tst01ParticleGun(G4ParticleDefinition * particleDef, |
---|
| 53 | G4int ) |
---|
| 54 | :G4ParticleGun(particleDef, 1) |
---|
| 55 | { |
---|
| 56 | SetInitialValues(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | Tst01ParticleGun::~Tst01ParticleGun() |
---|
| 61 | { |
---|
| 62 | while (!decay_products.empty()){ |
---|
| 63 | G4PrimaryParticle* particle = (G4PrimaryParticle*)(decay_products.back()); |
---|
| 64 | decay_products.pop_back(); |
---|
| 65 | delete particle; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | Tst01ParticleGun::Tst01ParticleGun(const Tst01ParticleGun &right) |
---|
| 70 | : G4ParticleGun() |
---|
| 71 | { |
---|
| 72 | *this = right; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | const Tst01ParticleGun & Tst01ParticleGun::operator=(const Tst01ParticleGun &right) |
---|
| 77 | { |
---|
| 78 | if ( this == &right) return *this; |
---|
| 79 | NumberOfParticlesToBeGenerated = right.NumberOfParticlesToBeGenerated; |
---|
| 80 | particle_definition = right.particle_definition; |
---|
| 81 | particle_momentum_direction = right.particle_momentum_direction; |
---|
| 82 | particle_energy = right.particle_energy; |
---|
| 83 | particle_charge = right.particle_charge; |
---|
| 84 | particle_polarization = right.particle_polarization; |
---|
| 85 | particle_decay_time = right.particle_decay_time; |
---|
| 86 | decay_products.clear(); |
---|
| 87 | return *this; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void Tst01ParticleGun::GeneratePrimaryVertex(G4Event* evt) |
---|
| 91 | { |
---|
| 92 | if(particle_definition==NULL) return; |
---|
| 93 | |
---|
| 94 | // create a new vertex |
---|
| 95 | G4PrimaryVertex* vertex = |
---|
| 96 | new G4PrimaryVertex(particle_position,particle_time); |
---|
| 97 | |
---|
| 98 | // create new primaries and set them to the vertex |
---|
| 99 | G4double mass = particle_definition->GetPDGMass(); |
---|
| 100 | G4double energy = particle_energy + mass; |
---|
| 101 | G4double pmom = std::sqrt(energy*energy-mass*mass); |
---|
| 102 | G4double px = pmom*particle_momentum_direction.x(); |
---|
| 103 | G4double py = pmom*particle_momentum_direction.y(); |
---|
| 104 | G4double pz = pmom*particle_momentum_direction.z(); |
---|
| 105 | |
---|
| 106 | G4PrimaryParticle* particle = |
---|
| 107 | new G4PrimaryParticle(particle_definition,px,py,pz); |
---|
| 108 | particle->SetMass( mass ); |
---|
| 109 | particle->SetCharge( particle_charge ); |
---|
| 110 | particle->SetPolarization(particle_polarization.x(), |
---|
| 111 | particle_polarization.y(), |
---|
| 112 | particle_polarization.z()); |
---|
| 113 | if (particle_decay_time>=0.) particle->SetProperTime(particle_decay_time); |
---|
| 114 | while (!decay_products.empty()){ |
---|
| 115 | G4PrimaryParticle* daughter = (G4PrimaryParticle*)(decay_products.back()); |
---|
| 116 | decay_products.pop_back(); |
---|
| 117 | particle->SetDaughter(daughter); |
---|
| 118 | } |
---|
| 119 | vertex->SetPrimary( particle ); |
---|
| 120 | |
---|
| 121 | evt->AddPrimaryVertex( vertex ); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | void Tst01ParticleGun::SetInitialValues() |
---|
| 126 | { |
---|
| 127 | NumberOfParticlesToBeGenerated = 1; |
---|
| 128 | particle_definition = NULL; |
---|
| 129 | G4ThreeVector zero; |
---|
| 130 | particle_momentum_direction = (G4ParticleMomentum)zero; |
---|
| 131 | particle_energy = 0.0; |
---|
| 132 | particle_position = zero; |
---|
| 133 | particle_time = 0.0; |
---|
| 134 | particle_polarization = zero; |
---|
| 135 | particle_charge = 0.0; |
---|
| 136 | |
---|
| 137 | particle_decay_time = -1.0; |
---|
| 138 | |
---|
| 139 | theMessenger = new Tst01ParticleGunMessenger(this); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|