00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 00028 // 00029 // MODULE: G4SingleParticleSource.hh 00030 // 00031 // Version: 1.0 00032 // Date: 5/02/04 00033 // Author: Fan Lei 00034 // Organisation: QinetiQ ltd. 00035 // Customer: ESA/ESTEC 00036 // 00038 // 00039 // CHANGE HISTORY 00040 // -------------- 00041 // 00042 // Version 1.0, 05/02/2004, Fan Lei, Created. 00043 // Based on the G4GeneralParticleSource class in Geant4 v6.0 00044 // 00046 // 00047 #include <cmath> 00048 00049 #include "G4SingleParticleSource.hh" 00050 00051 #include "G4SystemOfUnits.hh" 00052 #include "G4PrimaryParticle.hh" 00053 #include "G4Event.hh" 00054 #include "Randomize.hh" 00055 #include "G4ParticleTable.hh" 00056 #include "G4Geantino.hh" 00057 #include "G4ParticleDefinition.hh" 00058 #include "G4IonTable.hh" 00059 #include "G4Ions.hh" 00060 #include "G4TrackingManager.hh" 00061 #include "G4Track.hh" 00062 00063 G4SingleParticleSource::G4SingleParticleSource() { 00064 // Initialise all variables 00065 // Position distribution Variables 00066 00067 NumberOfParticlesToBeGenerated = 1; 00068 particle_definition = G4Geantino::GeantinoDefinition(); 00069 G4ThreeVector zero; 00070 particle_momentum_direction = G4ParticleMomentum(1, 0, 0); 00071 particle_energy = 1.0 * MeV; 00072 particle_position = zero; 00073 particle_time = 0.0; 00074 particle_polarization = zero; 00075 particle_charge = 0.0; 00076 particle_weight = 1.0; 00077 00078 biasRndm = new G4SPSRandomGenerator(); 00079 posGenerator = new G4SPSPosDistribution(); 00080 posGenerator->SetBiasRndm(biasRndm); 00081 angGenerator = new G4SPSAngDistribution(); 00082 angGenerator->SetPosDistribution(posGenerator); 00083 angGenerator->SetBiasRndm(biasRndm); 00084 eneGenerator = new G4SPSEneDistribution(); 00085 eneGenerator->SetBiasRndm(biasRndm); 00086 00087 // verbosity 00088 verbosityLevel = 0; 00089 00090 } 00091 00092 G4SingleParticleSource::~G4SingleParticleSource() { 00093 delete biasRndm; 00094 delete posGenerator; 00095 delete angGenerator; 00096 delete eneGenerator; 00097 } 00098 00099 void G4SingleParticleSource::SetVerbosity(int vL) { 00100 verbosityLevel = vL; 00101 posGenerator->SetVerbosity(vL); 00102 angGenerator->SetVerbosity(vL); 00103 eneGenerator->SetVerbosity(vL); 00104 G4cout << "Verbosity Set to: " << verbosityLevel << G4endl; 00105 } 00106 00107 void G4SingleParticleSource::SetParticleDefinition( 00108 G4ParticleDefinition* aParticleDefinition) { 00109 particle_definition = aParticleDefinition; 00110 particle_charge = particle_definition->GetPDGCharge(); 00111 } 00112 00113 void G4SingleParticleSource::GeneratePrimaryVertex(G4Event *evt) { 00114 if (particle_definition == NULL) 00115 return; 00116 00117 if (verbosityLevel > 1) 00118 G4cout << " NumberOfParticlesToBeGenerated: " 00119 << NumberOfParticlesToBeGenerated << G4endl; 00120 00121 // Position stuff 00122 particle_position = posGenerator->GenerateOne(); 00123 00124 // create a new vertex 00125 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position, 00126 particle_time); 00127 00128 for (G4int i = 0; i < NumberOfParticlesToBeGenerated; i++) { 00129 // Angular stuff 00130 particle_momentum_direction = angGenerator->GenerateOne(); 00131 // Energy stuff 00132 particle_energy = eneGenerator->GenerateOne(particle_definition); 00133 00134 if (verbosityLevel >= 2) 00135 G4cout << "Creating primaries and assigning to vertex" << G4endl; 00136 // create new primaries and set them to the vertex 00137 G4double mass = particle_definition->GetPDGMass(); 00138 G4PrimaryParticle* particle = 00139 new G4PrimaryParticle(particle_definition); 00140 particle->SetKineticEnergy( particle_energy ); 00141 particle->SetMass( mass ); 00142 particle->SetMomentumDirection( particle_momentum_direction ); 00143 particle->SetCharge( particle_charge ); 00144 particle->SetPolarization(particle_polarization.x(), 00145 particle_polarization.y(), 00146 particle_polarization.z()); 00147 if (verbosityLevel > 1) { 00148 G4cout << "Particle name: " 00149 << particle_definition->GetParticleName() << G4endl; 00150 G4cout << " Energy: " << particle_energy << G4endl; 00151 G4cout << " Position: " << particle_position << G4endl; 00152 G4cout << " Direction: " << particle_momentum_direction 00153 << G4endl; 00154 } 00155 // Set bweight equal to the multiple of all non-zero weights 00156 particle_weight = eneGenerator->GetWeight()*biasRndm->GetBiasWeight(); 00157 // pass it to primary particle 00158 particle->SetWeight(particle_weight); 00159 00160 vertex->SetPrimary(particle); 00161 00162 } 00163 // now pass the weight to the primary vertex. CANNOT be used here! 00164 // vertex->SetWeight(particle_weight); 00165 evt->AddPrimaryVertex(vertex); 00166 if (verbosityLevel > 1) 00167 G4cout << " Primary Vetex generated !" << G4endl; 00168 } 00169