Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
GammaRayTelPrimaryGeneratorAction Class Reference

#include <GammaRayTelPrimaryGeneratorAction.hh>

Inheritance diagram for GammaRayTelPrimaryGeneratorAction:
G4VUserPrimaryGeneratorAction

Public Member Functions

 GammaRayTelPrimaryGeneratorAction ()
 
 ~GammaRayTelPrimaryGeneratorAction ()
 
void GeneratePrimaries (G4Event *)
 
void SetRndmFlag (G4String val)
 
void SetSourceType (G4int val)
 
void SetSpectrumType (G4int val)
 
void SetVertexRadius (G4double val)
 
void SetSourceGen (G4bool val)
 
- Public Member Functions inherited from G4VUserPrimaryGeneratorAction
 G4VUserPrimaryGeneratorAction ()
 
virtual ~G4VUserPrimaryGeneratorAction ()
 

Detailed Description

Definition at line 58 of file GammaRayTelPrimaryGeneratorAction.hh.

Constructor & Destructor Documentation

GammaRayTelPrimaryGeneratorAction::GammaRayTelPrimaryGeneratorAction ( )

Definition at line 58 of file GammaRayTelPrimaryGeneratorAction.cc.

References python.hepunit::cm, G4ParticleTable::FindParticle(), G4ParticleTable::GetParticleTable(), G4RunManager::GetRunManager(), G4RunManager::GetUserDetectorConstruction(), GammaRayTelDetectorConstruction::GetWorldSizeZ(), python.hepunit::MeV, G4ParticleGun::SetParticleDefinition(), G4ParticleGun::SetParticleEnergy(), G4ParticleGun::SetParticleMomentumDirection(), and G4VPrimaryGenerator::SetParticlePosition().

