diff --git a/bind/example.py b/bind/example.py new file mode 100644 index 0000000..2865bed --- /dev/null +++ b/bind/example.py @@ -0,0 +1,11 @@ + +from bindings import ConstructionWrapper, SystemBuilder + +cw = ConstructionWrapper() +cw.addLayer(10,"G4_Si",True) +cw.addLayer(1,"G4_Pb",False) +cw.addLayer(10,"G4_Si",False) + +sb = SystemBuilder() +sb.init(cw) +sb.run_batch(100, "e-", 1000, 5000) \ No newline at end of file diff --git a/src/PrimaryGeneratorAction.cc b/src/PrimaryGeneratorAction.cc index 88b0477..a053701 100644 --- a/src/PrimaryGeneratorAction.cc +++ b/src/PrimaryGeneratorAction.cc @@ -83,6 +83,11 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) auto particleDefinition = G4ParticleTable::GetParticleTable()->FindParticle(partSpecies); + if(particleDefinition == nullptr){ + G4cout << "Particle " << partSpecies << " not found" << G4endl; + throw std::runtime_error("Particle not found"); + return; + } fParticleGun->SetParticleDefinition(particleDefinition); fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); fParticleGun->SetParticleEnergy(partEnergy*MeV); diff --git a/src/SystemBuilder.cc b/src/SystemBuilder.cc index 6e8cf91..4814791 100644 --- a/src/SystemBuilder.cc +++ b/src/SystemBuilder.cc @@ -60,7 +60,7 @@ void SystemBuilder::run_gui(){ } void SystemBuilder::run_batch(int nEvents, std::string partSpecies, double minEnergy, double maxEnergy){ - actionInitialization->setGeneratorProperties(minEnergy, maxEnergy, partSpecies); + actionInitialization->setGeneratorProperties(minEnergy, maxEnergy, (G4String)partSpecies); UImanager->ApplyCommand("/run/initialize"); runManager->BeamOn(nEvents); } \ No newline at end of file