source: trunk/examples/extended/parallel/ExDiane/src/BrachyPrimaryGeneratorActionI.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

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