1 | #include "ELYSE/PrimaryGeneratorAction.hh"
|
---|
2 |
|
---|
3 | //Geant4
|
---|
4 | #include "G4Event.hh"
|
---|
5 | #include "G4ParticleGun.hh"
|
---|
6 | #include "G4ParticleTable.hh"
|
---|
7 | #include "G4ParticleDefinition.hh"
|
---|
8 | #include "G4ThreeVector.hh"
|
---|
9 | #include "globals.hh"
|
---|
10 | #include "Randomize.hh"
|
---|
11 | #include "G4Navigator.hh"
|
---|
12 | #include "G4TransportationManager.hh"
|
---|
13 | #include "G4ProcessManager.hh"
|
---|
14 |
|
---|
15 | //ELYSE
|
---|
16 | #include "ELYSE/DetectorConstruction.hh"
|
---|
17 | #include "ELYSE/PrimaryGeneratorMessenger.hh"
|
---|
18 |
|
---|
19 |
|
---|
20 | ELYSE::PrimaryGeneratorAction::PrimaryGeneratorAction() {
|
---|
21 | // Initialize to zero
|
---|
22 | vtx = G4ThreeVector(0.,0.,0.);
|
---|
23 | beamenergy = 0.;
|
---|
24 | beamdir = G4ThreeVector(0.,0.,0.);
|
---|
25 |
|
---|
26 |
|
---|
27 | //---Set defaults. Do once at beginning of session.
|
---|
28 |
|
---|
29 | G4int n_particle = 1;
|
---|
30 | particleGun = new G4ParticleGun(n_particle);
|
---|
31 |
|
---|
32 | particleTable = G4ParticleTable::GetParticleTable();
|
---|
33 | particleGun->SetParticleDefinition(particleTable->FindParticle("e-"));
|
---|
34 |
|
---|
35 |
|
---|
36 | particleGun->SetParticleTime(0.0*ns);
|
---|
37 | particleGun->SetParticlePosition(G4ThreeVector(0.0*cm,0.0*cm,0.0*cm));
|
---|
38 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
|
---|
39 | particleGun->SetParticleEnergy(8.2*MeV);
|
---|
40 |
|
---|
41 |
|
---|
42 | //link to the messanger
|
---|
43 | messenger = new PrimaryGeneratorMessenger(this);
|
---|
44 | }//Ctor
|
---|
45 |
|
---|
46 | //-------------------------------------------------------------------------------------------------
|
---|
47 |
|
---|
48 | ELYSE::PrimaryGeneratorAction::~PrimaryGeneratorAction() {
|
---|
49 | delete particleGun;
|
---|
50 | delete messenger;
|
---|
51 | }//Dtor
|
---|
52 |
|
---|
53 | //-------------------------------------------------------------------------------------------------
|
---|
54 |
|
---|
55 | void ELYSE::PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
|
---|
56 |
|
---|
57 |
|
---|
58 | //use the Gun used by default or in the Messenger
|
---|
59 | particleGun->GeneratePrimaryVertex(anEvent);
|
---|
60 |
|
---|
61 | //This code suppose 1 particle in the gun.
|
---|
62 | // G4ThreeVector P = anEvent->GetPrimaryVertex()->GetPrimary()->GetMomentum();
|
---|
63 | // G4ThreeVector vtx = anEvent->GetPrimaryVertex()->GetPosition();
|
---|
64 | // G4double m = anEvent->GetPrimaryVertex()->GetPrimary()->GetMass();
|
---|
65 | // G4int pdg = anEvent->GetPrimaryVertex()->GetPrimary()->GetPDGcode());
|
---|
66 |
|
---|
67 | // G4ThreeVector dir = P.unit();
|
---|
68 | // G4double E = std::sqrt((P.dot(P))+(m*m));
|
---|
69 |
|
---|
70 | // SetBeamPDG(pdg);
|
---|
71 | // SetBeamEnergy(E);
|
---|
72 | // SetVtx(vtx);
|
---|
73 | // SetBeamDir(dir);
|
---|
74 |
|
---|
75 | }//GeneratePrimaries
|
---|
76 |
|
---|
77 | //-------------------------------------------------------------------------------------------------
|
---|
78 | void ELYSE::PrimaryGeneratorAction::SetBeamPDG(G4int i) {
|
---|
79 |
|
---|
80 | // G4cout << "(JEC): SetBeamPDG(" << i << ")" << G4endl;
|
---|
81 |
|
---|
82 | beampdg = i;
|
---|
83 | particleGun->
|
---|
84 | SetParticleDefinition(particleTable->FindParticle(i));
|
---|
85 | }//SetBeamPDG
|
---|
86 | //-------------------------------------------------------------------------------------------------
|
---|
87 |
|
---|
88 | void ELYSE::PrimaryGeneratorAction::SetBeamName(G4String i) {
|
---|
89 |
|
---|
90 | // G4cout << "(JEC): SetBeamName(" << i << ")" << G4endl;
|
---|
91 |
|
---|
92 | beampdg = particleTable->FindParticle(i)->GetPDGEncoding();
|
---|
93 |
|
---|
94 | particleGun->
|
---|
95 | SetParticleDefinition(particleTable->FindParticle(i));
|
---|
96 | }//SetBeamPDG
|
---|
97 |
|
---|
98 | //-----------------------------------------------------------------------
|
---|
99 |
|
---|
100 | void ELYSE::PrimaryGeneratorAction::SetBeamEnergy(G4double i) {
|
---|
101 | // G4cout << "(JEC): SetBeamEnergy(" << i << ")" << G4endl;
|
---|
102 | beamenergy = i;
|
---|
103 | particleGun->SetParticleEnergy(i);
|
---|
104 | }//SetBeamEnergy
|
---|
105 |
|
---|
106 | //-----------------------------------------------------------------------
|
---|
107 |
|
---|
108 | void ELYSE::PrimaryGeneratorAction::SetVtx(G4ThreeVector i) {
|
---|
109 | // G4cout << "(JEC): SetVtx(" << i << ")" << G4endl;
|
---|
110 | vtx = i;
|
---|
111 | particleGun->SetParticlePosition(i);
|
---|
112 | }//SetVtx
|
---|
113 |
|
---|
114 | //-----------------------------------------------------------------------
|
---|
115 |
|
---|
116 | void ELYSE::PrimaryGeneratorAction::SetBeamDir(G4ThreeVector i) {
|
---|
117 | // G4cout << "(JEC): SetBeamDir(" << i << ")" << G4endl;
|
---|
118 | beamdir = i;
|
---|
119 | particleGun->SetParticleMomentumDirection(i);
|
---|
120 | }//SetBeamDir
|
---|
121 |
|
---|
122 | //-----------------------------------------------------------------------
|
---|
123 | void ELYSE::PrimaryGeneratorAction::SetOptPhotonPolar(G4ThreeVector i) {
|
---|
124 | polar = i;
|
---|
125 | // G4cout << "(JEC): SetOptPhotonPolar(" << polar << ")" << G4endl;
|
---|
126 | particleGun->SetParticlePolarization(i);
|
---|
127 | }
|
---|