1 |
cafagna |
1.1 |
|
2 |
|
|
#include "PrimaryGeneratorMessenger.hh" |
3 |
|
|
#include "PrimaryGeneratorAction.hh" |
4 |
|
|
#include "DetectorConstruction.hh" |
5 |
|
|
#include "G4Event.hh" |
6 |
|
|
#include "G4ParticleGun.hh" |
7 |
|
|
#include "G4ParticleTable.hh" |
8 |
|
|
#include "G4ParticleDefinition.hh" |
9 |
|
|
#include "globals.hh" |
10 |
|
|
#include "Randomize.hh" |
11 |
|
|
|
12 |
|
|
PrimaryGeneratorAction::PrimaryGeneratorAction( |
13 |
|
|
DetectorConstruction* DC) |
14 |
|
|
:Detector(DC),rndmFlag("off") |
15 |
|
|
{ |
16 |
|
|
G4int n_particle = 1; |
17 |
|
|
particleGun = new G4ParticleGun(n_particle); |
18 |
|
|
//create a messenger for this class |
19 |
|
|
gunMessenger = new PrimaryGeneratorMessenger(this); |
20 |
|
|
// default particle |
21 |
|
|
|
22 |
|
|
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
23 |
|
|
G4String particleName; |
24 |
|
|
G4ParticleDefinition* particle |
25 |
|
|
= particleTable->FindParticle(particleName="proton"); |
26 |
|
|
particleGun->SetParticleDefinition(particle); |
27 |
|
|
particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); |
28 |
|
|
particleGun->SetParticleEnergy(20.*GeV); |
29 |
|
|
G4double position = -(Detector->GetWorld_Z())/2.; |
30 |
|
|
particleGun->SetParticlePosition(G4ThreeVector(0.*cm, 0.*cm, position)); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
PrimaryGeneratorAction::~PrimaryGeneratorAction() |
34 |
|
|
{ |
35 |
|
|
delete particleGun; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
39 |
|
|
{ |
40 |
|
|
if (rndmFlag == "on"){ |
41 |
|
|
|
42 |
|
|
G4double z = Detector->GetWorld_XY()*(G4UniformRand()-0.5); |
43 |
|
|
G4double y = Detector->GetWorld_XY()*(G4UniformRand()-0.5); |
44 |
|
|
G4double x = Detector->GetWorld_Z()/2.; |
45 |
|
|
particleGun->SetParticlePosition(G4ThreeVector(x,y,z)); |
46 |
|
|
|
47 |
|
|
//k G4int i=0; |
48 |
|
|
//k G4double theta=pi/10*(i+G4UniformRand()); |
49 |
|
|
G4double phi=G4UniformRand()*twopi; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
G4double theta; |
55 |
|
|
do |
56 |
|
|
theta = G4UniformRand() * halfpi; |
57 |
|
|
while( G4UniformRand() > 2.*cos(theta)*sin(theta)); |
58 |
|
|
|
59 |
|
|
G4double px=sin(theta)*sin(phi); |
60 |
|
|
|
61 |
|
|
G4double py=sin(theta)*cos(phi); |
62 |
|
|
|
63 |
|
|
G4double pz=cos(theta); |
64 |
|
|
|
65 |
|
|
particleGun->SetParticleMomentumDirection(G4ThreeVector(-fabs(pz),py,px)); |
66 |
|
|
|
67 |
|
|
// G4cout<<"y0 "<<y0<< " z0 "<<z0<<" Theta " << theta<<" Phi "<<phi<<G4endl; |
68 |
|
|
|
69 |
|
|
// G4double E=pow(6.0255959E-6 -5.91594E-6*G4UniformRand(),-0.5747712644); |
70 |
|
|
// G4double E=pow(0.000316228 -0.000310604*G4UniformRand(),-0.571429); |
71 |
|
|
|
72 |
|
|
// particleGun->SetParticleEnergy(E*GeV); |
73 |
|
|
// G4cout<<E<<"GeV"<<G4endl; |
74 |
|
|
|
75 |
|
|
//l particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); |
76 |
|
|
} |
77 |
|
|
particleGun->GeneratePrimaryVertex(anEvent); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
// 2005 by G.I.Vasilyev |