source: trunk/source/processes/electromagnetic/lowenergy/test/fluoTest/src/XrayFluoPrimaryGeneratorAction.cc @ 1199

Last change on this file since 1199 was 1199, checked in by garnier, 15 years ago

nvx fichiers dans CVS

File size: 6.8 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//
27// $Id: XrayFluoPrimaryGeneratorAction.cc
28// GEANT4 tag $Name: xray_fluo-V03-02-00
29//
30// Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
31//
32// History:
33// -----------
34// 28 Nov 2001 Elena Guardincerri     Created
35//
36// -------------------------------------------------------------------
37
38#include "XrayFluoPrimaryGeneratorAction.hh"
39#include "G4DataVector.hh"
40#include "XrayFluoDetectorConstruction.hh"
41#include "XrayFluoPrimaryGeneratorMessenger.hh"
42#include "XrayFluoRunAction.hh"
43#include "G4Event.hh"
44#include "G4ParticleGun.hh"
45#include "G4ParticleTable.hh"
46#include "G4ParticleDefinition.hh"
47#include "Randomize.hh"
48#include "XrayFluoAnalysisManager.hh"
49#include "XrayFluoDataSet.hh"
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
52
53XrayFluoPrimaryGeneratorAction::XrayFluoPrimaryGeneratorAction(
54                                                               XrayFluoDetectorConstruction* XrayFluoDC)
55  :XrayFluoDetector(XrayFluoDC),rndmFlag("off"),
56   beam("off"),spectrum("off"),isoVert("off")
57{
58  G4int n_particle = 1;
59  particleGun  = new G4ParticleGun(n_particle);
60 
61  //create a messenger for this class
62  gunMessenger = new XrayFluoPrimaryGeneratorMessenger(this);
63  runManager = new XrayFluoRunAction();
64 
65  // default particle kinematic
66 
67  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
68  G4String particleName;
69  G4ParticleDefinition* particle
70    = particleTable->FindParticle(particleName="e-");
71  particleGun->SetParticleDefinition(particle);
72  particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
73 
74  particleGun->SetParticleEnergy(50.*MeV);
75  G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
76  particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
77 
78}
79
80
81//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
82
83XrayFluoPrimaryGeneratorAction::~XrayFluoPrimaryGeneratorAction()
84{
85  delete particleGun;
86  delete gunMessenger;
87  delete runManager;
88}
89
90//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91
92void XrayFluoPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
93{
94  //this function is called at the begining of event
95  //
96  G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ());
97  G4double y0 = 0.*cm, x0 = 0.*cm;
98  if (rndmFlag == "on")
99    {y0 = (XrayFluoDetector->GetSampleSizeXY())*(G4UniformRand()-0.5);
100    x0 = (XrayFluoDetector->GetSampleSizeXY())*(G4UniformRand()-0.5);
101    } 
102  particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
103 
104  //randomize starting point
105  if (beam == "on")
106    {
107      G4double radius = 0.5 * mm;
108      G4double rho = radius*std::sqrt(G4UniformRand());
109      G4double theta = 2*pi*G4UniformRand()*rad;
110      G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
111     
112      G4double y = rho * std::sin(theta);
113      G4double x = rho * std::cos(theta);
114     
115      particleGun->SetParticlePosition(G4ThreeVector(x,y,position));
116    }
117  //shoot particles according to a certain spectrum
118  if (spectrum =="on")
119    {
120      G4String particle =  particleGun->GetParticleDefinition()
121        ->GetParticleName();
122      if(particle == "proton"|| particle == "alpha")
123        {
124          G4DataVector* energies =  runManager->GetEnergies();
125          G4DataVector* data =  runManager->GetData();
126         
127          G4double sum = runManager->GetDataSum();
128          G4double partSum = 0;
129          G4int j = 0;
130          G4double random= sum*G4UniformRand();
131          while (partSum<random)
132            {
133              partSum += (*data)[j];
134              j++;
135            }
136         
137          particleGun->SetParticleEnergy((*energies)[j]);
138       
139        }
140      else if (particle == "gamma")
141        {
142          const XrayFluoDataSet* dataSet = runManager->GetGammaSet();
143         
144          G4int i = 0;
145          G4int id = 0;
146          G4double minEnergy = 0. * keV;
147          G4double particleEnergy= 0.;
148          G4double maxEnergy = 10. * keV;
149          G4double energyRange = maxEnergy - minEnergy;
150
151           while ( i == 0)
152            {
153              G4double random = G4UniformRand();
154             
155              G4double randomNum = G4UniformRand()*5.0E6;
156             
157              particleEnergy = random *  energyRange;
158             
159              if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
160                {
161                  i = 1;
162                 
163                }
164            }
165           particleGun->SetParticleEnergy(particleEnergy);
166        }
167    }
168 
169  if (isoVert == "on")
170    {
171      G4double rho = 1. *m;
172      //theta in [0;pi/2]
173      G4double theta = (pi/2)*G4UniformRand();
174      //phi in [-pi;pi]
175      G4double phi = (G4UniformRand()*2*pi)- pi;
176      G4double x = rho*std::sin(theta)*std::sin(phi);
177      G4double y = rho*std::sin(theta)*std::cos(phi);
178      G4double z = -(rho*std::cos(theta));
179      particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
180     
181      G4double Xdim = XrayFluoDetector->GetSampleSizeXY();
182      G4double Ydim = XrayFluoDetector->GetSampleSizeXY();
183     
184      G4double Dx = Xdim*(G4UniformRand()-0.5);
185     
186      G4double Dy = Ydim*(G4UniformRand()-0.5);
187     
188      particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z));
189     
190    }
191#ifdef G4ANALYSIS_USE
192
193  G4double partEnergy = particleGun->GetParticleEnergy();
194  XrayFluoAnalysisManager* analysis =  XrayFluoAnalysisManager::getInstance();
195  analysis->analysePrimaryGenerator(partEnergy/keV);
196
197#endif
198 
199  particleGun->GeneratePrimaryVertex(anEvent);
200}
201
202//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
203
Note: See TracBrowser for help on using the repository browser.