Message: GeneralParticleSource ignoring particle position given in GeneratePrimaries Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question GeneralParticleSource ignoring particle position given in GeneratePrimaries 

Forum: Particles
Date: 13 Feb, 2017
From: <php1ic>

I am trying to randomly distribute my source position in a spherical shell using G4GeneralParticleSource. I generate (x,y,z) and the primary like this:

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  //Random position in a spherical shell
  G4double R3 = Rmin3 + G4UniformRand()*(Rmax3 - Rmin3);
  G4double R  = pow(R3, 1./3);

  G4double cosTheta = 2.0*G4UniformRand() - 1;
  G4double sinTheta = sqrt(1.0 - cosTheta*cosTheta);
  G4double phi      = 2.0*CLHEP::pi*G4UniformRand();

  G4double x0 = R*sinTheta*std::cos(phi);
  G4double y0 = R*sinTheta*std::sin(phi);
  G4double z0 = R*cosTheta;

  fParticleSource->SetParticlePosition(G4ThreeVector(x0,y0,z0));

  G4cout << "Given position: " << x0 << " | " << y0 << " | " << z0 << G4endl;

  fParticleSource->GeneratePrimaryVertex(anEvent);
}

With Rmin3 (30.0cm) and Rmax3 (35.0cm) being set in the constructor. However the SetParticlePosition appears to be ignored, as when I /run/beamOn I get:

G4WT0 > Given position: -117.018 | 251.985 | 175.319
G4WT0 > 
G4WT0 > *********************************************************************************************************
G4WT0 > * G4Track Information:   Particle = geantino,   Track ID = 1,   Parent ID = 0
G4WT0 > *********************************************************************************************************
G4WT0 > 
G4WT0 > Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  NextVolume ProcName
G4WT0 >     0        0        0        0         1        0        0         0       World initStep
G4WT0 >     1        0        0     -300         1        0      300       300      Source Transportation
G4WT0 >     2        0        0     -350         1        0       50       350       World Transportation
G4WT0 >     3        0        0 -1.5e+03         1        0 1.15e+03   1.5e+03  OutOfWorld Transportation

If I switch to G4ParticleGun, the initial position is taken from the G4ThreeVector passed to SetParticlePosition. Is this the wrong method of implementing the initial position of a particle for G4GeneralParticleSource?

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Feedback: Re: GeneralParticleSource ignoring particle position given in GeneratePrimaries   (php1ic - 13 Feb, 2017)
(_ None: Re: GeneralParticleSource ignoring particle position given in GeneratePrimaries   (php1ic - 20 Feb, 2017)
 Add Message Add Message
to: "GeneralParticleSource ignoring particle position given in GeneratePrimaries"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]