Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
F04PrimaryGeneratorAction.cc
이 파일의 문서화 페이지로 가기
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 // $Id: F04PrimaryGeneratorAction.cc 78002 2013-12-02 08:25:49Z gcosmo $
27 //
30 //
31 
32 #include "G4ios.hh"
33 #include "G4Event.hh"
34 #include "G4ParticleGun.hh"
35 #include "G4ParticleTable.hh"
36 #include "G4ParticleDefinition.hh"
37 
38 #include "G4GeometryManager.hh"
39 
40 #include "Randomize.hh"
41 #include "G4PhysicalConstants.hh"
42 #include "G4SystemOfUnits.hh"
43 
45 
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
53  : fDetector(detectorConstruction), fRndmFlag("off"), fFirst(false),
54  fXvertex(0.), fYvertex(0.), fZvertex(0.),
55  fVertexdefined(false)
56 {
57  G4int n_particle = 1;
58  fParticleGun = new G4ParticleGun(n_particle);
59 
61 
62  G4String particleName;
64 
65  fParticleGun->SetParticleDefinition(particleTable->
66  FindParticle(particleName="proton"));
69 
72 
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
79  delete fParticleGun;
80  delete fGunMessenger;
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87 
88  if (!fFirst) {
89 
90  fFirst = true;
91  G4ThreeVector direction(0.0,0.0,1.0);
92 
93  G4Navigator* theNavigator =
95  GetNavigatorForTracking();
96  if ( theNavigator->GetWorldVolume() )
97  {
98  G4Navigator* aNavigator = new G4Navigator();
99  aNavigator->SetWorldVolume(theNavigator->GetWorldVolume());
100 
101  G4ThreeVector center(0.,0.,0.);
102  aNavigator->LocateGlobalPointAndSetup(center,0,false);
103 
104  G4TouchableHistoryHandle touchable = aNavigator->
105  CreateTouchableHistoryHandle();
106 
107  // set Global2local transform
108  fGlobal2local = touchable->GetHistory()->GetTopTransform();
109 
110  direction = fGlobal2local.Inverse().TransformAxis(direction);
111  delete aNavigator;
112  }
113 
115  }
116 
117  G4double x0,y0,z0 ;
118 
119  if(fVertexdefined)
120  {
121  x0 = fXvertex ;
122  y0 = fYvertex ;
123  z0 = fZvertex ;
124  }
125  else
126  {
127  x0 = 0. ;
128  y0 = 0. ;
129  z0 = -0.5*(fDetector->GetTargetThickness());
130  }
131 
132  G4double r0, phi0;
133 
134  if (fRndmFlag == "on")
135  {
136  r0 = (fDetector->GetTargetRadius())*std::sqrt(G4UniformRand());
137  phi0 = twopi*G4UniformRand();
138  x0 = r0*std::cos(phi0);
139  y0 = r0*std::sin(phi0);
140  }
141 
142  G4ThreeVector localPosition(x0,y0,z0);
143  G4ThreeVector globalPosition =
144  fGlobal2local.Inverse().TransformPoint(localPosition);
145 
146  fParticleGun->SetParticlePosition(globalPosition);
148 }
149 
150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151 
153 {
154  fVertexdefined = true;
155  fXvertex = x;
156  G4cout << " X coordinate of the primary vertex = " << fXvertex/mm <<
157  " mm." << G4endl;
158 }
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161 
163 {
164  fVertexdefined = true;
165  fYvertex = y;
166  G4cout << " Y coordinate of the primary vertex = " << fYvertex/mm <<
167  " mm." << G4endl;
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 
173 {
174  fVertexdefined = true;
175  fZvertex = z;
176  G4cout << " Z coordinate of the primary vertex = " << fZvertex/mm <<
177  " mm." << G4endl;
178 }
Float_t x
Definition: compare.C:6
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
CLHEP::Hep3Vector G4ThreeVector
static G4ParticleTable * GetParticleTable()
static constexpr double MeV
Definition: G4SIunits.hh:214
virtual void GeneratePrimaries(G4Event *)
static constexpr double mm
Definition: G4SIunits.hh:115
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
Double_t z
void SetParticlePosition(G4ThreeVector aPosition)
F04PrimaryGeneratorAction(F04DetectorConstruction *)
Definition of the F04DetectorConstruction class.
double G4double
Definition: G4Types.hh:76
const G4NavigationHistory * GetHistory() const
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
F04DetectorConstruction * fDetector
#define G4UniformRand()
Definition: Randomize.hh:53
void SetWorldVolume(G4VPhysicalVolume *pWorld)
static constexpr double twopi
Definition: G4SIunits.hh:76
const G4AffineTransform & GetTopTransform() const
Definition of the F04PrimaryGeneratorAction class.
static G4TransportationManager * GetTransportationManager()
int G4int
Definition: G4Types.hh:78
Definition of the F04PrimaryGeneratorMessenger class.
virtual void GeneratePrimaryVertex(G4Event *evt)
G4GLOB_DLL std::ostream G4cout
G4AffineTransform Inverse() const
void SetParticleEnergy(G4double aKineticEnergy)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:131
G4VPhysicalVolume * GetWorldVolume() const
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
F04PrimaryGeneratorMessenger * fGunMessenger
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)