Having trouble defining multiple sources

I am having difficulties defining multiple sources in a macro file with gps. Specifically I want multiple mono-energetic sources, but only the last defined source seems to be fired.

For example, the following code results in only 500keV electrons being fired:

/run/initialize

/gps/particle e-
/gps/energy 300 keV
/gps/pos/centre 0 0 -4
/gps/direction 0 0 1

/gps/source/add 1.
/gps/particle e-
/gps/energy 500 keV
/gps/pos/centre 0 0 -4
/gps/direction 0 0 1

/gps/source/multiplevertex true
/run/beamOn 100

Similarly, test34.mac in exgps fails in the same way, only firing particles from the last defined source. Is there something I need to enable in my actual code, not just in a macro file?

Another problem I’m encountering is an inability to set the name of an output file in a macro file. I would have thought /analysis/setFileName would work, but for my code I run into exceptions of the form
issued by : G4TNtupleManager::FillNtupleTColumn
ntupleId 0 does not exist.

I’ve checked runAction, and the analysisManager does not seem to go active- I thought I could use something like this:
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
if ( analysisManager->IsActive() ) {
analysisManager->OpenFile();
}

Normally I would do analysisManager->OpenFile(fileName); , but I want to run a bunch of different macro files and compare the results of each so I can’t have them all going to the same filename.

Perhaps this deserves a different thread, but it’s an issue I encountered while trying to adapt exgps as well so I included it here.

I had similar problems trying to get the test#.Mac to run in the exgps example. For my code to work, I used a different example. Specifically the LXe example. There I have my particle_sources.mac file nested in a vis.mac file which is in the main file titled LXe.cc there will be section that looks like this:

if (ui) {
//interactive mode
UImanager->ApplyCommand("/control/execute vis.mac");
if (ui->IsGUI()) {
UImanager->ApplyCommand("/control/execute gui.mac");
}
ui->SessionStart();
delete ui;
} else {
//batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command+fileName);
}

// job termination
delete visManager;
delete runManager;
return 0;
}
This code above has:
UImanager->ApplyCommand("/control/execute vis.mac");
where vis.mac is setting up the visualization. At the bottom go this Mac file there is a line:

/control/execute photon.mac

photon.mac is my GPS source file and it looks a lot like yours.

/run/initialize

/gps/particle e-
/gps/pos/type Point
/gps/pos/centre 100 -100 100 cm
/gps/ang/type iso
/gps/ang/maxtheta 1 deg
/gps/ang/rot1 1 1 0
/gps/ang/rot2 1 2 1
/gps/ene/type Mono
/gps/ene/mono 1 MeV

/gps/source/add 1
/gps/particle e-
/gps/pos/type Point
/gps/pos/centre 50 -100 100 cm
/gps/ang/type iso
/gps/ang/maxtheta 1 deg
/gps/ang/rot1 2 0 -1
/gps/ang/rot2 2 1 0
/gps/ene/type Mono
/gps/ene/mono 1 MeV

/gps/source/add 1
/gps/particle e-
/gps/pos/type Point
/gps/pos/centre 0 -100 100 cm
/gps/ang/type iso
/gps/ang/maxtheta 1 deg
/gps/ang/rot1 0 -1 -1
/gps/ang/rot2 1 0 0
/gps/ene/type Mono
/gps/ene/mono 1 MeV

/gps/source/add 1
/gps/particle e-
/gps/pos/type Point
/gps/pos/centre -50 -100 100 cm
/gps/ang/type iso
/gps/ang/maxtheta 1 deg
/gps/ang/rot1 2 -1 0
/gps/ang/rot2 2 0 1
/gps/ene/type Mono
/gps/ene/mono 1 MeV

/gps/source/add 1
/gps/particle e-
/gps/pos/type Point
/gps/pos/centre -100 -100 100 cm
/gps/ang/type iso
/gps/ang/maxtheta 1 deg
/gps/ang/rot1 1 2 3
/gps/ang/rot2 -5 4 -1
/gps/ene/type Mono
/gps/ene/mono 1 MeV

/gps/source/multiplevertex true
/tracking/verbose 0

/run/beamOn 10

It produces multiple sauces as show in the image below.

Ok, I think I’ve figured out why I’m having this issue. I’m fairly certain all the particles are firing, it’s just that only the last group fired is saved by the analysis manager- I am not sure why, as it seems that the analysis manager is only instantiated once.

Your example arthur definitely fires from multiple sources and I can confirm that visually, but in my code it also only saves the last defined source to a csv.