Message: Re: Altering Example TestEm1 to use GPS to simulate positron source emission Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Altering Example TestEm1 to use GPS to simulate positron source emission  

Forum: Particles
Re: Question Altering Example TestEm1 to use GPS to simulate positron source emission (Matthew Middione)
Re: None Re: Altering Example TestEm1 to use GPS to simulate positron source emission (Vladimir IVANTCHENKO )
Date: 27 Jun, 2007
From: Matthew Middione <middionematt@csufresno.edu>

Thanks very much for the advice, that is a splendid idea that I have 
implemented.  The GPS Manual states:
G4GeneralParticleSource is used exactly the same way as G4ParticleGun 
in a Geant4 application. In existing application one can simply change 
yourPrimaryGeneratorAction by globally replacing "G4ParticleGun" with 
"G4GeneralParticleSource".  Below is the code for the new test I created,
which is a hybrid of TestEm1 and exGPS to allow for the GPS to take effect:

#include "PrimaryGeneratorAction.hh"

#include "DetectorConstruction.hh"
#include "PrimaryGeneratorMessenger.hh"

#include "G4Event.hh"
#include "G4GeneralParticleSource.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "globals.hh"


PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* DC)
:Detector(DC)					       
{
  particleGun  = new G4GeneralParticleSource(); */Change implemented here/*
  SetDefaultKinematic(1);
  rndmBeam = 0.;
    
  //create a messenger for this class
  gunMessenger = new PrimaryGeneratorMessenger(this);  
}

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

void PrimaryGeneratorAction::SetDefaultKinematic(G4int front)
{
  G4ParticleDefinition* particle
           = G4ParticleTable::GetParticleTable()->FindParticle("e-");
  particleGun->SetParticleDefinition(particle);
  particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
  particleGun->SetParticleEnergy(100*MeV);
  G4double position = 0.*cm;
  if (front) position = -0.5*(Detector->GetSize());
  particleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm));
}

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  //this function is called at the begining of event
  //
  //randomize the beam, if requested.
  if (rndmBeam > 0.) 
    {
      G4ThreeVector oldPosition = particleGun->GetParticlePosition();    
      G4double rbeam = 0.5*(Detector->GetSize())*rndmBeam;
      G4double x0 = oldPosition.x();
      G4double y0 = oldPosition.y() + (2*G4UniformRand()-1.)*rbeam;
      G4double z0 = oldPosition.z() + (2*G4UniformRand()-1.)*rbeam;
      particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
      particleGun->GeneratePrimaryVertex(anEvent);
      particleGun->SetParticlePosition(oldPosition);      
    }
  else  particleGun->GeneratePrimaryVertex(anEvent); 
}

When compiling this is the error message I recieve:

Making dependency for file src/PrimaryGeneratorAction.cc ...
Compiling PrimaryGeneratorAction.cc ...
src/PrimaryGeneratorAction.cc: In constructor `PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction*)':
src/PrimaryGeneratorAction.cc:15: error: cannot convert `G4GeneralParticleSource*' to `G4ParticleGun*' in assignment
src/PrimaryGeneratorAction.cc: In member function `virtual void PrimaryGeneratorAction::GeneratePrimaries(G4Event*)':
src/PrimaryGeneratorAction.cc:50: error: `G4UniformRand' was not declared in this scope
make: *** [/home/public/Desktop/TestPR/tmp/Linux-g++/MyTest/PrimaryGeneratorAction.o] Error 1

I am a bit stuck and any help regarding how I could fix this error would
be much appreciated.

Thanks,
Matthew Middione

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

1 Note: Re: Altering Example TestEm1 to use GPS to simulate positron source emission   (Matthew Middione - 28 Jun, 2007)
(_ Question: Re: Altering Example TestEm1 to use GPS to simulate positron source emission   (Rahul Shah - 07 Apr, 2009)
(_ Feedback: Re: Altering Example TestEm1 to use GPS to simulate positron source emission   (Giovanni Santin - 07 Apr, 2009)
 Add Message Add Message
to: "Re: Altering Example TestEm1 to use GPS to simulate positron source emission "

 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 ]