@@ -368,6 +368,8 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event) {
368368 const auto & primaryGeneratorInfo = restG4Metadata->GetGeant4PrimaryGeneratorInfo ();
369369 const string& spatialGeneratorTypeName = primaryGeneratorInfo.GetSpatialGeneratorType ().Data ();
370370 const auto spatialGeneratorTypeEnum = StringToSpatialGeneratorTypes (spatialGeneratorTypeName);
371+ const auto spatialGeneratorShapeEnum =
372+ StringToSpatialGeneratorShapes (primaryGeneratorInfo.GetSpatialGeneratorShape ().Data ());
371373 // Apparently not used. I comment to avoid compilation warning
372374 // Int_t nParticles = restG4Metadata->GetNumberOfSources();
373375
@@ -387,7 +389,14 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event) {
387389 }
388390 // Set the particle(s)' position, multiple particles generated from multiple sources shall always have a
389391 // same origin
390- SetParticlePosition ();
392+
393+ // if sphere surface generator
394+ if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::SURFACE &&
395+ spatialGeneratorShapeEnum == SpatialGeneratorShapes::SPHERE) {
396+ // DO NOTHING! This is set elsewhere
397+ } else {
398+ SetParticlePosition ();
399+ }
391400
392401 for (int i = 0 ; i < restG4Metadata->GetNumberOfSources (); i++) {
393402 vector<TRestGeant4Particle> particles = restG4Metadata->GetParticleSource (i)->GetParticles ();
@@ -470,6 +479,30 @@ void PrimaryGeneratorAction::SetParticleDirection(Int_t particleSourceIndex,
470479 const auto sourceDirection = source->GetDirection ();
471480 G4ThreeVector direction = {sourceDirection.X (), sourceDirection.Y (), sourceDirection.Z ()};
472481
482+ const auto & primaryGeneratorInfo = restG4Metadata->GetGeant4PrimaryGeneratorInfo ();
483+
484+ const string& spatialGeneratorTypeName = primaryGeneratorInfo.GetSpatialGeneratorType ().Data ();
485+ const auto spatialGeneratorTypeEnum = StringToSpatialGeneratorTypes (spatialGeneratorTypeName);
486+ const auto spatialGeneratorShapeEnum =
487+ StringToSpatialGeneratorShapes (primaryGeneratorInfo.GetSpatialGeneratorShape ().Data ());
488+
489+ if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::SURFACE &&
490+ spatialGeneratorShapeEnum == SpatialGeneratorShapes::SPHERE) {
491+ SetParticlePosition ();
492+
493+ const TVector3 sourcePositionReference = {0 , 0 , 0 }; // TODO: use the source position
494+ const TVector3 particlePosition = {fParticleGun .GetParticlePosition ().x (),
495+ fParticleGun .GetParticlePosition ().y (),
496+ fParticleGun .GetParticlePosition ().z ()};
497+
498+ const TVector3 directionSphere = (sourcePositionReference - particlePosition).Unit ();
499+ direction = {directionSphere.X (), directionSphere.Y (), directionSphere.Z ()};
500+ }
501+
502+ const TVector3 particlePosition = {fParticleGun .GetParticlePosition ().x (),
503+ fParticleGun .GetParticlePosition ().y (),
504+ fParticleGun .GetParticlePosition ().z ()};
505+
473506 const string angularDistTypeName = source->GetAngularDistributionType ().Data ();
474507 const auto angularDistTypeEnum = StringToAngularDistributionTypes (angularDistTypeName);
475508
0 commit comments