Changeset 1347 for trunk/source/event/src/G4SingleParticleSource.cc
- Timestamp:
- Dec 22, 2010, 3:52:27 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/event/src/G4SingleParticleSource.cc
r816 r1347 58 58 #include "G4SingleParticleSource.hh" 59 59 60 G4SingleParticleSource::G4SingleParticleSource() 61 { 62 // Initialise all variables 63 // Position distribution Variables 60 G4SingleParticleSource::G4SingleParticleSource() { 61 // Initialise all variables 62 // Position distribution Variables 64 63 65 66 67 68 particle_momentum_direction = G4ParticleMomentum(1,0,0);69 particle_energy = 1.0*MeV;70 71 72 73 74 64 NumberOfParticlesToBeGenerated = 1; 65 particle_definition = G4Geantino::GeantinoDefinition(); 66 G4ThreeVector zero; 67 particle_momentum_direction = G4ParticleMomentum(1, 0, 0); 68 particle_energy = 1.0 * MeV; 69 particle_position = zero; 70 particle_time = 0.0; 71 particle_polarization = zero; 72 particle_charge = 0.0; 73 particle_weight = 1.0; 75 74 76 77 78 79 80 81 82 83 75 biasRndm = new G4SPSRandomGenerator(); 76 posGenerator = new G4SPSPosDistribution(); 77 posGenerator->SetBiasRndm(biasRndm); 78 angGenerator = new G4SPSAngDistribution(); 79 angGenerator->SetPosDistribution(posGenerator); 80 angGenerator->SetBiasRndm(biasRndm); 81 eneGenerator = new G4SPSEneDistribution(); 82 eneGenerator->SetBiasRndm(biasRndm); 84 83 85 86 84 // verbosity 85 verbosityLevel = 0; 87 86 88 87 } 89 88 90 G4SingleParticleSource::~G4SingleParticleSource() 91 {} 92 93 void G4SingleParticleSource::SetVerbosity(int vL) 94 { 95 verbosityLevel = vL; 96 posGenerator->SetVerbosity(vL); 97 angGenerator->SetVerbosity(vL); 98 eneGenerator->SetVerbosity(vL); 99 G4cout << "Verbosity Set to: " << verbosityLevel << G4endl; 89 G4SingleParticleSource::~G4SingleParticleSource() { 90 delete biasRndm; 91 delete posGenerator; 92 delete angGenerator; 93 delete eneGenerator; 100 94 } 101 95 102 void G4SingleParticleSource::SetParticleDefinition 103 (G4ParticleDefinition* aParticleDefinition) 104 { 105 particle_definition = aParticleDefinition; 106 particle_charge = particle_definition->GetPDGCharge(); 96 void G4SingleParticleSource::SetVerbosity(int vL) { 97 verbosityLevel = vL; 98 posGenerator->SetVerbosity(vL); 99 angGenerator->SetVerbosity(vL); 100 eneGenerator->SetVerbosity(vL); 101 G4cout << "Verbosity Set to: " << verbosityLevel << G4endl; 107 102 } 108 103 109 void G4SingleParticleSource::GeneratePrimaryVertex(G4Event *evt) 110 { 111 if(particle_definition==NULL) return; 112 113 if(verbosityLevel > 1) 114 G4cout << " NumberOfParticlesToBeGenerated: "<<NumberOfParticlesToBeGenerated << G4endl; 115 116 // Position stuff 117 particle_position = posGenerator->GenerateOne(); 118 119 // create a new vertex 120 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position,particle_time); 121 122 for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ) { 123 // Angular stuff 124 particle_momentum_direction = angGenerator->GenerateOne(); 125 // Energy stuff 126 particle_energy = eneGenerator->GenerateOne(particle_definition); 127 128 if(verbosityLevel >= 2) 129 G4cout << "Creating primaries and assigning to vertex" << G4endl; 130 // create new primaries and set them to the vertex 131 G4double mass = particle_definition->GetPDGMass(); 132 G4double energy = particle_energy + mass; 133 G4double pmom = std::sqrt(energy*energy-mass*mass); 134 G4double px = pmom*particle_momentum_direction.x(); 135 G4double py = pmom*particle_momentum_direction.y(); 136 G4double pz = pmom*particle_momentum_direction.z(); 137 138 if(verbosityLevel > 1){ 139 G4cout << "Particle name: "<<particle_definition->GetParticleName() << G4endl; 140 G4cout << " Energy: "<<particle_energy << G4endl; 141 G4cout << " Position: "<<particle_position<< G4endl; 142 G4cout << " Direction: "<<particle_momentum_direction << G4endl; 143 } 144 G4PrimaryParticle* particle = 145 new G4PrimaryParticle(particle_definition,px,py,pz); 146 particle->SetMass( mass ); 147 particle->SetCharge( particle_charge ); 148 particle->SetPolarization(particle_polarization.x(), 149 particle_polarization.y(), 150 particle_polarization.z()); 151 // Set bweight equal to the multiple of all non-zero weights 152 particle_weight = biasRndm->GetBiasWeight(); 153 // pass it to primary particle 154 particle->SetWeight(particle_weight); 155 156 vertex->SetPrimary( particle ); 157 158 } 159 // now pass the weight to the primary vertex. CANNOT be used here! 160 // vertex->SetWeight(particle_weight); 161 evt->AddPrimaryVertex( vertex ); 162 if(verbosityLevel > 1) 163 G4cout << " Primary Vetex generated !"<< G4endl; 104 void G4SingleParticleSource::SetParticleDefinition( 105 G4ParticleDefinition* aParticleDefinition) { 106 particle_definition = aParticleDefinition; 107 particle_charge = particle_definition->GetPDGCharge(); 164 108 } 165 109 110 void G4SingleParticleSource::GeneratePrimaryVertex(G4Event *evt) { 111 if (particle_definition == NULL) 112 return; 166 113 114 if (verbosityLevel > 1) 115 G4cout << " NumberOfParticlesToBeGenerated: " 116 << NumberOfParticlesToBeGenerated << G4endl; 167 117 118 // Position stuff 119 particle_position = posGenerator->GenerateOne(); 168 120 121 // create a new vertex 122 G4PrimaryVertex* vertex = new G4PrimaryVertex(particle_position, 123 particle_time); 169 124 125 for (G4int i = 0; i < NumberOfParticlesToBeGenerated; i++) { 126 // Angular stuff 127 particle_momentum_direction = angGenerator->GenerateOne(); 128 // Energy stuff 129 particle_energy = eneGenerator->GenerateOne(particle_definition); 170 130 131 if (verbosityLevel >= 2) 132 G4cout << "Creating primaries and assigning to vertex" << G4endl; 133 // create new primaries and set them to the vertex 134 G4double mass = particle_definition->GetPDGMass(); 135 G4double energy = particle_energy + mass; 136 G4double pmom = std::sqrt(energy * energy - mass * mass); 137 G4double px = pmom * particle_momentum_direction.x(); 138 G4double py = pmom * particle_momentum_direction.y(); 139 G4double pz = pmom * particle_momentum_direction.z(); 171 140 141 if (verbosityLevel > 1) { 142 G4cout << "Particle name: " 143 << particle_definition->GetParticleName() << G4endl; 144 G4cout << " Energy: " << particle_energy << G4endl; 145 G4cout << " Position: " << particle_position << G4endl; 146 G4cout << " Direction: " << particle_momentum_direction 147 << G4endl; 148 } 149 G4PrimaryParticle* particle = new G4PrimaryParticle( 150 particle_definition, px, py, pz); 151 particle->SetMass(mass); 152 particle->SetCharge(particle_charge); 153 particle->SetPolarization(particle_polarization.x(), 154 particle_polarization.y(), particle_polarization.z()); 155 // Set bweight equal to the multiple of all non-zero weights 156 particle_weight = eneGenerator->GetWeight()*biasRndm->GetBiasWeight(); 157 // pass it to primary particle 158 particle->SetWeight(particle_weight); 172 159 160 vertex->SetPrimary(particle); 173 161 162 } 163 // now pass the weight to the primary vertex. CANNOT be used here! 164 // vertex->SetWeight(particle_weight); 165 evt->AddPrimaryVertex(vertex); 166 if (verbosityLevel > 1) 167 G4cout << " Primary Vetex generated !" << G4endl; 168 } 169
Note: See TracChangeset
for help on using the changeset viewer.