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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/XrayFluoPrimaryGeneratorAction.cc (Version 11.3.0) and /examples/advanced/xray_fluorescence/src/XrayFluoPrimaryGeneratorAction.cc (Version 6.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 //                                                
 28 // Author: Elena Guardincerri (Elena.Guardince    
 29 //                                                
 30 // History:                                       
 31 // -----------                                    
 32 // 28 Nov 2001 Elena Guardincerri     Created     
 33 //                                                
 34 // -------------------------------------------    
 35                                                   
 36 #include "XrayFluoPrimaryGeneratorAction.hh"      
 37 #include "XrayFluoDetectorConstruction.hh"        
 38 #include "XrayFluoPrimaryGeneratorMessenger.hh    
 39 #include "XrayFluoRunAction.hh"                   
 40 #include "G4Event.hh"                             
 41 #include "G4Gamma.hh"                             
 42 #include "G4ParticleGun.hh"                       
 43 #include "G4ParticleTable.hh"                     
 44 #include "G4ParticleDefinition.hh"                
 45 #include "G4MTRunManager.hh"                      
 46 #include "Randomize.hh"                           
 47 #include "XrayFluoAnalysisManager.hh"             
 48 #include "XrayFluoDataSet.hh"                     
 49 #include "G4PhysicalConstants.hh"                 
 50 #include "G4SystemOfUnits.hh"                     
 51                                                   
 52 //....oooOO0OOooo........oooOO0OOooo........oo    
 53                                                   
 54 XrayFluoPrimaryGeneratorAction::XrayFluoPrimar    
 55                      XrayFluoDetectorConstruct    
 56   :rndmFlag("off"),beam("off"),spectrum("off")    
 57    rayleighFlag(true), detectorPosition(0)        
 58 {                                                 
 59   runAction = 0;                                  
 60   XrayFluoDetector = XrayFluoDC;                  
 61                                                   
 62   G4int n_particle = 1;                           
 63   particleGun  = new G4ParticleGun(n_particle)    
 64                                                   
 65   //create a messenger for this class             
 66   gunMessenger = new XrayFluoPrimaryGeneratorM    
 67                                                   
 68   // default particle kinematic                   
 69   G4ParticleDefinition* particle                  
 70     = G4Gamma::Definition();                      
 71   particleGun->SetParticleDefinition(particle)    
 72   particleGun->SetParticleMomentumDirection(G4    
 73   particleGun->SetParticleEnergy(10. * keV);      
 74                                                   
 75   G4double position = -0.5*(XrayFluoDetector->    
 76   particleGun->SetParticlePosition(G4ThreeVect    
 77                                                   
 78   G4cout << "XrayFluoPrimaryGeneratorAction cr    
 79                                                   
 80 }                                                 
 81                                                   
 82 //....oooOO0OOooo........oooOO0OOooo........oo    
 83                                                   
 84 void XrayFluoPrimaryGeneratorAction::ActivateP    
 85                                                   
 86   // load phase-space                             
 87   phaseSpaceGunFlag = true;                       
 88                                                   
 89   // reads the data stored on disk form previo    
 90   // and get these data to data members           
 91                                                   
 92   XrayFluoAnalysisManager* analysis =  XrayFlu    
 93   analysis->LoadGunData(fileName, rayleighFlag    
 94   detectorPosition = XrayFluoDetector->GetDete    
 95   detectorPosition.setR(detectorPosition.r()-(    
 96                                                   
 97 }                                                 
 98                                                   
 99 //....oooOO0OOooo........oooOO0OOooo........oo    
100                                                   
101 void XrayFluoPrimaryGeneratorAction::SetRaylei    
102 {                                                 
103   rayleighFlag = value;                           
104 }                                                 
105                                                   
106                                                   
107 //....oooOO0OOooo........oooOO0OOooo........oo    
108                                                   
109 XrayFluoPrimaryGeneratorAction::~XrayFluoPrima    
110 {                                                 
111   delete particleGun;                             
112   delete gunMessenger;                            
113 }                                                 
114                                                   
115 //....oooOO0OOooo........oooOO0OOooo........oo    
116                                                   
117 void XrayFluoPrimaryGeneratorAction::GenerateP    
118 {                                                 
119   //retrieve runAction, if not done               
120   if (!runAction)                                 
121     {                                             
122       //Sequential runaction                      
123       if (G4RunManager::GetRunManager()->GetRu    
124     G4RunManager::sequentialRM)                   
125   runAction = static_cast<const XrayFluoRunAct    
126     (G4RunManager::GetRunManager()->GetUserRun    
127       else //MT master runaction                  
128   runAction = static_cast<const XrayFluoRunAct    
129     (G4MTRunManager::GetMasterRunManager()->Ge    
130       if (!runAction)                             
131   G4cout << "Something wrong here!" << G4endl;    
132     }                                             
133                                                   
134   //this function is called at the begining of    
135   //                                              
136   G4double z0 = -0.5*(XrayFluoDetector->GetWor    
137   G4double y0 = 0.*cm, x0 = 0.*cm;                
138   if (rndmFlag == "on")                           
139     {                                             
140       y0 = (XrayFluoDetector->GetDia3SizeXY())    
141       x0 = (XrayFluoDetector->GetDia3SizeXY())    
142     }                                             
143   particleGun->SetParticlePosition(G4ThreeVect    
144                                                   
145   //randomize starting point                      
146   if (beam == "on")                               
147     {                                             
148       G4double radius = 0.5 * mm;                 
149       G4double rho = radius*std::sqrt(G4Unifor    
150       G4double theta = 2*pi*G4UniformRand()*ra    
151       G4double position = -0.5*(XrayFluoDetect    
152                                                   
153       G4double y = rho * std::sin(theta);         
154       G4double x = rho * std::cos(theta);         
155                                                   
156       particleGun->SetParticlePosition(G4Three    
157     }                                             
158   //shoot particles according to a certain spe    
159   if (spectrum =="on")                            
160     {                                             
161       G4String particle =  particleGun->GetPar    
162   ->GetParticleName();                            
163       if(particle == "proton"|| particle == "a    
164   {                                               
165     G4DataVector* energies =  runAction->GetEn    
166     G4DataVector* data =  runAction->GetData()    
167                                                   
168     G4double sum = runAction->GetDataSum();       
169     G4double partSum = 0;                         
170     G4int j = 0;                                  
171     G4double random= sum*G4UniformRand();         
172     while (partSum<random)                        
173       {                                           
174         partSum += (*data)[j];                    
175         j++;                                      
176       }                                           
177                                                   
178     particleGun->SetParticleEnergy((*energies)    
179                                                   
180   }                                               
181       else if (particle == "gamma")               
182   {                                               
183     const XrayFluoDataSet* dataSet = runAction    
184                                                   
185     G4int i = 0;                                  
186     G4int id = 0;                                 
187     G4double minEnergy = 0. * keV;                
188     G4double particleEnergy= 0.;                  
189     G4double maxEnergy = 10. * keV;               
190     G4double energyRange = maxEnergy - minEner    
191                                                   
192      while ( i == 0)                              
193       {                                           
194         G4double random = G4UniformRand();        
195                                                   
196         G4double randomNum = G4UniformRand();     
197                                                   
198         particleEnergy = (random*energyRange)     
199                                                   
200         if ((dataSet->FindValue(particleEnergy    
201     {                                             
202       i = 1;                                      
203                                                   
204     }                                             
205       }                                           
206      particleGun->SetParticleEnergy(particleEn    
207   }                                               
208     }                                             
209                                                   
210   // Randomize starting point and direction       
211                                                   
212   if (isoVert == "on")                            
213     {                                             
214       G4double rho = 1. *m;                       
215       //theta in [0;pi/2]                         
216       G4double theta = (pi/2)*G4UniformRand();    
217       //phi in [-pi;pi]                           
218       G4double phi = (G4UniformRand()*2*pi)- p    
219       G4double x = rho*std::sin(theta)*std::si    
220       G4double y = rho*std::sin(theta)*std::co    
221       G4double z = -(rho*std::cos(theta));        
222       particleGun->SetParticlePosition(G4Three    
223                                                   
224       G4double Xdim = XrayFluoDetector->GetSam    
225       G4double Ydim = XrayFluoDetector->GetSam    
226                                                   
227       G4double Dx = Xdim*(G4UniformRand()-0.5)    
228                                                   
229       G4double Dy = Ydim*(G4UniformRand()-0.5)    
230                                                   
231       particleGun->SetParticleMomentumDirectio    
232                                                   
233     }                                             
234                                                   
235   // using prevoiously genereated emissions fr    
236                                                   
237   if (phaseSpaceGunFlag){                         
238                                                   
239     particleGun->SetParticlePosition(detectorP    
240     particleGun->SetParticleMomentumDirection(    
241                                                   
242     G4ParticleTable* particleTable = G4Particl    
243                                                   
244     const std::pair<G4double,G4String> kine =     
245       XrayFluoAnalysisManager::getInstance()->    
246                                                   
247     G4double energy = kine.first;                 
248     G4ParticleDefinition* particle = particleT    
249                                                   
250     particleGun->SetParticleEnergy(energy);       
251     particleGun->SetParticleDefinition(particl    
252                                                   
253                                                   
254   }                                               
255                                                   
256   G4double partEnergy = particleGun->GetPartic    
257   XrayFluoAnalysisManager* analysis =  XrayFlu    
258   analysis->analysePrimaryGenerator(partEnergy    
259                                                   
260                                                   
261   particleGun->GeneratePrimaryVertex(anEvent);    
262 }                                                 
263                                                   
264 //....oooOO0OOooo........oooOO0OOooo........oo    
265                                                   
266                                                   
267                                                   
268                                                   
269                                                   
270                                                   
271                                                   
272                                                   
273                                                   
274