Message: Trouble with particle gun/general particle source Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Trouble with particle gun/general particle source 

Forum: Particles
Date: 13 Oct, 2014
From: Chris Ferraioli <Chris Ferraioli>


I'm running geant4.9.4.p02 on a Scientific Linux 5 machine and I'm having some trouble setting the position, energy, etc. of my particle gun. I have attached my PrimaryGeneratorAction files below.

The problem I'm running into is that I cannot set my particle gun attributes within the PrimaryGeneratorAction file, though I can do so interactively using /gun/position commands. If I try to set the position in the PrimaryGeneratorEvent, I simply get a particle produced at the default 0,0,0 position of my detector. The reason this is an issue is that I'd like to set two (or more) particle guns in different positions to test detector response to multiple incident particles, but without the ability to control in my PrimaryGenerator, I am stuck. No other attributes can be set in PrimaryGeneratorEvent either - event energy, particle type, etc., all must be set interactively with /gun/ commands.

I've also tried using general particle source (currently commented out in the code below), but when I try to run a /gps command I am met with a "command not found" error.

Any help would be appreciated!

Cheers, Chris Ferraioli

------------ ExNO2PrimaryGeneratorAction.hh ------------

#ifndef ExN02PrimaryGeneratorAction_h
#define ExN02PrimaryGeneratorAction_h 1

#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
#include "G4ParticleGun.hh"
//#include "G4GeneralParticleSource.hh" #include "G4ThreeVector.hh"

class ExN02DetectorConstruction; class G4ParticleGun; //class G4GeneralParticleSource; class G4Event; class ExN02PrimaryGeneratorActionMessenger;

class ExN02PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction

    void GeneratePrimaries(G4Event*);
  G4ParticleGun* GetParticleGun() {return particleGun;};
//  G4GeneralParticleSource* GetParticleGun() {return particleGun;};

  void SetVxSmearing(G4ThreeVector);
  void SetVxPosition(G4ThreeVector);

    G4ParticleGun* particleGun;
//    G4GeneralParticleSource* particleGun;    
    ExN02DetectorConstruction* myDetector;
  ExN02PrimaryGeneratorActionMessenger* actMessenger;
  ExN02DetectorConstruction*         Detector;         

  G4int                         smearFlag, smearErea;
  G4double                      xVertex, yVertex, zVertex;
  G4double                      dRwidth;
  G4bool                        vertexDefined; 

------------ ------------

#include "ExN02PrimaryGeneratorAction.hh"
#include "ExN02DetectorConstruction.hh"
#include "G4Event.hh"
//#include "G4GeneralParticleSource.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "globals.hh"

                                               ExN02DetectorConstruction* myDC)
  G4int n_particle = 1;
  particleGun = new G4ParticleGun(n_particle);
//  particleGun = new G4GeneralParticleSource();

  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
  G4ParticleDefinition* particle = particleTable->FindParticle("neutron");


  G4double position = -0.5*(myDetector->GetWorldFullLength());

  delete particleGun;

void ExN02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)

 Add Message Add Message
to: "Trouble with particle gun/general particle source"

 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 ]