source: trunk/examples/advanced/medical_linac/src/MedLinacPrimaryGeneratorAction.cc@ 1280

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

update

File size: 4.4 KB
RevLine 
[807]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// $Id: MedLinacPrimaryGeneratorAction.cc,v 1.8 2006/06/29 16:04:43 gunter Exp $
27//
28//
29// Code developed by: M. Piergentili
30//
31#include "MedLinacPrimaryGeneratorAction.hh"
32#include "MedLinacPrimaryGeneratorMessenger.hh"
33
34#ifdef G4ANALYSIS_USE
35#include "MedLinacAnalysisManager.hh"
36#endif
37#include "MedLinacDetectorConstruction.hh"
38#include "G4Event.hh"
39#include "G4ParticleGun.hh"
40#include "G4ParticleTable.hh"
41#include "G4ParticleDefinition.hh"
42#include "globals.hh"
43#include "Randomize.hh"
44#include "G4RunManager.hh"
45#include "G4UImanager.hh"
46#include "G4IonTable.hh"
47
48MedLinacPrimaryGeneratorAction::MedLinacPrimaryGeneratorAction()
49 :pEnergy(99.0*MeV),sigma(12.7*MeV)
50{
51 G4int n_particle = 1;
52 particleGun = new G4ParticleGun(n_particle);
53
54//create a messenger for this class
55 gunMessenger = new MedLinacPrimaryGeneratorMessenger(this);
56
57 // default particle kinematic
58
59 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
60 G4String particleName;
61
62 particleGun->SetParticleDefinition(particleTable->FindParticle(particleName="e-"));
63 particleGun->SetParticleEnergy(pEnergy);
64
65 //**********************************************************************
66 //**********************************************************************
67 particleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 123.0*cm));
68 //particleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 160.09855*cm));
69 //**********************************************************************
70 //**********************************************************************
71
72}
73
74MedLinacPrimaryGeneratorAction::~MedLinacPrimaryGeneratorAction()
75{
76 delete particleGun;
77 delete gunMessenger;
78}
79
80void MedLinacPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
81{
82 G4double energy;
83
84 //#ifdef G4ANALYSIS_USE
85 //MedLinacAnalysisManager* analysis = MedLinacAnalysisManager::getInstance();
86 //#endif
87
88 //BeamLine
89 //G4ThreeVector v(0.0,0.0,-1.0);
90 //particleGun->SetParticleMomentumDirection(v);
91
92
93 //uniform distribution in solid angle (-1<cosTheta<-0.9999; 0<phi<2pi)
94 //
95
96 //G4double cosTheta = -0.0001*G4UniformRand()-0.9999;
97 G4double cosTheta = CLHEP::RandGauss::shoot(-1.,0.00003);
98 G4double phi = twopi * G4UniformRand();
99
100 G4double sinTheta = std::sqrt(1. - cosTheta*cosTheta);
101 G4double ux = sinTheta*std::cos(phi);
102 G4double uy = sinTheta*std::sin(phi);
103 G4double uz = cosTheta;
104
105 particleGun->SetParticleMomentumDirection(G4ThreeVector(ux,uy,uz));
106
107 energy=pEnergy;
108 energy = CLHEP::RandGauss::shoot(pEnergy,sigma);
109 particleGun->SetParticleEnergy(energy);
110
111 //G4cout <<"the energy of the primaries is " << energy <<" "<<"MeV"<< G4endl;
112 //G4cout <<"the sigma of the energy is " << sigma <<" "<<"MeV"<< G4endl;
113
114 particleGun->GeneratePrimaryVertex(anEvent);
115}
116
117
118
Note: See TracBrowser for help on using the repository browser.