Message: About G4ParticleGun Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question About G4ParticleGun 

Forum: Event and Track Management
Date: 24 Nov, 2009
From: Evgenya <Evgenya>

Good afternoon!
 
I need to play energy of gamma under the following law: E=10/sqrt(1-63*u/64),
u-random number from 0 to 1. And  I should receive a spectrum of the allocated energy in the detector volume.

I do it so:

#include "PrimaryGeneratorAction.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4RandomDirection.hh"

#include "G4Gamma.hh"
#include "Randomize.hh"
#include "globals.hh"
#include <cmath>
#include <fstream>


PrimaryGeneratorAction::PrimaryGeneratorAction()

{
 particleGun = new G4ParticleGun(1);
 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
 G4ParticleDefinition* gamma = particleTable->FindParticle("gamma");
 particleGun->SetParticleDefinition(gamma);
}

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

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* Event)
{

 G4double E[50];
 G4double rnd[50];
 G4double Xc = -130 * mm / 2   + 130 *  mm * G4UniformRand();
 G4double Yc = -130 *  mm / 2  + 130 *  mm * G4UniformRand(); 

for (int i=0; i<50; i++) 
 {

   rnd[i]= G4UniformRand();
   E[i] = 10/(std::sqrt(1.0-63.0*rnd[i]/64.0));
   particleGun->SetParticleEnergy(E[i]*keV);
 
   particleGun->SetParticlePosition(G4ThreeVector(Xc, Yc, -5.0*cm));
 
   G4double cosThetaa= 1;
   G4double sinThetaa = sqrt(1 - cosThetaa*cosThetaa);
   particleGun -> SetParticleMomentumDirection(G4ThreeVector(0, sinThetaa, cosThetaa));

   particleGun -> GeneratePrimaryVertex(Event);
  }
}

But i receive not that that is necessary. 

Please help me. Where is my mistake?

Thanks, Evgenia.

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

1 Feedback: Re: About G4ParticleGun   (Gumplinger Peter - 25 Nov, 2009)
(_ None: Re: About G4ParticleGun   (Evgenya - 26 Nov, 2009)
 Add Message Add Message
to: "About G4ParticleGun"

 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 ]