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 | // -------------------------------------------------------------- |
---|
28 | // GEANT 4 - Brachytherapy example |
---|
29 | // -------------------------------------------------------------- |
---|
30 | // |
---|
31 | // Code developed by: S.Guatelli |
---|
32 | // |
---|
33 | // ******************************************** |
---|
34 | // * * |
---|
35 | // * BrachyPrimaryGeneratorActionIr.cc * |
---|
36 | // * * |
---|
37 | // ******************************************** |
---|
38 | // |
---|
39 | // $Id: BrachyPrimaryGeneratorActionIr.cc,v 1.4 2006/06/29 17:33:36 gunter Exp $ |
---|
40 | // GEANT4 tag $Name: $ |
---|
41 | // |
---|
42 | #include "BrachyPrimaryGeneratorActionIr.hh" |
---|
43 | |
---|
44 | #ifdef G4ANALYSIS_USE |
---|
45 | #include "BrachyAnalysisManager.hh" |
---|
46 | #endif |
---|
47 | |
---|
48 | #include "globals.hh" |
---|
49 | #include "G4ParticleTable.hh" |
---|
50 | #include "Randomize.hh" |
---|
51 | #include "G4Event.hh" |
---|
52 | #include "G4ParticleGun.hh" |
---|
53 | #include "G4IonTable.hh" |
---|
54 | #include "G4UImanager.hh" |
---|
55 | #include "G4RunManager.hh" |
---|
56 | |
---|
57 | BrachyPrimaryGeneratorActionIr::BrachyPrimaryGeneratorActionIr() |
---|
58 | { |
---|
59 | G4int NumParticles = 1; |
---|
60 | particleGun = new G4ParticleGun(NumParticles); |
---|
61 | } |
---|
62 | |
---|
63 | BrachyPrimaryGeneratorActionIr::~BrachyPrimaryGeneratorActionIr() |
---|
64 | { |
---|
65 | if(particleGun) |
---|
66 | delete particleGun; |
---|
67 | } |
---|
68 | |
---|
69 | void BrachyPrimaryGeneratorActionIr::GeneratePrimaries(G4Event* anEvent) |
---|
70 | { |
---|
71 | #ifdef G4ANALYSIS_USE |
---|
72 | BrachyAnalysisManager* analysis = BrachyAnalysisManager::getInstance(); |
---|
73 | #endif |
---|
74 | |
---|
75 | G4ParticleTable* pParticleTable = G4ParticleTable::GetParticleTable(); |
---|
76 | G4String ParticleName = "gamma"; |
---|
77 | G4ParticleDefinition* pParticle = pParticleTable->FindParticle(ParticleName); |
---|
78 | particleGun->SetParticleDefinition(pParticle); |
---|
79 | |
---|
80 | // Random generation of gamma source point inside the Iodium core |
---|
81 | G4double x,y,z; |
---|
82 | G4double radius = 0.30*mm; |
---|
83 | do{ |
---|
84 | x = (G4UniformRand()-0.5)*(radius)/0.5; |
---|
85 | y = (G4UniformRand()-0.5)*(radius)/0.5; |
---|
86 | }while(x*x+y*y > radius*radius); |
---|
87 | |
---|
88 | z = (G4UniformRand()-0.5)*1.75*mm/0.5 -1.975*mm ; |
---|
89 | |
---|
90 | G4ThreeVector position(x,y,z); |
---|
91 | particleGun->SetParticlePosition(position); |
---|
92 | // Random generation of the impulse direction |
---|
93 | G4double a,b,c; |
---|
94 | G4double n; |
---|
95 | do{ |
---|
96 | a = (G4UniformRand()-0.5)/0.5; |
---|
97 | b = (G4UniformRand()-0.5)/0.5; |
---|
98 | c = (G4UniformRand()-0.5)/0.5; |
---|
99 | n = a*a+b*b+c*c; |
---|
100 | }while(n > 1 || n == 0.0); |
---|
101 | n = std::sqrt(n); |
---|
102 | a /= n; |
---|
103 | b /= n; |
---|
104 | c /= n; |
---|
105 | |
---|
106 | G4ThreeVector direction(a,b,c); |
---|
107 | particleGun -> SetParticleMomentumDirection(direction); |
---|
108 | |
---|
109 | primaryParticleEnergy = 356*keV; |
---|
110 | particleGun -> SetParticleEnergy(primaryParticleEnergy); |
---|
111 | |
---|
112 | //1D Histogram of primary particle energy ... |
---|
113 | #ifdef G4ANALYSIS_USE |
---|
114 | analysis -> PrimaryParticleEnergySpectrum(primaryParticleEnergy); |
---|
115 | #endif |
---|
116 | particleGun -> GeneratePrimaryVertex(anEvent); |
---|
117 | } |
---|
118 | |
---|