source: trunk/examples/advanced/brachytherapy/src/BrachyPrimaryGeneratorActionIr.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 4.4 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. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano, S.Guatelli
33//
34//    ********************************************
35//    *                                          *
36//    *    BrachyPrimaryGeneratorActionIr.cc     *
37//    *                                          *
38//    ********************************************
39//
40// $Id: BrachyPrimaryGeneratorActionIr.cc,v 1.11 2006/06/29 15:48:51 gunter Exp $
41// GEANT4 tag $Name: geant4-09-04-beta-01 $
42//
43#include "BrachyPrimaryGeneratorActionIr.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
58BrachyPrimaryGeneratorActionIr::BrachyPrimaryGeneratorActionIr()
59{
60  G4int NumParticles = 1;
61  particleGun = new G4ParticleGun(NumParticles); 
62}
63
64BrachyPrimaryGeneratorActionIr::~BrachyPrimaryGeneratorActionIr()
65{
66  if(particleGun)
67    delete particleGun;
68}
69
70void BrachyPrimaryGeneratorActionIr::GeneratePrimaries(G4Event* anEvent)
71{
72#ifdef G4ANALYSIS_USE
73  BrachyAnalysisManager* analysis = BrachyAnalysisManager::getInstance();
74#endif
75
76  // Define primary particle type
77  G4ParticleTable* pParticleTable = G4ParticleTable::GetParticleTable();
78  G4String ParticleName = "gamma";
79  G4ParticleDefinition* pParticle = pParticleTable -> FindParticle(ParticleName);
80  particleGun -> SetParticleDefinition(pParticle);
81 
82  //  Random generation of gamma source point inside the Iridium core
83  G4double x,y,z;
84  G4double radius = 0.30*mm;
85  do{
86    x = (G4UniformRand()-0.5)*(radius)/0.5;
87    y = (G4UniformRand()-0.5)*(radius)/0.5;
88  }while(x*x+y*y > radius*radius);
89 
90  z = (G4UniformRand()-0.5)*1.75*mm/0.5 -1.975*mm  ;
91
92  G4ThreeVector position(x,y,z);
93  particleGun -> SetParticlePosition(position);
94
95  // Random generation of the impulse direction
96  G4double a,b,c;
97  G4double n;
98  do{
99    a = (G4UniformRand()-0.5)/0.5;
100    b = (G4UniformRand()-0.5)/0.5; 
101    c = (G4UniformRand()-0.5)/0.5;
102    n = a*a+b*b+c*c;
103  }while(n > 1 || n == 0.0);
104  n = std::sqrt(n);
105  a /= n;
106  b /= n;
107  c /= n;
108
109  G4ThreeVector direction(a,b,c);
110  particleGun->SetParticleMomentumDirection(direction);
111
112  // Primary particle energy
113  primaryParticleEnergy = 356.*keV;
114  particleGun->SetParticleEnergy(primaryParticleEnergy);
115 
116  //1D Histogram of primary particle energy ...
117#ifdef G4ANALYSIS_USE
118  analysis -> PrimaryParticleEnergySpectrum(primaryParticleEnergy);
119#endif   
120 
121  // Generate a primary particle
122  particleGun -> GeneratePrimaryVertex(anEvent);
123}
124
Note: See TracBrowser for help on using the repository browser.