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 | // $Id: MicrobeamPrimaryGeneratorAction.cc,v 1.7 2007/08/27 15:51:54 gcosmo Exp $ |
---|
28 | // ------------------------------------------------------------------- |
---|
29 | |
---|
30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
31 | |
---|
32 | #include "G4Event.hh" |
---|
33 | #include "G4ParticleTable.hh" |
---|
34 | #include "Randomize.hh" |
---|
35 | |
---|
36 | #include "MicrobeamPrimaryGeneratorAction.hh" |
---|
37 | #include "MicrobeamDetectorConstruction.hh" |
---|
38 | |
---|
39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
40 | |
---|
41 | MicrobeamPrimaryGeneratorAction::MicrobeamPrimaryGeneratorAction(MicrobeamDetectorConstruction* DC) |
---|
42 | :Detector(DC) |
---|
43 | { |
---|
44 | particleGun = new G4ParticleGun(1); |
---|
45 | } |
---|
46 | |
---|
47 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
48 | |
---|
49 | MicrobeamPrimaryGeneratorAction::~MicrobeamPrimaryGeneratorAction() |
---|
50 | { |
---|
51 | delete particleGun; |
---|
52 | } |
---|
53 | |
---|
54 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
55 | |
---|
56 | void MicrobeamPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
57 | { |
---|
58 | G4int numEvent; |
---|
59 | numEvent=anEvent->GetEventID()+1; |
---|
60 | G4double x0,y0,z0,theta,phi,xMom0,yMom0,zMom0,e0; |
---|
61 | |
---|
62 | // INITIAL BEAM POSITION |
---|
63 | |
---|
64 | z0=-10000*mm; |
---|
65 | x0=10*mm; |
---|
66 | y0=10*mm; |
---|
67 | |
---|
68 | G4double sizeMax = 0.5*micrometer; // INITIAL BEAM POSITION UNIFORMLY SPREAD ON A DISK |
---|
69 | while (! (std::sqrt(x0*x0+y0*y0)<= sizeMax) ) |
---|
70 | { |
---|
71 | x0 = CLHEP::RandFlat::shoot(-sizeMax,sizeMax); |
---|
72 | y0 = CLHEP::RandFlat::shoot(-sizeMax,sizeMax); |
---|
73 | } |
---|
74 | |
---|
75 | // INITIAL BEAM ENERGY |
---|
76 | |
---|
77 | e0= G4RandGauss::shoot(3*MeV,5.0955e-5*MeV); // AIFIRA ENERGY RESOLUTION |
---|
78 | |
---|
79 | // INITIAL BEAM DIVERGENCE |
---|
80 | |
---|
81 | do { |
---|
82 | theta=std::acos(1-G4UniformRand()*(1.0-std::cos(1.1e-6)))*rad; |
---|
83 | } |
---|
84 | while(theta>1.1e-6*rad); |
---|
85 | |
---|
86 | phi=CLHEP::twopi*G4UniformRand()*rad; |
---|
87 | |
---|
88 | xMom0=std::sin(theta)*std::cos(phi); |
---|
89 | yMom0=std::sin(theta)*std::sin(phi); |
---|
90 | zMom0=std::cos(theta); |
---|
91 | |
---|
92 | // VERBOSE |
---|
93 | |
---|
94 | G4cout |
---|
95 | << "-> Event # " << numEvent |
---|
96 | << " generated " |
---|
97 | << G4endl; |
---|
98 | |
---|
99 | /* |
---|
100 | G4cout |
---|
101 | << "-> Event # " << numEvent |
---|
102 | << " : THETA from Z axis (mrad) = " << theta*1000 |
---|
103 | << " -- PHI (deg) = " << phi*180/CLHEP::pi |
---|
104 | << " -- x0 (um) = " << x0/micrometer |
---|
105 | << " -- y0 (um) = " << y0/micrometer |
---|
106 | << " -- z0 (m) = " << z0/m |
---|
107 | << " -- e0 (MeV) = " << e0/MeV |
---|
108 | << G4endl; |
---|
109 | */ |
---|
110 | |
---|
111 | particleGun->SetParticleEnergy(e0); |
---|
112 | |
---|
113 | particleGun->SetParticleMomentumDirection(G4ThreeVector(xMom0,yMom0,zMom0)); |
---|
114 | |
---|
115 | particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); |
---|
116 | |
---|
117 | G4ParticleDefinition* particle= |
---|
118 | G4ParticleTable::GetParticleTable()->FindParticle("alpha"); |
---|
119 | |
---|
120 | particleGun->SetParticleDefinition(particle); |
---|
121 | |
---|
122 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
127 | |
---|
128 | |
---|