1 | #include "OptPrimaryGeneratorAction.hh" |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | #include "Randomize.hh" |
---|
6 | #include "TRandom3.h" |
---|
7 | #include "DetectorGeometry.hh" |
---|
8 | #include "Detector.hh" |
---|
9 | |
---|
10 | #include "Pupil.hh" |
---|
11 | #include "G4Event.hh" |
---|
12 | #include "EVector.hh" |
---|
13 | #include "G4ParticleGun.hh" |
---|
14 | #include "G4ParticleTable.hh" |
---|
15 | #include "G4ParticleDefinition.hh" |
---|
16 | #include "G4RunManager.hh" |
---|
17 | #include "PhotonsOnPupil.hh" |
---|
18 | #include "Photon.hh" |
---|
19 | #include "TMath.h" |
---|
20 | #include <iostream> |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | using namespace TMath; |
---|
24 | using namespace CLHEP; |
---|
25 | //----------------------------------------------------------------------------------------- |
---|
26 | |
---|
27 | OptPrimaryGeneratorAction::OptPrimaryGeneratorAction(bool active): |
---|
28 | factive(active) |
---|
29 | { |
---|
30 | SetSender("OptPrimaryGeneratorAction"); |
---|
31 | G4int n_particle = 1; |
---|
32 | particleGun = new G4ParticleGun(n_particle); |
---|
33 | gRandom->SetSeed(99999); |
---|
34 | fThetaMin = 0.; |
---|
35 | fThetaMax = 0.; |
---|
36 | fPhiMin = 0.; |
---|
37 | fPhiMax = 360.; |
---|
38 | fDirection.set(0.,0.,1.); |
---|
39 | fEnergyMin = 0.*MeV; //eV |
---|
40 | fEnergyMax = 0.*MeV; //eV |
---|
41 | fEnergy = 0.*MeV; //eV |
---|
42 | fTheta = 0.*DegToRad(); |
---|
43 | fPhi = 0.*DegToRad(); |
---|
44 | |
---|
45 | if (factive)Init(); |
---|
46 | |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | //----------------------------------------------------------------------------------------- |
---|
51 | |
---|
52 | OptPrimaryGeneratorAction::~OptPrimaryGeneratorAction() |
---|
53 | { |
---|
54 | delete particleGun; |
---|
55 | |
---|
56 | } |
---|
57 | //----------------------------------------------------------------------------------------- |
---|
58 | void OptPrimaryGeneratorAction::Init(){ |
---|
59 | |
---|
60 | |
---|
61 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
62 | string p_type = Conf()->GetStr("PrimaryGeneratorAction.ParticleType"); |
---|
63 | MsgForm(EsafMsg::Info,Form("Particle Type is %s",p_type.data())); |
---|
64 | G4ParticleDefinition* particle = particleTable->FindParticle(p_type.data()); |
---|
65 | particleGun->SetParticleDefinition(particle); |
---|
66 | particleGun->SetParticleTime(0.0*ns); |
---|
67 | GenerateDirection(); |
---|
68 | GenerateEnergy(); |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | //----------------------------------------------------------------------------------------- |
---|
73 | void OptPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
74 | { |
---|
75 | if(!factive)return; |
---|
76 | string FillPosition = Conf()->GetStr("PrimaryGeneratorAction.GeneratePrimaries"); |
---|
77 | if(!FillPosition.compare ("Circle")) |
---|
78 | FillCircle(anEvent); |
---|
79 | else if(!FillPosition.compare ("Point")) |
---|
80 | OnePoint(anEvent); |
---|
81 | |
---|
82 | } |
---|
83 | //----------------------------------------------------------------------------------------- |
---|
84 | void OptPrimaryGeneratorAction::GenerateDirection() |
---|
85 | { |
---|
86 | //GenerateTheta |
---|
87 | fThetaMin = (double)Conf()->GetNum("PrimaryGeneratorAction.ThetaMin"); |
---|
88 | fThetaMax = (double)Conf()->GetNum("PrimaryGeneratorAction.ThetaMax"); |
---|
89 | |
---|
90 | if ( fThetaMin == fThetaMax ) |
---|
91 | fTheta = fThetaMin*DegToRad(); |
---|
92 | else fTheta = gRandom->Uniform(fThetaMin,fThetaMax)*DegToRad(); |
---|
93 | fDirection.setTheta(fTheta); |
---|
94 | |
---|
95 | //Generate Phi |
---|
96 | fPhiMin = (double)Conf()->GetNum("PrimaryGeneratorAction.PhiMin"); |
---|
97 | fPhiMax = (double)Conf()->GetNum("PrimaryGeneratorAction.PhiMax"); |
---|
98 | |
---|
99 | if ( fPhiMin == fPhiMax ) |
---|
100 | fPhi = fPhiMin*DegToRad(); |
---|
101 | else fPhi = gRandom->Uniform(fPhiMin,fPhiMax)*DegToRad(); |
---|
102 | fDirection.setPhi(fPhi); |
---|
103 | fDirection.setMag(1.); |
---|
104 | particleGun->SetParticleMomentumDirection(fDirection); |
---|
105 | } |
---|
106 | //---------------------------------------------------------------------------------------- |
---|
107 | void OptPrimaryGeneratorAction::GenerateEnergy() { |
---|
108 | // |
---|
109 | // Genrate energy |
---|
110 | // |
---|
111 | fEnergyMin = (double)Conf()->GetNum("PrimaryGeneratorAction.EnergyMin"); |
---|
112 | fEnergyMax = (double)Conf()->GetNum("PrimaryGeneratorAction.EnergyMax"); |
---|
113 | if ( fEnergyMin == fEnergyMax ) |
---|
114 | fEnergy = fEnergyMin; |
---|
115 | else fEnergy = gRandom->Uniform(fEnergyMin,fEnergyMax); |
---|
116 | particleGun->SetParticleEnergy(fEnergy*MeV); |
---|
117 | |
---|
118 | |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | void OptPrimaryGeneratorAction::OnePoint(G4Event* anEvent){ |
---|
123 | double x = (double)Conf()->GetNum("PrimaryGeneratorAction.Point.x"); |
---|
124 | double y = (double)Conf()->GetNum("PrimaryGeneratorAction.Point.y"); |
---|
125 | particleGun->SetParticlePosition(G4ThreeVector(x*mm,y*mm,0.*mm)); |
---|
126 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | //----------------------------------------------------------------------------------------- |
---|
131 | void OptPrimaryGeneratorAction::FillCircle(G4Event* anEvent){ |
---|
132 | double x,y,phi,r; |
---|
133 | double rmin = (double)Conf()->GetNum("PrimaryGeneratorAction.Circle.rmin"); |
---|
134 | double rmax = (double)Conf()->GetNum("PrimaryGeneratorAction.Circle.rmax"); |
---|
135 | phi = gRandom->Uniform(0,TMath::TwoPi()); |
---|
136 | r = gRandom->Uniform(rmin*mm,rmax*mm); |
---|
137 | x = r*Cos(phi); |
---|
138 | y = r*Sin(phi); |
---|
139 | particleGun->SetParticlePosition(G4ThreeVector(x,y,0.*mm)); |
---|
140 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | |
---|