source: trunk/examples/extended/analysis/A01/src/A01PrimaryGeneratorAction.cc @ 807

Last change on this file since 807 was 807, checked in by garnier, 16 years ago

update

File size: 4.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26// $Id: A01PrimaryGeneratorAction.cc,v 1.5 2006/06/29 16:33:05 gunter Exp $
27// --------------------------------------------------------------
28//
29
30#include "A01PrimaryGeneratorAction.hh"
31#include "A01PrimaryGeneratorMessenger.hh"
32
33#include "G4Event.hh"
34#include "G4ParticleGun.hh"
35#include "G4ParticleTable.hh"
36#include "G4ParticleDefinition.hh"
37#include "Randomize.hh"
38
39A01PrimaryGeneratorAction::A01PrimaryGeneratorAction()
40{
41  momentum = 1000.*MeV;
42  sigmaMomentum = 50.*MeV;
43  sigmaAngle = 2.*deg;
44  randomizePrimary = true;
45
46  G4int n_particle = 1;
47  particleGun  = new G4ParticleGun(n_particle);
48
49  //create a messenger for this class
50  gunMessenger = new A01PrimaryGeneratorMessenger(this);
51
52  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
53  G4String particleName;
54  positron = particleTable->FindParticle(particleName="e+");
55  muon = particleTable->FindParticle(particleName="mu+");
56  pion = particleTable->FindParticle(particleName="pi+");
57  kaon = particleTable->FindParticle(particleName="kaon+");
58  proton = particleTable->FindParticle(particleName="proton");
59
60  // default particle kinematics
61  particleGun->SetParticlePosition(G4ThreeVector(0.,0.,-8.*m));
62  particleGun->SetParticleDefinition(positron);
63}
64
65A01PrimaryGeneratorAction::~A01PrimaryGeneratorAction()
66{
67  delete particleGun;
68  delete gunMessenger;
69}
70
71void A01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
72{
73  G4ParticleDefinition* particle;
74
75  if(randomizePrimary)
76  {
77    /////////////////////////////////////////////G4int i = (int)(5.*G4UniformRand());
78    G4int i = (int)(2.*G4UniformRand());
79    switch(i)
80    {
81      case 0:
82        particle = positron;
83        break;
84      case 1:
85        particle = muon;
86        break;
87      case 2:
88        particle = pion;
89        break;
90      case 3:
91        particle = kaon;
92        break;
93      default:
94        particle = proton;
95        break;
96    }
97    particleGun->SetParticleDefinition(particle);
98  }
99  else
100  {
101    particle = particleGun->GetParticleDefinition();
102  }
103
104  G4double pp = momentum + (G4UniformRand()-0.5)*sigmaMomentum;
105  G4double mass = particle->GetPDGMass();
106  G4double Ekin = std::sqrt(pp*pp+mass*mass)-mass;
107  particleGun->SetParticleEnergy(Ekin);
108
109  G4double angle = (G4UniformRand()-0.5)*sigmaAngle;
110  particleGun->SetParticleMomentumDirection(G4ThreeVector(std::sin(angle),0.,std::cos(angle)));
111
112  particleGun->GeneratePrimaryVertex(anEvent);
113}
114
Note: See TracBrowser for help on using the repository browser.