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 | // GridParticleGun.cc |
---|
28 | // |
---|
29 | // Implementation of grid particle gun |
---|
30 | // |
---|
31 | |
---|
32 | #include "GridParticleGun.hh" |
---|
33 | #include "GridParticleGunMessenger.hh" |
---|
34 | |
---|
35 | #include "G4PrimaryParticle.hh" |
---|
36 | #include "G4ParticleTypes.hh" |
---|
37 | #include "G4Event.hh" |
---|
38 | |
---|
39 | // |
---|
40 | // Constructor (no arguments) |
---|
41 | // |
---|
42 | GridParticleGun::GridParticleGun() |
---|
43 | { |
---|
44 | SetDefaults(); |
---|
45 | } |
---|
46 | |
---|
47 | // |
---|
48 | // Constructor |
---|
49 | // |
---|
50 | GridParticleGun::GridParticleGun( G4ThreeVector theDirection, |
---|
51 | G4ThreeVector theOrigin, |
---|
52 | G4ThreeVector theGrid1, |
---|
53 | G4ThreeVector theGrid2, |
---|
54 | G4int theN1, G4int theN2 ) |
---|
55 | { |
---|
56 | SetDefaults(); |
---|
57 | |
---|
58 | direction = theDirection; |
---|
59 | origin = theOrigin; |
---|
60 | grid1 = theGrid1; |
---|
61 | grid2 = theGrid2; |
---|
62 | n1 = theN1; |
---|
63 | n2 = theN2; |
---|
64 | |
---|
65 | if (n1*n2 == 0) |
---|
66 | G4Exception( "GridParticleGun created with n1 or n2 zero" ); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | // |
---|
71 | // Destructor |
---|
72 | // |
---|
73 | GridParticleGun::~GridParticleGun() { |
---|
74 | delete messenger; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | // |
---|
79 | // SetDefaults |
---|
80 | // |
---|
81 | // Set defaults and create associated messenger |
---|
82 | // |
---|
83 | void GridParticleGun::SetDefaults() |
---|
84 | { |
---|
85 | direction = G4ThreeVector(0,0,1); |
---|
86 | origin = G4ThreeVector(-2*m,-2*m,-2*m); |
---|
87 | grid1 = G4ThreeVector(4*m,0,0); |
---|
88 | grid2 = G4ThreeVector(0,4*m,0); |
---|
89 | n1 = 10; |
---|
90 | n2 = 10; |
---|
91 | |
---|
92 | |
---|
93 | particleType = G4Geantino::GeantinoDefinition(); |
---|
94 | |
---|
95 | messenger = new GridParticleGunMessenger( this ); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | // |
---|
100 | // GeneratePrimaryVertex |
---|
101 | // |
---|
102 | // Make the event. |
---|
103 | // |
---|
104 | // Note the strange notation of G4Event: we are allowed to have as many |
---|
105 | // "primary" vertices as we wish. |
---|
106 | // |
---|
107 | void GridParticleGun::GeneratePrimaryVertex( G4Event *evt ) |
---|
108 | { |
---|
109 | G4ThreeVector delta1 = grid1*(1.0/((G4double) n1)), |
---|
110 | delta2 = grid2*(1.0/((G4double) n2)); |
---|
111 | |
---|
112 | G4int i = 0; |
---|
113 | G4ThreeVector iStart = origin; |
---|
114 | do { |
---|
115 | G4int j = 0; |
---|
116 | G4ThreeVector jStart = iStart; |
---|
117 | do { |
---|
118 | |
---|
119 | // |
---|
120 | // New particle: make it's vertex |
---|
121 | // |
---|
122 | G4PrimaryVertex *vertex = new G4PrimaryVertex( jStart, 0.0 ); |
---|
123 | |
---|
124 | // |
---|
125 | // ...then make it's self |
---|
126 | // |
---|
127 | G4PrimaryParticle *particle = new G4PrimaryParticle( particleType, direction.x(), direction.y(), direction.z() ); |
---|
128 | |
---|
129 | // |
---|
130 | // ...add it to the vertex, and add the vertex to the event |
---|
131 | // |
---|
132 | vertex->SetPrimary( particle ); |
---|
133 | evt->AddPrimaryVertex( vertex ); |
---|
134 | |
---|
135 | } while( jStart += delta2, j++ < n2 ); |
---|
136 | } while( iStart += delta1, i++ < n1 ); |
---|
137 | } |
---|
138 | |
---|