Hi,
I’m trying to create a General Particle Source which I define in a configuration file.
I’m using this code for PosDist and AngDist:
auto particle_source = std::make_unique<G4GeneralParticleSource>(); auto single_source = particle_source_->GetCurrentSource(); single_source->GetPosDist()->SetCentreCoords(config.get<G4ThreeVector>("source_position")); single_source->GetPosDist()->SetPosDisType("Beam"); single_source->GetPosDist()->SetBeamSigmaInR(config.get<double>("beam_size", 0)); single_source->GetAngDist()->SetAngDistType("beam2d"); single_source->GetAngDist()->DefineAngRefAxes("angref1", G4ThreeVector(1., 0, 0)); G4TwoVector divergence = config.get<G4TwoVector>("beam_divergence", G4TwoVector(0., 0.)); single_source->GetAngDist()->SetBeamSigmaInAngX(divergence.x()); single_source->GetAngDist()->SetBeamSigmaInAngY(divergence.y()); G4ThreeVector direction = config.get<G4ThreeVector>("beam_direction"); single_source->GetAngDist()->SetParticleMomentumDirection(direction);
The code compiles fine, but when I look at the MomentumDirection by using GetParticleMomentumDirection() I get the following direction, regardless of the G4ThreeVector direction used:
single_source->GetParticleMomentumDirection() = (1,0,0) (which is default)
particle_sourc->GetParticleMomentumDirection() = (0,0,-1) (which is default)
Could you tell me why the “single_source->GetAngDist()->SetParticleMomentumDirection(direction)” does not affect the direction?
For some reason, the “SetParticleMomentumDirection(direction)” function works if I add the following piece of code in the following position.
... single_source->GetAngDist()->SetAngDistType("beam2d"); G4UImanager* UI = G4UImanager::GetUIpointer(); UI->ApplyCommand("/gps/direction 1 0 1); single_source->GetAngDist()->DefineAngRefAxes("angref1", G4ThreeVector(1., 0, 0)); ...
However, this gave me a slightly different beam compared to the beam without the added UI->ApplyCommand (probably because the “beam2d properties” are lost, but I’m not sure)
This something I don’t want so would like to solve the problem without adding the UI->ApplyCommand.
Cheers,
Koen