Message: Re: Gun more than 1 primary in PrimaryGeneratorAction Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Gun more than 1 primary in PrimaryGeneratorAction 

Forum: Event and Track Management
Re: Question Gun more than 1 primary in PrimaryGeneratorAction (lu luo)
Re: None Re: Gun more than 1 primary in PrimaryGeneratorAction (Rohin)
Date: 18 Jul, 2010
From: lu luo <lu luo>

Hi Rohin,

Thanks for your answer, I have already tried this method, My complete PrimaryGeneratorAction class is copied here :

#include "TestPrimaryGeneratorAction.hh"
#include "TestDetectorConstruction.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "globals.hh"
#include "Randomize.hh"

TestPrimaryGeneratorAction::TestPrimaryGeneratorAction(TestDetectorConstruction* detector)
{
  n_particle = 3;
  particleGun = new G4ParticleGun(n_particle);

  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4String particle;

  particleGun->SetParticleDefinition(particleTable->FindParticle(particle="gamma"));

  particleGun->SetParticlePosition(G4ThreeVector(-7.0*cm, 0.0*cm, 0.0*cm));
  G4ThreeVector v(1.0,0.0,0.0);
  particleGun->SetParticleMomentumDirection(v);
}

TestPrimaryGeneratorAction::~TestPrimaryGeneratorAction()
{
  delete particleGun;
}

void TestPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  for(int i=0;i<n_particle;i++){

		G4double energy = 40.0*G4UniformRand();
	    particleGun->SetParticleEnergy(energy*keV);
		particleGun->GeneratePrimaryVertex(anEvent);
  }

}

But the problem is:

When I activate /tracking/verbose 1 in the macro file, what I see is there are 9 gamma primary particles and not 3. The random number(which determine here the energy) is the same 3 by 3.

If I would like to gun 10^6 gamma, in fact I have to set n_particle= 10^3 with only 10^3 different random number.

I donít understand very well how work this class, but the method GeneratePrimaries is called 3 times(=n_particle) and GeneratePrimaryVertex 3 times again because it is in a loop.

How can I avoid this and gun 10^6 gamma with 10^6 different random energy?

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

1 None: Re: Gun more than 1 primary in PrimaryGeneratorAction   (Rohin - 18 Jul, 2010)
(_ Ok: Re: Gun more than 1 primary in PrimaryGeneratorAction   (lu luo - 18 Jul, 2010)
(_ Feedback: Re: Gun more than 1 primary in PrimaryGeneratorAction   (Gumplinger Peter - 19 Jul, 2010)
(_ None: Re: Gun more than 1 primary in PrimaryGeneratorAction   (lu luo - 19 Jul, 2010)
(_ Feedback: Re: Gun more than 1 primary in PrimaryGeneratorAction   (Gumplinger Peter - 19 Jul, 2010)
 Add Message Add Message
to: "Re: Gun more than 1 primary in PrimaryGeneratorAction"

 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 ]