Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // 27 // ------------------------------------------- 24 // -------------------------------------------------------------- 28 // GEANT 4 - Underground Dark Matter Detecto 25 // GEANT 4 - Underground Dark Matter Detector Advanced Example 29 // 26 // 30 // For information related to this code c 27 // For information related to this code contact: Alex Howard 31 // e-mail: alexander.howard@cern.ch << 28 // e-mail: a.s.howard@ic.ac.uk 32 // ------------------------------------------- 29 // -------------------------------------------------------------- 33 // Comments 30 // Comments 34 // 31 // 35 // Underground Advanced 32 // Underground Advanced 36 // by A. Howard and H. Araujo 33 // by A. Howard and H. Araujo 37 // (27th November 2001) 34 // (27th November 2001) 38 // 35 // 39 // 36 // 40 // ParticleSource program 37 // ParticleSource program 41 // ------------------------------------------- 38 // -------------------------------------------------------------- 42 ////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////// 43 // This particle source is a shortened version 40 // This particle source is a shortened version of G4GeneralParticleSource by 44 // C Ferguson, F Lei & P Truscott (University 41 // C Ferguson, F Lei & P Truscott (University of Southampton / DERA), with 45 // some minor modifications. 42 // some minor modifications. 46 ////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////// 47 44 48 #include <cmath> << 49 << 50 #include "DMXParticleSource.hh" 45 #include "DMXParticleSource.hh" 51 46 52 #include "G4PhysicalConstants.hh" << 53 #include "G4SystemOfUnits.hh" << 54 #include "G4PrimaryParticle.hh" 47 #include "G4PrimaryParticle.hh" 55 #include "G4Event.hh" 48 #include "G4Event.hh" 56 #include "Randomize.hh" 49 #include "Randomize.hh" >> 50 #include <cmath> 57 #include "G4TransportationManager.hh" 51 #include "G4TransportationManager.hh" 58 #include "G4VPhysicalVolume.hh" 52 #include "G4VPhysicalVolume.hh" 59 #include "G4PhysicalVolumeStore.hh" 53 #include "G4PhysicalVolumeStore.hh" 60 #include "G4ParticleTable.hh" 54 #include "G4ParticleTable.hh" 61 #include "G4ParticleDefinition.hh" 55 #include "G4ParticleDefinition.hh" 62 #include "G4IonTable.hh" 56 #include "G4IonTable.hh" 63 #include "G4Ions.hh" 57 #include "G4Ions.hh" 64 #include "G4TrackingManager.hh" 58 #include "G4TrackingManager.hh" 65 #include "G4Track.hh" 59 #include "G4Track.hh" 66 60 67 61 68 DMXParticleSource::DMXParticleSource() { 62 DMXParticleSource::DMXParticleSource() { 69 63 70 NumberOfParticlesToBeGenerated = 1; 64 NumberOfParticlesToBeGenerated = 1; 71 particle_definition = nullptr; << 65 particle_definition = NULL; 72 G4ThreeVector zero(0., 0., 0.); 66 G4ThreeVector zero(0., 0., 0.); 73 particle_momentum_direction = G4ParticleMome 67 particle_momentum_direction = G4ParticleMomentum(1., 0., 0.); 74 particle_energy = 1.0*MeV; 68 particle_energy = 1.0*MeV; 75 particle_position = zero; 69 particle_position = zero; 76 particle_time = 0.0; 70 particle_time = 0.0; 77 particle_polarization = zero; 71 particle_polarization = zero; 78 particle_charge = 0.0; 72 particle_charge = 0.0; 79 73 80 SourcePosType = "Volume"; 74 SourcePosType = "Volume"; 81 Shape = "NULL"; 75 Shape = "NULL"; 82 halfz = 0.; 76 halfz = 0.; 83 Radius = 0.; 77 Radius = 0.; 84 CentreCoords = zero; 78 CentreCoords = zero; 85 Confine = false; 79 Confine = false; 86 VolName = "NULL"; 80 VolName = "NULL"; 87 81 88 AngDistType = "iso"; 82 AngDistType = "iso"; 89 MinTheta = 0.; 83 MinTheta = 0.; 90 MaxTheta = pi; 84 MaxTheta = pi; 91 MinPhi = 0.; 85 MinPhi = 0.; 92 MaxPhi = twopi; 86 MaxPhi = twopi; 93 87 94 EnergyDisType = "Mono"; 88 EnergyDisType = "Mono"; 95 MonoEnergy = 1*MeV; 89 MonoEnergy = 1*MeV; 96 90 97 verbosityLevel = 0; 91 verbosityLevel = 0; 98 92 99 theMessenger = new DMXParticleSourceMessenge 93 theMessenger = new DMXParticleSourceMessenger(this); 100 gNavigator = G4TransportationManager::GetTra 94 gNavigator = G4TransportationManager::GetTransportationManager() 101 ->GetNavigatorForTracking(); 95 ->GetNavigatorForTracking(); 102 } 96 } 103 97 104 DMXParticleSource::~DMXParticleSource() 98 DMXParticleSource::~DMXParticleSource() 105 { 99 { 106 delete theMessenger; 100 delete theMessenger; 107 } 101 } 108 102 109 void DMXParticleSource::SetPosDisType(G4String 103 void DMXParticleSource::SetPosDisType(G4String PosType) 110 { 104 { 111 SourcePosType = PosType; 105 SourcePosType = PosType; 112 } 106 } 113 107 114 void DMXParticleSource::SetPosDisShape(G4Strin 108 void DMXParticleSource::SetPosDisShape(G4String shapeType) 115 { 109 { 116 Shape = shapeType; 110 Shape = shapeType; 117 } 111 } 118 112 119 void DMXParticleSource::SetCentreCoords(G4Thre 113 void DMXParticleSource::SetCentreCoords(G4ThreeVector coordsOfCentre) 120 { 114 { 121 CentreCoords = coordsOfCentre; 115 CentreCoords = coordsOfCentre; 122 } 116 } 123 117 124 void DMXParticleSource::SetHalfZ(G4double zhal 118 void DMXParticleSource::SetHalfZ(G4double zhalf) 125 { 119 { 126 halfz = zhalf; 120 halfz = zhalf; 127 } 121 } 128 122 129 void DMXParticleSource::SetRadius(G4double rad << 123 void DMXParticleSource::SetRadius(G4double rad) 130 { 124 { 131 Radius = radius; << 125 Radius = rad; 132 } 126 } 133 127 134 void DMXParticleSource::ConfineSourceToVolume( 128 void DMXParticleSource::ConfineSourceToVolume(G4String Vname) 135 { 129 { 136 VolName = Vname; 130 VolName = Vname; 137 if(verbosityLevel == 2) G4cout << VolName << 131 if(verbosityLevel == 2) G4cout << VolName << G4endl; 138 132 139 // checks if selected volume exists 133 // checks if selected volume exists 140 G4VPhysicalVolume *tempPV = nullptr; << 134 G4VPhysicalVolume *tempPV = NULL; 141 G4PhysicalVolumeStore *PVStore = nullptr; << 135 G4PhysicalVolumeStore *PVStore = 0; 142 G4String theRequiredVolumeName = VolName; 136 G4String theRequiredVolumeName = VolName; 143 PVStore = G4PhysicalVolumeStore::GetInstance 137 PVStore = G4PhysicalVolumeStore::GetInstance(); >> 138 G4int i = 0; 144 G4bool found = false; 139 G4bool found = false; 145 if(verbosityLevel == 2) G4cout << PVStore->s 140 if(verbosityLevel == 2) G4cout << PVStore->size() << G4endl; 146 141 147 tempPV = PVStore->GetVolume(theRequiredVolum << 142 // recasting required since PVStore->size() is actually a signed int... 148 if (tempPV != nullptr) { found = true; } << 143 while (!found && i<(G4int)PVStore->size()) >> 144 { >> 145 tempPV = (*PVStore)[i]; >> 146 found = tempPV->GetName() == theRequiredVolumeName; >> 147 if(verbosityLevel == 2) >> 148 G4cout << i << " " << " " << tempPV->GetName() >> 149 << " " << theRequiredVolumeName << " " << found << G4endl; >> 150 if (!found) >> 151 {i++;} >> 152 } 149 153 150 // found = true then the volume exists else 154 // found = true then the volume exists else it doesnt. 151 if(found == true) { 155 if(found == true) { 152 if(verbosityLevel >= 1) 156 if(verbosityLevel >= 1) 153 G4cout << "Volume " << VolName << " exis 157 G4cout << "Volume " << VolName << " exists" << G4endl; 154 Confine = true; 158 Confine = true; 155 } 159 } 156 else if(VolName=="NULL") 160 else if(VolName=="NULL") 157 Confine = false; 161 Confine = false; 158 else { 162 else { 159 G4cout << " **** Error: Volume does not ex 163 G4cout << " **** Error: Volume does not exist **** " << G4endl; 160 G4cout << " Ignoring confine condition" << 164 G4cout << " Ignoring confine condition" << G4endl; 161 VolName = "NULL"; 165 VolName = "NULL"; 162 Confine = false; 166 Confine = false; 163 } 167 } >> 168 164 } 169 } 165 170 >> 171 166 void DMXParticleSource::SetAngDistType(G4Strin 172 void DMXParticleSource::SetAngDistType(G4String atype) 167 { 173 { 168 AngDistType = atype; 174 AngDistType = atype; 169 } 175 } 170 176 >> 177 171 void DMXParticleSource::GeneratePointSource() 178 void DMXParticleSource::GeneratePointSource() 172 { 179 { 173 // Generates Points given the point source. 180 // Generates Points given the point source. 174 if(SourcePosType == "Point") 181 if(SourcePosType == "Point") 175 particle_position = CentreCoords; 182 particle_position = CentreCoords; 176 else 183 else 177 if(verbosityLevel >= 1) 184 if(verbosityLevel >= 1) 178 G4cout << "Error SourcePosType is not se 185 G4cout << "Error SourcePosType is not set to Point" << G4endl; 179 } 186 } 180 187 >> 188 181 void DMXParticleSource::GeneratePointsInVolume 189 void DMXParticleSource::GeneratePointsInVolume() 182 { 190 { 183 G4ThreeVector RandPos; 191 G4ThreeVector RandPos; 184 G4double x=0., y=0., z=0.; 192 G4double x=0., y=0., z=0.; 185 193 186 if(SourcePosType != "Volume" && verbosityLev 194 if(SourcePosType != "Volume" && verbosityLevel >= 1) 187 G4cout << "Error SourcePosType not Volume" 195 G4cout << "Error SourcePosType not Volume" << G4endl; 188 196 189 if(Shape == "Sphere") { 197 if(Shape == "Sphere") { 190 x = Radius*2.; 198 x = Radius*2.; 191 y = Radius*2.; 199 y = Radius*2.; 192 z = Radius*2.; 200 z = Radius*2.; 193 while(((x*x)+(y*y)+(z*z)) > (Radius*Radius 201 while(((x*x)+(y*y)+(z*z)) > (Radius*Radius)) { 194 x = G4UniformRand(); 202 x = G4UniformRand(); 195 y = G4UniformRand(); 203 y = G4UniformRand(); 196 z = G4UniformRand(); 204 z = G4UniformRand(); 197 205 198 x = (x*2.*Radius) - Radius; 206 x = (x*2.*Radius) - Radius; 199 y = (y*2.*Radius) - Radius; 207 y = (y*2.*Radius) - Radius; 200 z = (z*2.*Radius) - Radius; 208 z = (z*2.*Radius) - Radius; 201 } 209 } 202 } 210 } 203 211 204 else if(Shape == "Cylinder") { 212 else if(Shape == "Cylinder") { 205 x = Radius*2.; 213 x = Radius*2.; 206 y = Radius*2.; 214 y = Radius*2.; 207 while(((x*x)+(y*y)) > (Radius*Radius)) { 215 while(((x*x)+(y*y)) > (Radius*Radius)) { 208 x = G4UniformRand(); 216 x = G4UniformRand(); 209 y = G4UniformRand(); 217 y = G4UniformRand(); 210 z = G4UniformRand(); 218 z = G4UniformRand(); 211 x = (x*2.*Radius) - Radius; 219 x = (x*2.*Radius) - Radius; 212 y = (y*2.*Radius) - Radius; 220 y = (y*2.*Radius) - Radius; 213 z = (z*2.*halfz) - halfz; 221 z = (z*2.*halfz) - halfz; 214 } 222 } 215 } 223 } 216 224 217 else 225 else 218 G4cout << "Error: Volume Shape Does Not Ex 226 G4cout << "Error: Volume Shape Does Not Exist" << G4endl; 219 227 220 RandPos.setX(x); 228 RandPos.setX(x); 221 RandPos.setY(y); 229 RandPos.setY(y); 222 RandPos.setZ(z); 230 RandPos.setZ(z); 223 particle_position = CentreCoords + RandPos; 231 particle_position = CentreCoords + RandPos; 224 232 225 } 233 } 226 234 >> 235 227 G4bool DMXParticleSource::IsSourceConfined() 236 G4bool DMXParticleSource::IsSourceConfined() 228 { 237 { 229 238 230 // Method to check point is within the volum 239 // Method to check point is within the volume specified 231 if(Confine == false) 240 if(Confine == false) 232 G4cout << "Error: Confine is false" << G4e 241 G4cout << "Error: Confine is false" << G4endl; 233 G4ThreeVector null_vec(0.,0.,0.); << 242 G4ThreeVector null(0.,0.,0.); 234 G4ThreeVector *ptr = &null_vec; << 243 G4ThreeVector *ptr; >> 244 ptr = &null; 235 245 236 // Check particle_position is within VolName 246 // Check particle_position is within VolName 237 G4VPhysicalVolume *theVolume; 247 G4VPhysicalVolume *theVolume; 238 theVolume=gNavigator->LocateGlobalPointAndSe 248 theVolume=gNavigator->LocateGlobalPointAndSetup(particle_position,ptr,true); 239 G4String theVolName = theVolume->GetName(); 249 G4String theVolName = theVolume->GetName(); 240 if(theVolName == VolName) { 250 if(theVolName == VolName) { 241 if(verbosityLevel >= 1) 251 if(verbosityLevel >= 1) 242 G4cout << "Particle is in volume " << Vo 252 G4cout << "Particle is in volume " << VolName << G4endl; 243 return(true); 253 return(true); 244 } 254 } 245 else 255 else 246 return(false); 256 return(false); 247 } 257 } 248 258 >> 259 249 void DMXParticleSource::SetParticleMomentumDir 260 void DMXParticleSource::SetParticleMomentumDirection 250 (G4ParticleMomentum aDirection) { 261 (G4ParticleMomentum aDirection) { 251 262 252 particle_momentum_direction = aDirection.un 263 particle_momentum_direction = aDirection.unit(); 253 } 264 } 254 265 >> 266 255 void DMXParticleSource::GenerateIsotropicFlux( 267 void DMXParticleSource::GenerateIsotropicFlux() 256 { 268 { 257 269 258 G4double rndm, rndm2; 270 G4double rndm, rndm2; 259 G4double px, py, pz; 271 G4double px, py, pz; 260 272 261 G4double sintheta, sinphi, costheta, cosphi; 273 G4double sintheta, sinphi, costheta, cosphi; 262 rndm = G4UniformRand(); 274 rndm = G4UniformRand(); 263 costheta = std::cos(MinTheta) - rndm * (std: << 275 costheta = std::cos(MinTheta) - rndm * (std::cos(MinTheta) - std::cos(MaxTheta)); 264 - std::cos(Max << 265 sintheta = std::sqrt(1. - costheta*costheta) 276 sintheta = std::sqrt(1. - costheta*costheta); 266 277 267 rndm2 = G4UniformRand(); 278 rndm2 = G4UniformRand(); 268 Phi = MinPhi + (MaxPhi - MinPhi) * rndm2; 279 Phi = MinPhi + (MaxPhi - MinPhi) * rndm2; 269 sinphi = std::sin(Phi); 280 sinphi = std::sin(Phi); 270 cosphi = std::cos(Phi); 281 cosphi = std::cos(Phi); 271 282 272 px = -sintheta * cosphi; 283 px = -sintheta * cosphi; 273 py = -sintheta * sinphi; 284 py = -sintheta * sinphi; 274 pz = -costheta; 285 pz = -costheta; 275 286 276 G4double ResMag = std::sqrt((px*px) + (py*py 287 G4double ResMag = std::sqrt((px*px) + (py*py) + (pz*pz)); 277 px = px/ResMag; 288 px = px/ResMag; 278 py = py/ResMag; 289 py = py/ResMag; 279 pz = pz/ResMag; 290 pz = pz/ResMag; 280 291 281 particle_momentum_direction.setX(px); 292 particle_momentum_direction.setX(px); 282 particle_momentum_direction.setY(py); 293 particle_momentum_direction.setY(py); 283 particle_momentum_direction.setZ(pz); 294 particle_momentum_direction.setZ(pz); 284 295 285 // particle_momentum_direction now holds uni 296 // particle_momentum_direction now holds unit momentum vector. 286 if(verbosityLevel >= 2) 297 if(verbosityLevel >= 2) 287 G4cout << "Generating isotropic vector: " << 298 G4cout << "Generating isotropic vector: " << particle_momentum_direction << G4endl; 288 << particle_momentum_direction << G << 289 } 299 } 290 300 >> 301 291 void DMXParticleSource::SetEnergyDisType(G4Str 302 void DMXParticleSource::SetEnergyDisType(G4String DisType) 292 { 303 { 293 EnergyDisType = DisType; 304 EnergyDisType = DisType; 294 } 305 } 295 306 296 void DMXParticleSource::SetMonoEnergy(G4double 307 void DMXParticleSource::SetMonoEnergy(G4double menergy) 297 { 308 { 298 MonoEnergy = menergy; 309 MonoEnergy = menergy; 299 } 310 } 300 311 301 void DMXParticleSource::GenerateMonoEnergetic( 312 void DMXParticleSource::GenerateMonoEnergetic() 302 { 313 { 303 particle_energy = MonoEnergy; 314 particle_energy = MonoEnergy; 304 } 315 } 305 316 >> 317 306 void DMXParticleSource::SetVerbosity(int vL) 318 void DMXParticleSource::SetVerbosity(int vL) 307 { 319 { 308 verbosityLevel = vL; 320 verbosityLevel = vL; 309 G4cout << "Verbosity Set to: " << verbosityL 321 G4cout << "Verbosity Set to: " << verbosityLevel << G4endl; 310 } 322 } 311 323 312 void DMXParticleSource::SetParticleDefinition 324 void DMXParticleSource::SetParticleDefinition 313 (G4ParticleDefinition* aParticleDefinition) 325 (G4ParticleDefinition* aParticleDefinition) 314 { 326 { 315 particle_definition = aParticleDefinition; 327 particle_definition = aParticleDefinition; 316 particle_charge = particle_definition->GetPD 328 particle_charge = particle_definition->GetPDGCharge(); 317 } 329 } 318 330 >> 331 319 void DMXParticleSource::GeneratePrimaryVertex( 332 void DMXParticleSource::GeneratePrimaryVertex(G4Event *evt) 320 { 333 { 321 334 322 if(particle_definition==nullptr) { << 335 if(particle_definition==NULL) { 323 G4cout << "No particle has been defined!" 336 G4cout << "No particle has been defined!" << G4endl; 324 return; 337 return; 325 } 338 } 326 339 327 // Position 340 // Position 328 G4bool srcconf = false; 341 G4bool srcconf = false; 329 G4int LoopCount = 0; 342 G4int LoopCount = 0; 330 343 331 while(srcconf == false) { 344 while(srcconf == false) { 332 if(SourcePosType == "Point") 345 if(SourcePosType == "Point") 333 GeneratePointSource(); 346 GeneratePointSource(); 334 else if(SourcePosType == "Volume") 347 else if(SourcePosType == "Volume") 335 GeneratePointsInVolume(); 348 GeneratePointsInVolume(); 336 else { 349 else { 337 G4cout << "Error: SourcePosType undefine 350 G4cout << "Error: SourcePosType undefined" << G4endl; 338 G4cout << "Generating point source" << G 351 G4cout << "Generating point source" << G4endl; 339 GeneratePointSource(); 352 GeneratePointSource(); 340 } 353 } 341 if(Confine == true) { 354 if(Confine == true) { 342 srcconf = IsSourceConfined(); 355 srcconf = IsSourceConfined(); 343 // if source in confined srcconf = true 356 // if source in confined srcconf = true terminating the loop 344 // if source isnt confined srcconf = fal 357 // if source isnt confined srcconf = false and loop continues 345 } 358 } 346 else if(Confine == false) 359 else if(Confine == false) 347 srcconf = true; // terminate loop 360 srcconf = true; // terminate loop 348 361 349 ++LoopCount; << 362 LoopCount++; 350 if(LoopCount == 100000) { 363 if(LoopCount == 100000) { 351 G4cout << "***************************** 364 G4cout << "*************************************" << G4endl; 352 G4cout << "LoopCount = 100000" << G4en 365 G4cout << "LoopCount = 100000" << G4endl; 353 G4cout << "Either the source distribut 366 G4cout << "Either the source distribution >> confinement" << G4endl; 354 G4cout << "or any confining volume may 367 G4cout << "or any confining volume may not overlap with" << G4endl; 355 G4cout << "the source distribution or 368 G4cout << "the source distribution or any confining volumes" << G4endl; 356 G4cout << "may not exist"<< G4endl; 369 G4cout << "may not exist"<< G4endl; 357 G4cout << "If you have set confine the 370 G4cout << "If you have set confine then this will be ignored" <<G4endl; 358 G4cout << "for this event." << G4endl; 371 G4cout << "for this event." << G4endl; 359 G4cout << "*************************** 372 G4cout << "*************************************" << G4endl; 360 srcconf = true; //Avoids an infinite l 373 srcconf = true; //Avoids an infinite loop 361 } 374 } 362 } 375 } 363 376 364 // Angular stuff 377 // Angular stuff 365 if(AngDistType == "iso") 378 if(AngDistType == "iso") 366 GenerateIsotropicFlux(); 379 GenerateIsotropicFlux(); 367 else if(AngDistType == "direction") 380 else if(AngDistType == "direction") 368 SetParticleMomentumDirection(particle_mome 381 SetParticleMomentumDirection(particle_momentum_direction); 369 else 382 else 370 G4cout << "Error: AngDistType has unusual 383 G4cout << "Error: AngDistType has unusual value" << G4endl; 371 // Energy stuff 384 // Energy stuff 372 if(EnergyDisType == "Mono") 385 if(EnergyDisType == "Mono") 373 GenerateMonoEnergetic(); 386 GenerateMonoEnergetic(); 374 else 387 else 375 G4cout << "Error: EnergyDisType has unusua 388 G4cout << "Error: EnergyDisType has unusual value" << G4endl; 376 389 377 // create a new vertex 390 // create a new vertex 378 G4PrimaryVertex* vertex = 391 G4PrimaryVertex* vertex = 379 new G4PrimaryVertex(particle_position,part 392 new G4PrimaryVertex(particle_position,particle_time); 380 393 381 if(verbosityLevel >= 2) 394 if(verbosityLevel >= 2) 382 G4cout << "Creating primaries and assignin 395 G4cout << "Creating primaries and assigning to vertex" << G4endl; 383 // create new primaries and set them to the 396 // create new primaries and set them to the vertex 384 G4double mass = particle_definition->GetPDG 397 G4double mass = particle_definition->GetPDGMass(); 385 G4double energy = particle_energy + mass; 398 G4double energy = particle_energy + mass; 386 G4double pmom = std::sqrt(energy*energy-mass 399 G4double pmom = std::sqrt(energy*energy-mass*mass); 387 G4double px = pmom*particle_momentum_directi 400 G4double px = pmom*particle_momentum_direction.x(); 388 G4double py = pmom*particle_momentum_directi 401 G4double py = pmom*particle_momentum_direction.y(); 389 G4double pz = pmom*particle_momentum_directi 402 G4double pz = pmom*particle_momentum_direction.z(); 390 403 391 if(verbosityLevel >= 1){ 404 if(verbosityLevel >= 1){ 392 G4cout << "Particle name: " 405 G4cout << "Particle name: " 393 << particle_definition->GetParticle << 406 << particle_definition->GetParticleName() << G4endl; 394 G4cout << " Energy: "<<particle_ener 407 G4cout << " Energy: "<<particle_energy << G4endl; 395 G4cout << " Position: "<<particle_posi 408 G4cout << " Position: "<<particle_position<< G4endl; 396 G4cout << " Direction: "<<particle_mome 409 G4cout << " Direction: "<<particle_momentum_direction << G4endl; 397 G4cout << " NumberOfParticlesToBeGenerated 410 G4cout << " NumberOfParticlesToBeGenerated: " 398 << NumberOfParticlesToBeGenerated < << 411 << NumberOfParticlesToBeGenerated << G4endl; 399 } 412 } 400 413 401 for( G4int i=0; i<NumberOfParticlesToBeGener << 414 >> 415 for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ ) { 402 G4PrimaryParticle* particle = 416 G4PrimaryParticle* particle = 403 new G4PrimaryParticle(particle_definitio 417 new G4PrimaryParticle(particle_definition,px,py,pz); 404 particle->SetMass( mass ); 418 particle->SetMass( mass ); 405 particle->SetCharge( particle_charge ); 419 particle->SetCharge( particle_charge ); 406 particle->SetPolarization(particle_polariz 420 particle->SetPolarization(particle_polarization.x(), 407 particle_polariz << 421 particle_polarization.y(), 408 particle_polariz << 422 particle_polarization.z()); 409 vertex->SetPrimary( particle ); 423 vertex->SetPrimary( particle ); 410 } 424 } 411 evt->AddPrimaryVertex( vertex ); 425 evt->AddPrimaryVertex( vertex ); 412 if(verbosityLevel > 1) 426 if(verbosityLevel > 1) 413 G4cout << " Primary Vetex generated "<< G4 427 G4cout << " Primary Vetex generated "<< G4endl; 414 } 428 } >> 429 >> 430 >> 431 >> 432 415 433