source: trunk/examples/advanced/brachytherapy/src/BrachyPrimaryGeneratorActionI.cc@ 1282

Last change on this file since 1282 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

File size: 5.0 KB
Line 
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:
32// S.Guatelli
33//
34// ********************************************
35// * *
36// * BrachyPrimaryGeneratorActionI.cc *
37// * *
38// ********************************************
39//
40// $Id: BrachyPrimaryGeneratorActionI.cc,v 1.10 2006/06/29 15:48:48 gunter Exp $
41// GEANT4 tag $Name: geant4-09-03-cand-01 $
42//
43#include "BrachyPrimaryGeneratorActionI.hh"
44
45#ifdef G4ANALYSIS_USE
46#include "BrachyAnalysisManager.hh"
47#endif
48
49#include "globals.hh"
50#include "G4ParticleTable.hh"
51#include "Randomize.hh"
52#include "G4Event.hh"
53#include "G4ParticleGun.hh"
54//#include "G4IonTable.hh"
55#include "G4UImanager.hh"
56#include "G4RunManager.hh"
57
58BrachyPrimaryGeneratorActionI::BrachyPrimaryGeneratorActionI()
59{
60 G4int numberParticles = 1;
61
62 particleGun = new G4ParticleGun(numberParticles);
63
64 // Gamma energy spectrum ...
65 // Fill a vector with the energy probabilities
66 energySpectrum.push_back(0.783913);
67 energySpectrum.push_back(0.170416);
68 energySpectrum.push_back(0.045671);
69}
70
71BrachyPrimaryGeneratorActionI::~BrachyPrimaryGeneratorActionI()
72{
73 if(particleGun)
74 delete particleGun;
75}
76
77void BrachyPrimaryGeneratorActionI::GeneratePrimaries(G4Event* anEvent)
78{
79#ifdef G4ANALYSIS_USE
80 BrachyAnalysisManager* analysis = BrachyAnalysisManager::getInstance();
81#endif
82
83 // Define the primary particle type
84 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
85 G4String ParticleName = "gamma";
86 G4ParticleDefinition* particle = particleTable -> FindParticle(ParticleName);
87
88 particleGun -> SetParticleDefinition(particle);
89
90 // Random generation of gamma source point inside the Iodium core ...
91 G4double x,y,z;
92 G4double radiuMax = 0.30*mm;
93 G4double radiusMin = 0.085*mm;
94
95 do{
96 x = (G4UniformRand()-0.5)*(radiuMax)/0.5;
97 y = (G4UniformRand()-0.5)*(radiuMax)/0.5;
98 }while(((x*x+y*y )> (radiuMax*radiuMax))||((x*x+y*y)<(radiusMin*radiusMin)));
99
100 z = (G4UniformRand()-0.5)*1.75*mm/0.5 ;
101
102 G4ThreeVector position(x,y,z);
103 particleGun -> SetParticlePosition(position);
104
105 // Random generation of the impulse direction of primary particles ...
106 G4double a,b,c;
107 G4double n;
108 do{
109 a = (G4UniformRand()-0.5)/0.5;
110 b = (G4UniformRand()-0.5)/0.5;
111 c = (G4UniformRand()-0.5)/0.5;
112 n = a*a+b*b+c*c;
113 }while(n > 1 || n == 0.0);
114 n = std::sqrt(n);
115 a /= n;
116 b /= n;
117 c /= n;
118
119 G4ThreeVector direction(a,b,c);
120 particleGun -> SetParticleMomentumDirection(direction);
121
122 // Generate the primary particles with a defined energy spectrum
123 G4double random = G4UniformRand();
124 G4double sum = 0;
125 G4int i = 0;
126 while(sum<random){sum+=energySpectrum[i];
127 i++;}
128
129 // energy spectrum
130 if(i==1){primaryParticleEnergy = 27.4*keV;}
131 else{
132 if(i==2){primaryParticleEnergy = 31.4*keV;}
133 else {primaryParticleEnergy = 35.5*keV;}}
134
135 particleGun -> SetParticleEnergy(primaryParticleEnergy);
136
137 // Fill 1D histogram with gamma energy spectrum ...
138#ifdef G4ANALYSIS_USE
139 analysis -> PrimaryParticleEnergySpectrum(primaryParticleEnergy);
140#endif
141
142 // generate primary particle
143 particleGun->GeneratePrimaryVertex(anEvent);
144}
145
146G4double BrachyPrimaryGeneratorActionI::GetEnergy()
147{
148 return primaryParticleEnergy;
149}
150
Note: See TracBrowser for help on using the repository browser.