Is there a way to access GeneralParticleSource parameters (radius, etc) in my UserRunAction so that they can be written to the output file? I’ve been looking at the documentation and can’t seem to figure out an easy way, so wanted to inquire here if anyone has advice.
It seems that the G4GeneralParticleSource has a GetCurrentSource() member function that returns a G4SingleParticleSource*, which in turn has a GetPosDist() (as well as GetAngDist() and GetEneDist()) member function, which returns a G4SPSPosDistribution* that has a GetRadius() function, as well as other getters for different settings (HalfX, HalfY etc.).
I’ve never used this myself, but it should be possible in the BeginOfRunAction to access this information using these functions.
However I wouldn’t use this to write to the output file, instead I prefer to write a messenger class for the RunAction that can pass this (and more) information. The upside of this approach is that you can be more general in the information contained in the output. The downside is that you have to ensure you update all commands so that things don’t get misnamed, but if you use a script to generate your macro files this problem is alleviated.
From the GPS object, you can retrieve the current single particle source with the method GetCurrentSource [1].
From the single GPS, you can access the objects that store the position distribution, angular distribution and energy distribution [2]:
inline G4SPSPosDistribution* GetPosDist() const { return posGenerator; }
// Return a pointer to the position distribution generator
inline G4SPSAngDistribution* GetAngDist() const { return angGenerator; }
// Return a pointer to the angular distribution generator
inline G4SPSEneDistribution* GetEneDist() const { return eneGenerator; }
// Return a pointer to the energy distribution generator
From the G4SPSPosDistribution for example, you may obtain the parameters that you were looking for [3]
There is however a corner case which I believe it is not contemplated in the current status: a GPS may be made up of several single GPS. One could configure the mother GPS to trigger all the single GPS at the same time. I will open a bugzilla ticket to crosscheck. I hope that is not your case.
Thanks for your input! I’m able to access GPS info in EndOfRunAction, but there seems to be a segmentation fault after executing EndOfRunAction that I can’t quite figure out.
I accessed GPS in my run action via:
auto rMan = G4RunManager::GetRunManager();
auto pg = rMan->GetUserPrimaryGeneratorAction();
auto source = dynamic_cast<const SimPrimaryGenerator*>(pg);
Which doesn’t throw any errors unless accessing info like below:
Which thread is throwing the segfault? Unless you included your PrimaryGeneratorAction in ActionInitialization::BuildForMaster(), the master thread isn’t going to have a primary generator action.
You can protect your code against this using if (source).