It is not convenient that G4GeneralParticleSource class can not set particle energy, moment direction?

By the way, it is ineffective when using G4GeneralParticleSource class to set particle position.

Hello,

Is this a question or are you ranting?

I suppose this is a question…:
You can control particle energy, moment direction and particle position of the GPS via a macro file or macro-commands with

/gps/position 0 0 0 #GPS origin position
/gps/direction 0 0 1 #momentum oriented along the Z axis
/gps/ene/type Mono #for monoenergetic: I=E
/gps/ene/mono 14. MeV #sets energy for monoenergetic sources

(I am using Geant4 v10.7)
Regards
Max

I can use G4GeneralParticleSource class to define the source particle through command or macro file,
I just hope to integrate the advantage of G4ParticleGun and G4GeneralParticleSource classes.

Have you looked at $G4INCLUDE/G4GeneralParticleSource.hh? You’ll see that there’s an interface you can use, with basic functions parallel to what’s in G4ParticleGun.

yes, i kown the energy and direction of the particle can be set by mac command, but it can not set by hardcode, so it is difficult to achieve complex source.

Did you look at the .hh file? If you are only throwing single particles, you can call functions in your C++ application to set the energy and direction.

I did not look at the .hh file, but i refered to HTML help document, there is no related functions about setting enegy and direction in G4GeneralParticleSource class, and the
inteligence of c++ did not display the related functions。

this is also an option:

G4UImanager* UImanager = G4UImanager::GetUIpointer();
UImanager->ApplyCommand("/gps/direction 0 0 1");
...

Whilst it’s not totally obvious, the key member of functions of G4GeneralParticleSource are (see the LXR browser for details)

class G4GeneralParticleSource : public G4VPrimaryGenerator
{
 public:
  void AddaSource (G4double);
        // Add a new particle gun with the specified strength
  inline G4SingleParticleSource* GetCurrentSource() const
        // Return the pointer to current particle gun
...

Now it’s correct that G4GeneralParticleSource doesn’t provide direct member functions to set energy/etc of the current source, but it’s always possible, in C++, to get a pointer to the current source and then access its position, angle, energy generators:

It’s also possible to see how the UI commands translate to calls to G4GeneralParticleSource through the implementation of its UI messenger class. As a general particle source, the setup isn’t going to be as simple as a standard fixed energy/direction particle gun, though it’s entirely possible to set up the GPS to do that.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.