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] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/xray_fluorescence/src/XrayFluoPlanePrimaryGeneratorAction.cc (Version 11.3.0) and /examples/advanced/xray_fluorescence/src/XrayFluoPlanePrimaryGeneratorAction.cc (Version 10.6.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 //                                                 27 //
 28 // Author: Alfonso Mantero (Alfonso.Mantero@ge     28 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it)
 29 //                                                 29 //
 30 // History:                                        30 // History:
 31 // -----------                                     31 // -----------
 32 // 02 Sep 2003 Alfonso Mantero created             32 // 02 Sep 2003 Alfonso Mantero created
 33 //                                                 33 //
 34 // -------------------------------------------     34 // -------------------------------------------------------------------
 35                                                    35 
 36 #include "XrayFluoPlanePrimaryGeneratorAction.     36 #include "XrayFluoPlanePrimaryGeneratorAction.hh"
 37 #include "XrayFluoPlaneDetectorConstruction.hh     37 #include "XrayFluoPlaneDetectorConstruction.hh"
 38 #include "XrayFluoPlanePrimaryGeneratorMesseng     38 #include "XrayFluoPlanePrimaryGeneratorMessenger.hh"
 39 #include "XrayFluoRunAction.hh"                    39 #include "XrayFluoRunAction.hh"
 40 #include "XrayFluoAnalysisManager.hh"              40 #include "XrayFluoAnalysisManager.hh"
 41 #include "XrayFluoDataSet.hh"                      41 #include "XrayFluoDataSet.hh"
 42 #include "G4PhysicalConstants.hh"                  42 #include "G4PhysicalConstants.hh"
 43 #include "G4SystemOfUnits.hh"                      43 #include "G4SystemOfUnits.hh"
 44 #include "G4UnitsTable.hh"                         44 #include "G4UnitsTable.hh"
 45 #include "G4DataVector.hh"                         45 #include "G4DataVector.hh"
 46 #include "G4Event.hh"                              46 #include "G4Event.hh"
 47 #include "G4ParticleGun.hh"                        47 #include "G4ParticleGun.hh"
 48 #include "G4ParticleTable.hh"                      48 #include "G4ParticleTable.hh"
 49 #include "G4ParticleDefinition.hh"                 49 #include "G4ParticleDefinition.hh"
 50 #include "Randomize.hh"                            50 #include "Randomize.hh"
 51                                                    51 
 52 //....oooOO0OOooo........oooOO0OOooo........oo     52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 53                                                    53 
 54 XrayFluoPlanePrimaryGeneratorAction::XrayFluoP     54 XrayFluoPlanePrimaryGeneratorAction::XrayFluoPlanePrimaryGeneratorAction(const XrayFluoPlaneDetectorConstruction* XrayFluoDC)
 55   :rndmFlag("on"),beam("off"),spectrum("off"),     55   :rndmFlag("on"),beam("off"),spectrum("off"),isoVert("off")
 56 {                                                  56 {
 57                                                    57 
 58   XrayFluoDetector = XrayFluoDC;                   58   XrayFluoDetector = XrayFluoDC;
 59                                                    59 
 60   G4int n_particle = 1;                            60   G4int n_particle = 1;
 61   particleGun  = new G4ParticleGun(n_particle)     61   particleGun  = new G4ParticleGun(n_particle);
 62                                                    62   
 63   //create a messenger for this class              63   //create a messenger for this class
 64   gunMessenger = new XrayFluoPlanePrimaryGener     64   gunMessenger = new XrayFluoPlanePrimaryGeneratorMessenger(this);
 65   runManager = new XrayFluoRunAction();            65   runManager = new XrayFluoRunAction();
 66                                                    66   
 67   // default particle kinematic                    67   // default particle kinematic
 68                                                    68   
 69   G4ParticleTable* particleTable = G4ParticleT     69   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
 70   G4String particleName;                           70   G4String particleName;
 71   G4ParticleDefinition* particle                   71   G4ParticleDefinition* particle
 72     = particleTable->FindParticle(particleName     72     = particleTable->FindParticle(particleName="gamma");
 73   particleGun->SetParticleDefinition(particle)     73   particleGun->SetParticleDefinition(particle);
 74   particleGun->SetParticleMomentumDirection(G4     74   particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
 75                                                    75   
 76                                                    76 
 77   particleGun->SetParticleEnergy(10.*keV);         77   particleGun->SetParticleEnergy(10.*keV);
 78   G4double position = -0.5*(XrayFluoDetector->     78   G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
 79   particleGun->SetParticlePosition(G4ThreeVect     79   particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
 80                                                    80 
 81   G4cout << "XrayFluoPlanePrimaryGeneratorActi     81   G4cout << "XrayFluoPlanePrimaryGeneratorAction created  UUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAaa" << G4endl;
 82                                                    82   
 83 }                                                  83 }
 84                                                    84 
 85                                                    85 
 86 //....oooOO0OOooo........oooOO0OOooo........oo     86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 87                                                    87 
 88 XrayFluoPlanePrimaryGeneratorAction::~XrayFluo     88 XrayFluoPlanePrimaryGeneratorAction::~XrayFluoPlanePrimaryGeneratorAction()
 89 {                                                  89 {
 90   delete particleGun;                              90   delete particleGun;
 91   delete gunMessenger;                             91   delete gunMessenger;
 92   delete runManager;                               92   delete runManager;
 93                                                    93 
 94   G4cout << "XrayFluoPlanePrimaryGeneratorActi     94   G4cout << "XrayFluoPlanePrimaryGeneratorAction deleted" << G4endl;
 95                                                    95 
 96 }                                                  96 }
 97                                                    97 
 98 //....oooOO0OOooo........oooOO0OOooo........oo     98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 99                                                    99 
100 void XrayFluoPlanePrimaryGeneratorAction::Gene    100 void XrayFluoPlanePrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
101 {                                                 101 {
102   //this function is called at the begining of    102   //this function is called at the begining of event
103   //                                              103   // 
104   G4double z0 = -0.5*(XrayFluoDetector->GetWor    104   G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ());
105   G4double y0 = 0.*m, x0 = 0.*m;                  105   G4double y0 = 0.*m, x0 = 0.*m;
106   G4double dX = 0.5*(XrayFluoDetector->GetWorl    106   G4double dX = 0.5*(XrayFluoDetector->GetWorldSizeXY())-(XrayFluoDetector->GetPlaneSizeXY());
107   if (rndmFlag == "on")                           107   if (rndmFlag == "on")
108                                                   108 
109     {y0 = (XrayFluoDetector->GetPlaneSizeXY())    109     {y0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5); 
110     x0 = (XrayFluoDetector->GetPlaneSizeXY())*    110     x0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5) + dX; 
111     }                                             111     } 
112                                                   112 
113   z0 = -1 * dX;                                   113   z0 = -1 * dX;
114                                                   114 
115   particleGun->SetParticleMomentumDirection(G4    115   particleGun->SetParticleMomentumDirection(G4ThreeVector(-1.,0.,1.));
116                                                   116 
117   particleGun->SetParticlePosition(G4ThreeVect    117   particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
118                                                   118   
119   //randomize starting point                      119   //randomize starting point
120   if (beam == "on")                               120   if (beam == "on")
121     {                                             121     {
122       G4double radius = 0.5 * mm;                 122       G4double radius = 0.5 * mm;
123       G4double rho = radius*std::sqrt(G4Unifor    123       G4double rho = radius*std::sqrt(G4UniformRand());
124       G4double theta = 2*pi*G4UniformRand()*ra    124       G4double theta = 2*pi*G4UniformRand()*rad;
125       G4double position = -0.5*(XrayFluoDetect    125       G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ());
126                                                   126       
127       G4double y = rho * std::sin(theta);         127       G4double y = rho * std::sin(theta);
128       G4double x = rho * std::cos(theta);         128       G4double x = rho * std::cos(theta);
129                                                   129       
130       particleGun->SetParticlePosition(G4Three    130       particleGun->SetParticlePosition(G4ThreeVector(x,y,position));
131     }                                             131     }
132   //shoot particles according to a certain spe    132   //shoot particles according to a certain spectrum
133   if (spectrum =="on")                            133   if (spectrum =="on")
134     {                                             134     {
135       G4String particle =  particleGun->GetPar    135       G4String particle =  particleGun->GetParticleDefinition()
136   ->GetParticleName();                            136   ->GetParticleName();
137       if(particle == "proton"|| particle == "a    137       if(particle == "proton"|| particle == "alpha")
138   {                                               138   {
139     G4DataVector* energies =  runManager->GetE    139     G4DataVector* energies =  runManager->GetEnergies();
140     G4DataVector* data =  runManager->GetData(    140     G4DataVector* data =  runManager->GetData();
141                                                   141    
142     G4double sum = runManager->GetDataSum();      142     G4double sum = runManager->GetDataSum();
143     G4double partSum = 0;                         143     G4double partSum = 0;
144     G4int j = 0;                                  144     G4int j = 0;
145     G4double random= sum*G4UniformRand();         145     G4double random= sum*G4UniformRand();
146     while (partSum<random)                        146     while (partSum<random)
147       {                                           147       {
148         partSum += (*data)[j];                    148         partSum += (*data)[j];
149         j++;                                      149         j++;
150       }                                           150       }
151                                                   151    
152     particleGun->SetParticleEnergy((*energies)    152     particleGun->SetParticleEnergy((*energies)[j]);
153                                                   153   
154   }                                               154   }
155       else if (particle == "gamma")               155       else if (particle == "gamma")
156   {                                               156   {
157     const XrayFluoDataSet* dataSet = runManage    157     const XrayFluoDataSet* dataSet = runManager->GetGammaSet();
158                                                   158     
159     G4int i = 0;                                  159     G4int i = 0;
160     G4int id = 0;                                 160     G4int id = 0;
161     G4double minEnergy = 0. * keV;                161     G4double minEnergy = 0. * keV;
162     G4double particleEnergy= 0.;                  162     G4double particleEnergy= 0.;
163     G4double maxEnergy = 10. * keV;               163     G4double maxEnergy = 10. * keV;
164     G4double energyRange = maxEnergy - minEner    164     G4double energyRange = maxEnergy - minEnergy;
165                                                   165 
166      while ( i == 0)                              166      while ( i == 0)
167       {                                           167       {
168         G4double random = G4UniformRand();        168         G4double random = G4UniformRand();
169                                                   169         
170         G4double randomNum = G4UniformRand();     170         G4double randomNum = G4UniformRand(); //*5.0E6;
171                                                   171         
172         particleEnergy = (random*energyRange)     172         particleEnergy = (random*energyRange) + minEnergy;
173                                                   173         
174         if ((dataSet->FindValue(particleEnergy    174         if ((dataSet->FindValue(particleEnergy,id)) > randomNum)
175     {                                             175     {
176       i = 1;                                      176       i = 1;
177                                                   177       
178     }                                             178     }
179       }                                           179       }
180      particleGun->SetParticleEnergy(particleEn    180      particleGun->SetParticleEnergy(particleEnergy);
181   }                                               181   }
182     }                                             182     }
183                                                   183   
184   if (isoVert == "on")                            184   if (isoVert == "on")
185     {                                             185     {
186       G4double rho = 1. *m;                       186       G4double rho = 1. *m;
187       //theta in [0;pi/2]                         187       //theta in [0;pi/2]
188       G4double theta = (pi/2)*G4UniformRand();    188       G4double theta = (pi/2)*G4UniformRand();
189       //phi in [-pi;pi]                           189       //phi in [-pi;pi]
190       G4double phi = (G4UniformRand()*2*pi)- p    190       G4double phi = (G4UniformRand()*2*pi)- pi;
191       G4double x = rho*std::sin(theta)*std::si    191       G4double x = rho*std::sin(theta)*std::sin(phi);
192       G4double y = rho*std::sin(theta)*std::co    192       G4double y = rho*std::sin(theta)*std::cos(phi);
193       G4double z = -(rho*std::cos(theta));        193       G4double z = -(rho*std::cos(theta));
194       particleGun->SetParticlePosition(G4Three    194       particleGun->SetParticlePosition(G4ThreeVector(x,y,z));
195                                                   195       
196       G4double Xdim = XrayFluoDetector->GetPla    196       G4double Xdim = XrayFluoDetector->GetPlaneSizeXY();
197       G4double Ydim = XrayFluoDetector->GetPla    197       G4double Ydim = XrayFluoDetector->GetPlaneSizeXY();
198                                                   198       
199       G4double Dx = Xdim*(G4UniformRand()-0.5)    199       G4double Dx = Xdim*(G4UniformRand()-0.5);
200                                                   200       
201       G4double Dy = Ydim*(G4UniformRand()-0.5)    201       G4double Dy = Ydim*(G4UniformRand()-0.5);
202                                                   202       
203       particleGun->SetParticleMomentumDirectio    203       particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z));
204                                                   204       
205     }                                             205     }
206 #ifdef G4ANALYSIS_USE                             206 #ifdef G4ANALYSIS_USE 
207                                                   207 
208   G4double partEnergy = particleGun->GetPartic    208   G4double partEnergy = particleGun->GetParticleEnergy();
209   XrayFluoAnalysisManager* analysis =  XrayFlu    209   XrayFluoAnalysisManager* analysis =  XrayFluoAnalysisManager::getInstance();
210   analysis->analysePrimaryGenerator(partEnergy    210   analysis->analysePrimaryGenerator(partEnergy/keV);
211                                                   211 
212 #endif                                            212 #endif
213                                                   213  
214   particleGun->GeneratePrimaryVertex(anEvent);    214   particleGun->GeneratePrimaryVertex(anEvent);
215 }                                                 215 }
216                                                   216 
217 //....oooOO0OOooo........oooOO0OOooo........oo    217 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
218                                                   218 
219                                                   219 
220                                                   220 
221                                                   221 
222                                                   222 
223                                                   223 
224                                                   224 
225                                                   225 
226                                                   226 
227                                                   227