Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
F04PrimaryGeneratorAction Class Reference

#include <F04PrimaryGeneratorAction.hh>

Inheritance diagram for F04PrimaryGeneratorAction:
Collaboration diagram for F04PrimaryGeneratorAction:

Public Member Functions

 F04PrimaryGeneratorAction (F04DetectorConstruction *)
 
virtual ~F04PrimaryGeneratorAction ()
 
virtual void GeneratePrimaries (G4Event *)
 
void SetRndmFlag (G4String val)
 
void SetXvertex (G4double x)
 
void SetYvertex (G4double y)
 
void SetZvertex (G4double z)
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 47 of file F04PrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

F04PrimaryGeneratorAction::F04PrimaryGeneratorAction ( F04DetectorConstruction detectorConstruction)

Definition at line 52 of file F04PrimaryGeneratorAction.cc.

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 
60  fGunMessenger = new F04PrimaryGeneratorMessenger(this);
61 
62  G4String particleName;
64 
65  fParticleGun->SetParticleDefinition(particleTable->
66  FindParticle(particleName="proton"));
67  fParticleGun->SetParticleEnergy(500.*MeV);
68  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
69 
70  fZvertex = -0.5*(fDetector->GetTargetThickness());
71  fParticleGun->SetParticlePosition(G4ThreeVector(fXvertex,fYvertex,fZvertex));
72 
73 }
CLHEP::Hep3Vector G4ThreeVector
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
void SetParticlePosition(G4ThreeVector aPosition)
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
static constexpr double MeV
Definition: G4SIunits.hh:214
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)

Here is the call graph for this function:

F04PrimaryGeneratorAction::~F04PrimaryGeneratorAction ( )
virtual

Definition at line 77 of file F04PrimaryGeneratorAction.cc.

78 {
79  delete fParticleGun;
80  delete fGunMessenger;
81 }

Member Function Documentation

void F04PrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 85 of file F04PrimaryGeneratorAction.cc.

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 
114  fParticleGun->SetParticleMomentumDirection(direction);
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);
147  fParticleGun->GeneratePrimaryVertex(anEvent);
148 }
G4AffineTransform Inverse() const
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
static constexpr double twopi
Definition: G4SIunits.hh:76
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:97
static G4TransportationManager * GetTransportationManager()
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4ThreeVector TransformAxis(const G4ThreeVector &axis) const
void SetWorldVolume(G4VPhysicalVolume *pWorld)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:125
const G4AffineTransform & GetTopTransform() const
const G4NavigationHistory * GetHistory() const
double G4double
Definition: G4Types.hh:76
G4VPhysicalVolume * GetWorldVolume() const

Here is the call graph for this function:

void F04PrimaryGeneratorAction::SetRndmFlag ( G4String  val)
inline

Definition at line 58 of file F04PrimaryGeneratorAction.hh.

58 { fRndmFlag = val;}

Here is the caller graph for this function:

void F04PrimaryGeneratorAction::SetXvertex ( G4double  x)

Definition at line 152 of file F04PrimaryGeneratorAction.cc.

153 {
154  fVertexdefined = true;
155  fXvertex = x;
156  G4cout << " X coordinate of the primary vertex = " << fXvertex/mm <<
157  " mm." << G4endl;
158 }
static constexpr double mm
Definition: G4SIunits.hh:115
tuple x
Definition: test.py:50
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

Here is the caller graph for this function:

void F04PrimaryGeneratorAction::SetYvertex ( G4double  y)

Definition at line 162 of file F04PrimaryGeneratorAction.cc.

163 {
164  fVertexdefined = true;
165  fYvertex = y;
166  G4cout << " Y coordinate of the primary vertex = " << fYvertex/mm <<
167  " mm." << G4endl;
168 }
static constexpr double mm
Definition: G4SIunits.hh:115
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

Here is the caller graph for this function:

void F04PrimaryGeneratorAction::SetZvertex ( G4double  z)

Definition at line 172 of file F04PrimaryGeneratorAction.cc.

173 {
174  fVertexdefined = true;
175  fZvertex = z;
176  G4cout << " Z coordinate of the primary vertex = " << fZvertex/mm <<
177  " mm." << G4endl;
178 }
static constexpr double mm
Definition: G4SIunits.hh:115
G4GLOB_DLL std::ostream G4cout
tuple z
Definition: test.py:28
#define G4endl
Definition: G4ios.hh:61

Here is the caller graph for this function:


The documentation for this class was generated from the following files: