source: trunk/source/geometry/solids/test/OpticalEscape/src/AXPETPrimaryGeneratorAction.cc @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 4.5 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: AXPETPrimaryGeneratorAction.cc,v 1.1 2008/09/03 13:34:03 gcosmo Exp $
27// ------------------------------------------------------------
28// Geant4 class implementation file
29//
30// 03/09/2008, by T.Nikitina
31// ------------------------------------------------------------
32
33#include "AXPETPrimaryGeneratorAction.hh"
34#include "AXPETPrimaryGeneratorMessenger.hh"
35
36#include "Randomize.hh"
37
38#include "G4Event.hh"
39#include "G4ParticleGun.hh"
40#include "G4ParticleTable.hh"
41#include "G4ParticleDefinition.hh"
42
43AXPETPrimaryGeneratorAction::AXPETPrimaryGeneratorAction()
44{
45
46  G4int n_particle = 1;
47  particleGun = new G4ParticleGun(n_particle);
48 
49  //create a messenger for this class
50  gunMessenger = new AXPETPrimaryGeneratorMessenger(this);
51 
52  //default kinematic
53  //
54  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
55  G4ParticleDefinition* particle = particleTable->FindParticle("e-");
56
57  particleGun->SetParticleDefinition(particle);
58  particleGun->SetParticleTime(0.0*ns);
59
60  particleGun->SetParticlePosition(G4ThreeVector(0.0*cm,0.0*mm,15.0*cm));
61  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
62  particleGun->SetParticleEnergy(20.0*keV);
63}
64
65AXPETPrimaryGeneratorAction::~AXPETPrimaryGeneratorAction()
66{
67  delete particleGun;
68  delete gunMessenger;
69}
70
71void AXPETPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
72{
73
74  G4double sigma_xy = 10.*mm;//2.5;// ~6 mm (FWHM)
75  G4double x = G4RandGauss::shoot(0.,sigma_xy);
76  G4double y = G4RandGauss::shoot(0.,sigma_xy);
77  G4double z = G4RandGauss::shoot(0.,sigma_xy);//15.0*mm;
78  G4ThreeVector dir;
79  dir=(G4ThreeVector(0,0,0.0*mm)-G4ThreeVector(x,y,z));
80  dir=dir/dir.mag();
81  particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
82  particleGun->SetParticleMomentumDirection(dir);
83  G4cout << x << '\t' << y << '\t' << z << " position [mm] of Primaries" << G4endl;
84  G4cout << dir.x()<<'\t'<<dir.y()<<'\t'<<dir.z()<<'\t' <<" direction of Primaries" << G4endl;
85  particleGun->GeneratePrimaryVertex(anEvent);
86}
87
88void AXPETPrimaryGeneratorAction::SetOptPhotonPolar()
89{
90 G4double angle = G4UniformRand() * 360.0*deg;
91 SetOptPhotonPolar(angle);
92}
93
94void AXPETPrimaryGeneratorAction::SetOptPhotonPolar(G4double angle)
95{
96 if (particleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton")
97   {
98     G4cout << "--> warning from PrimaryGeneratorAction::SetOptPhotonPolar() :"
99               "the particleGun is not an opticalphoton" << G4endl;
100     return;
101   }
102               
103 G4ThreeVector normal (1., 0., 0.);
104 G4ThreeVector kphoton = particleGun->GetParticleMomentumDirection();
105 G4ThreeVector product = normal.cross(kphoton); 
106 G4double modul2       = product*product;
107 
108 G4ThreeVector e_perpend (0., 0., 1.);
109 if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product; 
110 G4ThreeVector e_paralle    = e_perpend.cross(kphoton);
111 
112 G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend;
113 particleGun->SetParticlePolarization(polar);
114}
115
Note: See TracBrowser for help on using the repository browser.