Thank you for your help! I really appreciate!
This is my generator.cc
#include “generator.hh”
#include “Randomize.hh”
#include “G4RandomDirection.hh”
MyPrimaryGenerator::MyPrimaryGenerator()
{
fParticleGun = new G4ParticleGun(1);
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4String particleName = “gamma”;
G4ParticleDefinition *particle = particleTable->FindParticle(“gamma”);
fParticleGun->SetParticleDefinition(particle);
}
MyPrimaryGenerator::~MyPrimaryGenerator()
{
delete fParticleGun;
}
void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent)
{
G4ThreeVector pos1(-53.66cm, -36cm - 1.8mm - 41.4cm, 0*m);
fParticleGun->SetParticlePosition(pos1);
G4double focus_size = 0.005*mm;
G4double x0 = focus_size * (G4UniformRand()+4.0);
G4double y0 = focus_size * (G4UniformRand()+4.0);
G4double cosTheta = 0.75;
G4ThreeVector v = G4RandomDirection(cosTheta);
v.set(v.y(), v.z(), v.x());
fParticleGun->SetParticleMomentumDirection(G4RandomDirection);
fParticleGun->SetParticleMomentum(0.1 *MeV);
fParticleGun->GeneratePrimaryVertex(anEvent);
which results in
C:\geant4\sim\generator.cc(74,62): error C2664: ‘void G4ParticleGun::SetParticleMomentumDirection(G4ParticleMomentum)’: cannot convert argument 1 from ‘overloaded-function’ to ‘G4ParticleMomentum’ [C:\geant4\bu
ild\project.vcxproj]
C:\geant4\sim\generator.cc(74,62): message : No constructor could take the source type, or constructor overload resolution was ambiguous [C:\geant4\build\project.vcxproj]
C:\Program Files\Geant4-11.0\include\Geant4\G4ParticleGun.hh(96,17): message : see declaration of ‘G4ParticleGun::SetParticleMomentumDirection’ [C:\geant4\build\project.vcxproj]
line 74 corresponds to:
fParticleGun->SetParticleMomentumDirection(G4RandomDirection);
and line 96 is the closing bracket
}
I realized that these two lines are working apparently and that there is an issue somewhere else when I try to use it for the particle direction. When I use
G4double cosTheta = 0.75;
G4ThreeVector G4RandomDirection(cosTheta);
fParticleGun->SetParticleMomentumDirection(G4RandomDirection);
I won’t get an error. Obviously I’m not sure how to change/modify the axis and the particle direction then.
Could you please advice?