Message: GENERATION OF SPECTRUM IN PRIMARYGENERATORACTION Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question GENERATION OF SPECTRUM IN PRIMARYGENERATORACTION 

Keywords: PrimaryGeneratorAction, Spectrum input
Forum: Event and Track Management
Date: 04 Mar, 2008
From: Francisco <Francisco>

Hi I have a problem with PrimaryGeneratorAction. I have a file with a spectrum first column is Energy and second is NofParticles. The code works well for a small number of particles. For the following code the program crashes in the third line. Can someone give me some help?

PrimaryGeneratorAction::PrimaryGeneratorAction()
{
  G4int n_particle = 1; 
  particleGun = new G4ParticleGun(n_particle);
  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4String particleName;
  particleGun->SetParticleDefinition(particleTable->FindParticle(particleName="gamma"));
  rBeam   = 0.65*cm; 
}
PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
  delete particleGun;
}

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
   ifstream indata;                           
   G4double Energy;
   G4int NofParticles;                                 

  indata.open("/g4work/examples/extended/electromagnetic/TestEm4/spectrum30keV-1mA.dat");                  
   if(!indata) {                            
      G4cerr << "Error: file could not be opened" << G4endl;
      exit(1);
   }
   G4cout << "GIVE THE NUMBER OF ENERGIES OF THE SPECTRUM: " << G4endl; 
   G4int N;
   G4cin >> N; 

   for (G4int j=0; j<N ; j++) {
     indata >> Energy;
     indata >> NofParticles; 

     G4int i=0;
        while (i < NofParticles) {   
	 i++;

	   G4double y0 = 0.5*cm;
           G4double beam  = rBeam;
           G4double x0 =  (2*G4UniformRand()-1.)*rBeam;
           G4double z0 = (2*G4UniformRand()-1.)*rBeam;
           particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
           particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,-1.,0.));
           particleGun->SetParticleEnergy(Energy*keV);
           particleGun->GeneratePrimaryVertex(anEvent);        
	 }
    }

indata.close(); }

This is a piece of the spectrum where it crashes: 9 keV- 15529/ 10 keV- 65569/ 11 keV- 1359686/

Thanks in advance

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

1 Feedback: Re: GENERATION OF SPECTRUM IN PRIMARYGENERATORACTION   (Peter Gumplinger - 06 Mar, 2008)
(_ None: Re: GENERATION OF SPECTRUM IN PRIMARYGENERATORACTION   (Francisco - 07 Mar, 2008)
(_ None: Re: GENERATION OF SPECTRUM IN PRIMARYGENERATORACTION   (Francisco - 11 Mar, 2008)
 Add Message Add Message
to: "GENERATION OF SPECTRUM 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 ]