59  :rndmFlag("off"),nSourceType(0),nSpectrumType(0)
60 {
62  GammaRayTelDetector =
64 
65 
66  //create a messenger for this class
67 
68  gunMessenger = new GammaRayTelPrimaryGeneratorMessenger(this);
69 
70  G4int n_particle = 1;
71 
72  particleGun = new G4ParticleGun(n_particle);
73  // default particle kinematic
74 
76  G4String particleName;
77  G4ParticleDefinition* particle
78  = particleTable->FindParticle(particleName="e-");
79  particleGun->SetParticleDefinition(particle);
80  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
81  particleGun->SetParticleEnergy(30.*MeV);
82  G4double position = 0.5*(GammaRayTelDetector->GetWorldSizeZ());
83  particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
84  particleSource = new G4GeneralParticleSource();
85 
86 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
void SetParticlePosition(G4ThreeVector aPosition)
void SetParticleEnergy(G4double aKineticEnergy)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static G4ParticleTable * GetParticleTable()
double G4double
Definition: G4Types.hh:76
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
GammaRayTelPrimaryGeneratorAction::~GammaRayTelPrimaryGeneratorAction ( )

Definition at line 90 of file GammaRayTelPrimaryGeneratorAction.cc.

91 {
92  if (sourceGun)
93  delete particleGun;
94  else
95  delete particleSource;
96 
97  delete gunMessenger;
98 }

Member Function Documentation

void GammaRayTelPrimaryGeneratorAction::GeneratePrimaries ( G4Event anEvent)
virtual

Implements G4VUserPrimaryGeneratorAction.

Definition at line 102 of file GammaRayTelPrimaryGeneratorAction.cc.

References python.hepunit::cm, CLHEP::Hep3Vector::dot(), G4cout, G4endl, G4UniformRand, G4ParticleGun::GeneratePrimaryVertex(), G4GeneralParticleSource::GeneratePrimaryVertex(), G4ParticleGun::GetParticleMomentumDirection(), GammaRayTelDetectorConstruction::GetWorldSizeXY(), GammaRayTelDetectorConstruction::GetWorldSizeZ(), python.hepunit::GeV, python.hepunit::halfpi, CLHEP::Hep3Vector::mag(), CLHEP::Hep3Vector::phi(), python.hepunit::pi, CLHEP::Hep3Vector::rotate(), CLHEP::Hep3Vector::setMag(), G4ParticleGun::SetParticleEnergy(), G4ParticleGun::SetParticleMomentumDirection(), G4VPrimaryGenerator::SetParticlePosition(), CLHEP::Hep3Vector::setPhi(), CLHEP::Hep3Vector::setTheta(), CLHEP::Hep3Vector::theta(), python.hepunit::twopi, z, and G4InuclParticleNames::z0.

103 {
104  if (sourceGun)
105  {
106 
107  //this function is called at the begining of event
108  //
109  G4double z0 = 0.5*(GammaRayTelDetector->GetWorldSizeZ());
110  G4double x0 = 0.*cm, y0 = 0.*cm;
111 
112  G4ThreeVector pos0;
113  G4ThreeVector dir0;
114  G4ThreeVector vertex0 = G4ThreeVector(x0,y0,z0);
115 
116  dir0 = G4ThreeVector(0.,0.,-1.);
117 
118  G4double theta, phi, y, f;
119  G4double theta0=0.;
120  G4double phi0=0.;
121 
122  switch(nSourceType) {
123  case 0:
124  particleGun->SetParticlePosition(vertex0);
125  particleGun->SetParticleMomentumDirection(dir0);
126  break;
127  case 1:
128  // GS: Generate random position on the 4PIsphere to create a unif. distrib.
129  // GS: on the sphere
130  phi = G4UniformRand() * twopi;
131  do {
132  y = G4UniformRand()*1.0;
133  theta = G4UniformRand() * pi;
134  f = std::sin(theta);
135  } while (y > f);
136  vertex0 = G4ThreeVector(1.,0.,0.);
137  vertex0.setMag(dVertexRadius);
138  vertex0.setTheta(theta);
139  vertex0.setPhi(phi);
140  particleGun->SetParticlePosition(vertex0);
141 
142  dir0 = G4ThreeVector(1.,0.,0.);
143  do {
144  phi = G4UniformRand() * twopi;
145  do {
146  y = G4UniformRand()*1.0;
147  theta = G4UniformRand() * pi;
148  f = std::sin(theta);
149  } while (y > f);
150  dir0.setPhi(phi);
151  dir0.setTheta(theta);
152  } while (vertex0.dot(dir0) >= -0.7 * vertex0.mag());
154 
155  break;
156  case 2:
157  // GS: Generate random position on the upper semi-sphere z>0 to create a unif. distrib.
158  // GS: on a plane
159  phi = G4UniformRand() * twopi;
160  do {
161  y = G4UniformRand()*1.0;
162  theta = G4UniformRand() * halfpi;
163  f = std::sin(theta) * std::cos(theta);
164  } while (y > f);
165  vertex0 = G4ThreeVector(1.,0.,0.);
166 
167  G4double xy = GammaRayTelDetector->GetWorldSizeXY();
168  G4double z = GammaRayTelDetector->GetWorldSizeZ();
169 
170  if (dVertexRadius > xy*0.5)
171  {
172  G4cout << "vertexRadius too big " << G4endl;
173  G4cout << "vertexRadius setted to " << xy*0.45 << G4endl;
174  dVertexRadius = xy*0.45;
175  }
176 
177  if (dVertexRadius > z*0.5)
178  {
179  G4cout << "vertexRadius too high " << G4endl;
180  G4cout << "vertexRadius setted to " << z*0.45 << G4endl;
181  dVertexRadius = z*0.45;
182  }
183 
184 
185  vertex0.setMag(dVertexRadius);
186  vertex0.setTheta(theta);
187  vertex0.setPhi(phi);
188 
189  // GS: Get the user defined direction for the primaries and
190  // GS: Rotate the random position according to the user defined direction for the particle
191 
192  dir0 = particleGun->GetParticleMomentumDirection();
193  if (dir0.mag() > 0.001)
194  {
195  theta0 = dir0.theta();
196  phi0 = dir0.phi();
197  }
198 
199  if (theta0!=0.)
200  {
201  G4ThreeVector rotationAxis(1.,0.,0.);
202  rotationAxis.setPhi(phi0+halfpi);
203  vertex0.rotate(theta0+pi,rotationAxis);
204  }
205  particleGun->SetParticlePosition(vertex0);
206  break;
207  }
208 
209 
210  G4double pEnergy;
211 
212  switch(nSpectrumType) {
213  case 0:
214  break;
215  case 1:
216  break;
217  case 2:
218  do {
219  y = G4UniformRand()*100000.0;
220  pEnergy = G4UniformRand() * 10. * GeV;
221  f = std::pow(pEnergy * (1/GeV), -4.);
222  } while (y > f);
223 
224  particleGun->SetParticleEnergy(pEnergy);
225 
226  break;
227  case 3:
228  break;
229  }
230 
231  particleGun->GeneratePrimaryVertex(anEvent);
232  }
233  else
234  {
235  particleSource->GeneratePrimaryVertex(anEvent);
236  }
237 
238 }
void setPhi(double)
CLHEP::Hep3Vector G4ThreeVector
double dot(const Hep3Vector &) const
G4double z
Definition: TRTMaterials.hh:39
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
G4ParticleMomentum GetParticleMomentumDirection() const
void SetParticlePosition(G4ThreeVector aPosition)
#define G4UniformRand()
Definition: Randomize.hh:87
G4GLOB_DLL std::ostream G4cout
double phi() const
void setTheta(double)
double theta() const
void SetParticleEnergy(G4double aKineticEnergy)
#define G4endl
Definition: G4ios.hh:61
void setMag(double)
Definition: ThreeVector.cc:25
double G4double
Definition: G4Types.hh:76
double mag() const
Hep3Vector & rotate(double, const Hep3Vector &)
Definition: ThreeVectorR.cc:28
void GammaRayTelPrimaryGeneratorAction::SetRndmFlag ( G4String  val)
inline

Definition at line 67 of file GammaRayTelPrimaryGeneratorAction.hh.

Referenced by GammaRayTelPrimaryGeneratorMessenger::SetNewValue().

67 { rndmFlag = val;}
void GammaRayTelPrimaryGeneratorAction::SetSourceGen ( G4bool  val)
inline

Definition at line 71 of file GammaRayTelPrimaryGeneratorAction.hh.

Referenced by GammaRayTelPrimaryGeneratorMessenger::SetNewValue().

71 { sourceGun = val;}
void GammaRayTelPrimaryGeneratorAction::SetSourceType ( G4int  val)
inline

Definition at line 68 of file GammaRayTelPrimaryGeneratorAction.hh.

Referenced by GammaRayTelPrimaryGeneratorMessenger::SetNewValue().

68 { nSourceType = val;}
void GammaRayTelPrimaryGeneratorAction::SetSpectrumType ( G4int  val)
inline

Definition at line 69 of file GammaRayTelPrimaryGeneratorAction.hh.

Referenced by GammaRayTelPrimaryGeneratorMessenger::SetNewValue().

69 { nSpectrumType = val;}
void GammaRayTelPrimaryGeneratorAction::SetVertexRadius ( G4double  val)
inline

Definition at line 70 of file GammaRayTelPrimaryGeneratorAction.hh.

Referenced by GammaRayTelPrimaryGeneratorMessenger::SetNewValue().

70 { dVertexRadius = val;}

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