Message: Updating primary particle position Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Updating primary particle position 

Forum: Particles
Date: 12 Jul, 2011
From: Charles Smiling <Charles Smiling>

Hi all,

I am stuck. I am modifying my geometry through a messenger. Since the geometry is moved (just like moving the linac), the origin of the primary particle must be changed. All I want to do is move the origin and momentum direction of the primary particles according to the transformation applied to the detector.

I started with a simple translation in one direction but to my frustration, the origin of the particle is not moving. Below is essentially the code with unnecessary stuffs removed.

!!!HEADER
class ExN01PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
  static ExN01PrimaryGeneratorAction* fManager;
   G4ParticleGun* particleGun;
   G4double* x_pos, *y_pos, *z_pos;
   G4double x, y, z;

  public:	
    ExN01PrimaryGeneratorAction();
    ~ExN01PrimaryGeneratorAction();
    static ExN01PrimaryGeneratorAction* getInstance();
   void PG_move_z(G4double val);
   void GeneratePrimaries(G4Event* anEvent);
};

//!!!!!!!SOURCE
ExN01PrimaryGeneratorAction* ExN01PrimaryGeneratorAction::fManager = 0;
ExN01PrimaryGeneratorAction* ExN01PrimaryGeneratorAction::getInstance()
{
	if(!fManager) {  fManager = new ExN01PrimaryGeneratorAction ();}
	return fManager;
}

ExN01PrimaryGeneratorAction::ExN01PrimaryGeneratorAction()
{
  x = -200; y = 0; z = 0; x_pos = &x; y_pos = &y; z_pos = &z;
  particleGun = new G4ParticleGun(1);
  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4String particleName;
particleGun->SetParticleDefinition(particleTable->FindParticle(particleName="e-"));
  particleGun->SetParticleEnergy(6.0*MeV);
}

void ExN01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  particleGun->SetParticlePosition(G4ThreeVector(x, y, z));
  particleGun->SetParticleMomentumDirection(G4ThreeVector (100, 1,1));/
  particleGun->GeneratePrimaryVertex(anEvent);
}

           IMPORTANT!!!!!!!
void ExN01PrimaryGeneratorAction :: PG_move_z(G4double val) { *z_pos +=  val; cout<<val<<endl;}

The last PG_move_z() function is called from the detector construction and the aim is to move the particle origin in the z-direction. Note that "*z_pos" is pointing to z. The cout statement shows the correct value of val, indicating that this function is correctly called, however the origin of the source stays frustratingly the same. What I'm I doing wrong. Any suggestions? I will also appreciate it if the suggestion includes rotation of the origin and momentum direction, but any contribution is welcome.

Thanks, Charles

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

1 Feedback: Re: Updating primary particle position   (Gumplinger Peter - 12 Jul, 2011)
1 None: Re: Updating primary particle position   (Charles Smiling - 12 Jul, 2011)
2 None: Re: Updating primary particle position   (Charles Smiling - 12 Jul, 2011)
2 Ok: Re: Updating primary particle position   (Charles Smiling - 13 Jul, 2011)
 Add Message Add Message
to: "Updating primary particle position"

 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 ]