Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!
Geant4 Version:
Operating System:
Compiler/Version:
CMake Version:
Hello all,
I am sorry, but I could not find clear answer on my question:
If I should to use G4AutoLock feature in primary generator action in a multi-threaded application when I use the particle energy spectrum from file? Or it will be unsafe without it?
Many thanks in advance,
Vyacheslav
P.S. Example of the code…
G4Mutex myPrimGenMutex = G4MUTEX_INITIALIZER;
PrimaryGeneratorAction::PrimaryGeneratorAction() : G4VUserPrimaryGeneratorAction()
{
G4AutoLock lock(&myPrimGenMutex);
// default particle kinematic
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition* electronDef = particleTable->FindParticle(“e-”); //gamma, e-, neutron, proton, opticalphoton
//
fGPS = new G4GeneralParticleSource();
…
fGPS->GetCurrentSource()->SetParticleDefinition(electronDef);
//// set energy distribution
G4SPSEneDistribution* electronEnergy = fGPS->GetCurrentSource()->GetEneDist();
electronEnergy->SetEnergyDisType(“Arb”);
//Electron spectrum
electronEnergy->ArbEnergyHistoFile(“Spectrum1.txt”);
//
//The only valid arguments are Lin, Log, Exp or Spline.
electronEnergy->ArbInterpolate(“Lin”);
…
}
PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
G4AutoLock lock(&myPrimGenMutex);
delete fGPS;
}
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
G4AutoLock lock(&myPrimGenMutex);
//Generate primary particle
fGPS->GeneratePrimaryVertex(anEvent);
}