Geant4 Cross Reference |
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 // G4SPSEneDistribution 26 // G4SPSEneDistribution 27 // 27 // 28 // Class Description: 28 // Class Description: 29 // 29 // 30 // To generate the energy of a primary vertex 30 // To generate the energy of a primary vertex according to the 31 // defined distribution. This is a shared clas 31 // defined distribution. This is a shared class between threads. 32 // Only one thread should use the set-methods 32 // Only one thread should use the set-methods here. 33 // Note that this is exactly what is achieved 33 // Note that this is exactly what is achieved using UI commands. 34 // If you use the set methods to set defaults 34 // If you use the set methods to set defaults in your application take 35 // care that only one thread is executing them 35 // care that only one thread is executing them. 36 // In addition take care of calling these meth 36 // In addition take care of calling these methods before the run is 37 // started. Do not use the setters during the 37 // started. Do not use the setters during the event loop 38 38 39 // Author: Fan Lei, QinetiQ ltd. 39 // Author: Fan Lei, QinetiQ ltd. 40 // Customer: ESA/ESTEC 40 // Customer: ESA/ESTEC 41 // History: 41 // History: 42 // - 05/02/2004, Fan Lei - Created. 42 // - 05/02/2004, Fan Lei - Created. 43 // Based on the G4GeneralParticleSource cl 43 // Based on the G4GeneralParticleSource class. 44 // - 26/03/2014, Andrew Green. 44 // - 26/03/2014, Andrew Green. 45 // Modification to use STL vectors instead 45 // Modification to use STL vectors instead of C-style arrays. 46 // Also moved to dynamically allocated mem 46 // Also moved to dynamically allocated memory in the LinearInterpolation(), 47 // ExpInterpolation() and LogInterpolation 47 // ExpInterpolation() and LogInterpolation() functions. 48 // - 06/06/2014, Andrea Dotti. 48 // - 06/06/2014, Andrea Dotti. 49 // For thread safety: this is a shared obj 49 // For thread safety: this is a shared object. 50 // Added mutex to control access to shared 50 // Added mutex to control access to shared resources (data members). 51 // in Getters and Setters, mutex is NOT us 51 // in Getters and Setters, mutex is NOT used in GenerateOne() because it 52 // is assumed that properties are not chan 52 // is assumed that properties are not changed during event loop. 53 // - 24/11/2017, Fan Lei 53 // - 24/11/2017, Fan Lei 54 // Added cutoff power-law distribution opti 54 // Added cutoff power-law distribution option. Implementation is similar 55 // to that of the BlackBody one. 55 // to that of the BlackBody one. 56 // ------------------------------------------- 56 // -------------------------------------------------------------------- 57 #ifndef G4SPSEneDistribution_hh 57 #ifndef G4SPSEneDistribution_hh 58 #define G4SPSEneDistribution_hh 1 58 #define G4SPSEneDistribution_hh 1 59 59 60 #include "G4PhysicsFreeVector.hh" 60 #include "G4PhysicsFreeVector.hh" 61 #include "G4ParticleMomentum.hh" 61 #include "G4ParticleMomentum.hh" 62 #include "G4ParticleDefinition.hh" 62 #include "G4ParticleDefinition.hh" 63 #include "G4DataInterpolation.hh" 63 #include "G4DataInterpolation.hh" 64 #include "G4Threading.hh" 64 #include "G4Threading.hh" 65 #include "G4Cache.hh" 65 #include "G4Cache.hh" 66 #include <vector> 66 #include <vector> 67 67 68 #include "G4SPSRandomGenerator.hh" 68 #include "G4SPSRandomGenerator.hh" 69 69 70 class G4SPSEneDistribution 70 class G4SPSEneDistribution 71 { 71 { 72 public: 72 public: 73 73 74 G4SPSEneDistribution(); 74 G4SPSEneDistribution(); 75 // Constructor: initializes variables 75 // Constructor: initializes variables 76 ~G4SPSEneDistribution(); 76 ~G4SPSEneDistribution(); 77 // Destructor 77 // Destructor 78 78 79 void SetEnergyDisType(const G4String&); 79 void SetEnergyDisType(const G4String&); 80 // Allows the user to choose the energy 80 // Allows the user to choose the energy distribution type. 81 // The arguments are: Mono (mono-energet 81 // The arguments are: Mono (mono-energetic), Lin (linear), 82 // Pow (power-law), Exp (exponential), G 82 // Pow (power-law), Exp (exponential), Gauss (gaussian), 83 // Brem (bremsstrahlung), BBody (black-b 83 // Brem (bremsstrahlung), BBody (black-body), 84 // Cdg (cosmic diffuse gamma-ray), User 84 // Cdg (cosmic diffuse gamma-ray), User (user-defined), 85 // Arb (arbitrary point-wise), Epn (ener 85 // Arb (arbitrary point-wise), Epn (energy per nucleon) 86 86 87 const G4String& GetEnergyDisType(); 87 const G4String& GetEnergyDisType(); 88 88 89 void SetEmin(G4double); 89 void SetEmin(G4double); 90 // Sets the minimum energy 90 // Sets the minimum energy 91 91 92 G4double GetEmin() const; 92 G4double GetEmin() const; 93 G4double GetArbEmin(); 93 G4double GetArbEmin(); 94 94 95 void SetEmax(G4double); 95 void SetEmax(G4double); 96 // Sets the maximum energy 96 // Sets the maximum energy 97 97 98 G4double GetEmax() const; 98 G4double GetEmax() const; 99 G4double GetArbEmax(); 99 G4double GetArbEmax(); 100 100 101 void SetMonoEnergy(G4double); 101 void SetMonoEnergy(G4double); 102 // Sets energy for mono-energetic distri 102 // Sets energy for mono-energetic distribution 103 103 104 void SetAlpha(G4double); 104 void SetAlpha(G4double); 105 // Sets alpha for a power-law distributi 105 // Sets alpha for a power-law distribution 106 106 107 void SetBiasAlpha(G4double); 107 void SetBiasAlpha(G4double); 108 108 109 void SetTemp(G4double); 109 void SetTemp(G4double); 110 // Sets Temperature for a Brem or BBody 110 // Sets Temperature for a Brem or BBody distributions 111 111 112 void SetBeamSigmaInE(G4double); 112 void SetBeamSigmaInE(G4double); 113 113 114 void SetEzero(G4double); 114 void SetEzero(G4double); 115 // Sets Ezero for an exponential distrib 115 // Sets Ezero for an exponential distribution 116 116 117 void SetGradient(G4double); 117 void SetGradient(G4double); 118 // Sets gradient for a linear distributi 118 // Sets gradient for a linear distribution 119 119 120 void SetInterCept(G4double); 120 void SetInterCept(G4double); 121 // Sets intercept for a linear distribut 121 // Sets intercept for a linear distribution 122 122 123 void UserEnergyHisto(const G4ThreeVector&) 123 void UserEnergyHisto(const G4ThreeVector&); 124 // Allows user to defined a histogram fo 124 // Allows user to defined a histogram for the energy distribution 125 125 126 void ArbEnergyHisto(const G4ThreeVector&); 126 void ArbEnergyHisto(const G4ThreeVector&); 127 // Allows the user to define an Arbitrar 127 // Allows the user to define an Arbitrary set of points for the 128 // energy distribution 128 // energy distribution 129 129 130 void ArbEnergyHistoFile(const G4String&); 130 void ArbEnergyHistoFile(const G4String&); 131 131 132 void EpnEnergyHisto(const G4ThreeVector&); 132 void EpnEnergyHisto(const G4ThreeVector&); 133 // Allows the user to define an Energy p 133 // Allows the user to define an Energy per nucleon histogram 134 134 135 void InputEnergySpectra(G4bool); 135 void InputEnergySpectra(G4bool); 136 // Allows the user to choose between mom 136 // Allows the user to choose between momentum and energy histograms 137 // for user-defined histograms and arbit 137 // for user-defined histograms and arbitrary point-wise spectra. 138 // The default is true (energy) 138 // The default is true (energy) 139 139 140 void InputDifferentialSpectra(G4bool); 140 void InputDifferentialSpectra(G4bool); 141 // Allows the user to choose between int 141 // Allows the user to choose between integral and differential 142 // distributions when using the arbitrar 142 // distributions when using the arbitrary point-wise option 143 143 144 void ArbInterpolate(const G4String&); 144 void ArbInterpolate(const G4String&); 145 // Allows the user to specify the type o 145 // Allows the user to specify the type of function to 146 // interpolate the Arbitrary points spec 146 // interpolate the Arbitrary points spectrum with 147 147 148 const G4String& GetIntType(); 148 const G4String& GetIntType(); 149 149 150 void Calculate(); 150 void Calculate(); 151 // Controls the calculation of Integral 151 // Controls the calculation of Integral PDF for the Cdg and BBody 152 // distributions 152 // distributions 153 153 154 void SetBiasRndm(G4SPSRandomGenerator* a); 154 void SetBiasRndm(G4SPSRandomGenerator* a); 155 // Sets the biased random number generat 155 // Sets the biased random number generator 156 156 157 void ReSetHist(const G4String&); 157 void ReSetHist(const G4String&); 158 // Resets the histogram for user defined 158 // Resets the histogram for user defined distribution 159 159 160 void SetVerbosity(G4int a); 160 void SetVerbosity(G4int a); 161 // Sets the verbosity level 161 // Sets the verbosity level 162 162 163 G4double GetWeight() const; 163 G4double GetWeight() const; 164 164 165 G4double GetMonoEnergy(); 165 G4double GetMonoEnergy(); 166 // Mono-energetic energy 166 // Mono-energetic energy 167 167 168 G4double GetSE(); 168 G4double GetSE(); 169 // Standard deviation for Gaussian distr 169 // Standard deviation for Gaussian distribution in energy 170 170 171 G4double Getalpha() const; 171 G4double Getalpha() const; 172 // Alpha (pow) 172 // Alpha (pow) 173 173 174 G4double GetEzero() const; 174 G4double GetEzero() const; 175 // E0 (exp) 175 // E0 (exp) 176 176 177 G4double GetTemp(); 177 G4double GetTemp(); 178 // Temp (bbody,brem) 178 // Temp (bbody,brem) 179 179 180 G4double Getgrad() const; 180 G4double Getgrad() const; 181 // Gradient and intercept for linear spe 181 // Gradient and intercept for linear spectra 182 182 183 G4double Getcept() const; 183 G4double Getcept() const; 184 184 185 G4PhysicsFreeVector GetUserDefinedEnergyHi 185 G4PhysicsFreeVector GetUserDefinedEnergyHisto(); 186 186 187 G4PhysicsFreeVector GetArbEnergyHisto(); 187 G4PhysicsFreeVector GetArbEnergyHisto(); 188 188 189 G4double GenerateOne(G4ParticleDefinition* 189 G4double GenerateOne(G4ParticleDefinition*); 190 // Generate one random energy for the s 190 // Generate one random energy for the specified particle 191 191 192 G4double GetProbability (G4double); 192 G4double GetProbability (G4double); 193 193 194 G4double GetArbEneWeight(G4double); 194 G4double GetArbEneWeight(G4double); 195 195 196 inline void ApplyEnergyWeight(G4bool val) 196 inline void ApplyEnergyWeight(G4bool val) { applyEvergyWeight = val; } 197 inline G4bool IfApplyEnergyWeight() const 197 inline G4bool IfApplyEnergyWeight() const { return applyEvergyWeight; } 198 198 199 private: 199 private: 200 200 201 void LinearInterpolation(); 201 void LinearInterpolation(); 202 void LogInterpolation(); 202 void LogInterpolation(); 203 void ExpInterpolation(); 203 void ExpInterpolation(); 204 void SplineInterpolation(); 204 void SplineInterpolation(); 205 void CalculateCdgSpectrum(); 205 void CalculateCdgSpectrum(); 206 void CalculateBbodySpectrum(); 206 void CalculateBbodySpectrum(); 207 void CalculateCPowSpectrum(); 207 void CalculateCPowSpectrum(); 208 208 209 // The following methods generate energies 209 // The following methods generate energies according 210 // to the spectral parameters defined abov 210 // to the spectral parameters defined above 211 211 212 void GenerateMonoEnergetic(); 212 void GenerateMonoEnergetic(); 213 void GenerateBiasPowEnergies(); 213 void GenerateBiasPowEnergies(); 214 void GenerateGaussEnergies(); 214 void GenerateGaussEnergies(); 215 void GenerateBremEnergies(); 215 void GenerateBremEnergies(); 216 void GenerateBbodyEnergies(); 216 void GenerateBbodyEnergies(); 217 void GenerateCdgEnergies(); 217 void GenerateCdgEnergies(); 218 void GenUserHistEnergies(); 218 void GenUserHistEnergies(); 219 void GenEpnHistEnergies(); 219 void GenEpnHistEnergies(); 220 void GenArbPointEnergies(); // NOTE: REQUI 220 void GenArbPointEnergies(); // NOTE: REQUIRES UPDATE OF DATA MEMBERS 221 void GenerateExpEnergies(G4bool); 221 void GenerateExpEnergies(G4bool); 222 void GenerateLinearEnergies(G4bool); 222 void GenerateLinearEnergies(G4bool); 223 void GeneratePowEnergies(G4bool); 223 void GeneratePowEnergies(G4bool); 224 void GenerateCPowEnergies(); 224 void GenerateCPowEnergies(); 225 225 226 void ConvertEPNToEnergy(); 226 void ConvertEPNToEnergy(); 227 // Converts energy per nucleon to energy 227 // Converts energy per nucleon to energy 228 228 229 void BBInitHists(); 229 void BBInitHists(); 230 void CPInitHists(); 230 void CPInitHists(); 231 231 232 private: // Non invariant data members beco 232 private: // Non invariant data members become G4Cache 233 233 234 G4String EnergyDisType; // energy dis type 234 G4String EnergyDisType; // energy dis type Variable - Mono,Lin,Exp,etc 235 G4double weight; // particle weight //// N 235 G4double weight; // particle weight //// NOT INVARIANT 236 G4double MonoEnergy; //Mono-energteic ener 236 G4double MonoEnergy; //Mono-energteic energy 237 G4double SE; // Standard deviation for Gau 237 G4double SE; // Standard deviation for Gaussian distribution in energy 238 238 239 G4double Emin, Emax; // emin and emax //// 239 G4double Emin, Emax; // emin and emax //// NOT INVARIANT 240 G4double alpha, Ezero;// alpha (pow), E0 ( 240 G4double alpha, Ezero;// alpha (pow), E0 (exp) //// NOT INVARIANT 241 G4double Temp; // Temp (bbody,brem) 241 G4double Temp; // Temp (bbody,brem) 242 G4double biasalpha; // biased power index 242 G4double biasalpha; // biased power index 243 G4double grad, cept; // gradient and inter 243 G4double grad, cept; // gradient and intercept for linear spectra //// NOT INVARIANT 244 G4double prob_norm; // normalisation facto 244 G4double prob_norm; // normalisation factor use in calculate the probability 245 G4bool Biased = false; // biased to power- 245 G4bool Biased = false; // biased to power-law 246 G4bool EnergySpec = true; // energy spectr 246 G4bool EnergySpec = true; // energy spectra, false - momentum spectra 247 G4bool DiffSpec = true; // differential sp 247 G4bool DiffSpec = true; // differential spec, false integral spec 248 248 249 G4PhysicsFreeVector UDefEnergyH; // energy 249 G4PhysicsFreeVector UDefEnergyH; // energy hist data 250 G4PhysicsFreeVector IPDFEnergyH; 250 G4PhysicsFreeVector IPDFEnergyH; 251 G4bool IPDFEnergyExist = false, IPDFArbExi 251 G4bool IPDFEnergyExist = false, IPDFArbExist = false, Epnflag = false; 252 G4PhysicsFreeVector ArbEnergyH; // Arb x,y 252 G4PhysicsFreeVector ArbEnergyH; // Arb x,y histogram 253 G4PhysicsFreeVector IPDFArbEnergyH; // IPD 253 G4PhysicsFreeVector IPDFArbEnergyH; // IPDF for Arb 254 G4PhysicsFreeVector EpnEnergyH; 254 G4PhysicsFreeVector EpnEnergyH; 255 G4double CDGhist[3]; // cumulative histo f 255 G4double CDGhist[3]; // cumulative histo for cdg 256 256 257 std::vector<G4double>* BBHist = nullptr; 257 std::vector<G4double>* BBHist = nullptr; 258 std::vector<G4double>* Bbody_x = nullptr; 258 std::vector<G4double>* Bbody_x = nullptr; 259 G4bool BBhistInit = false; 259 G4bool BBhistInit = false; 260 G4bool BBhistCalcd = false; 260 G4bool BBhistCalcd = false; 261 261 262 // For cutoff power-law 262 // For cutoff power-law 263 // 263 // 264 std::vector<G4double>* CPHist = nullptr; 264 std::vector<G4double>* CPHist = nullptr; 265 std::vector<G4double>* CP_x = nullptr; 265 std::vector<G4double>* CP_x = nullptr; 266 G4bool CPhistInit = false; 266 G4bool CPhistInit = false; 267 G4bool CPhistCalcd = false; 267 G4bool CPhistCalcd = false; 268 268 269 G4String IntType; // Interpolation type 269 G4String IntType; // Interpolation type 270 G4double* Arb_grad = nullptr; 270 G4double* Arb_grad = nullptr; 271 G4double* Arb_cept = nullptr; 271 G4double* Arb_cept = nullptr; 272 G4bool Arb_grad_cept_flag = false; 272 G4bool Arb_grad_cept_flag = false; 273 G4double* Arb_alpha = nullptr; 273 G4double* Arb_alpha = nullptr; 274 G4double* Arb_Const = nullptr; 274 G4double* Arb_Const = nullptr; 275 G4bool Arb_alpha_Const_flag = false; 275 G4bool Arb_alpha_Const_flag = false; 276 G4double* Arb_ezero = nullptr; 276 G4double* Arb_ezero = nullptr; 277 G4bool Arb_ezero_flag = false; 277 G4bool Arb_ezero_flag = false; 278 278 279 G4bool applyEvergyWeight = false; 279 G4bool applyEvergyWeight = false; 280 280 281 G4double ArbEmin, ArbEmax; 281 G4double ArbEmin, ArbEmax; 282 // Emin and Emax for the whole arb distr 282 // Emin and Emax for the whole arb distribution used primarily for debug. 283 283 284 G4double particle_energy; 284 G4double particle_energy; 285 285 286 G4SPSRandomGenerator* eneRndm = nullptr; 286 G4SPSRandomGenerator* eneRndm = nullptr; 287 287 288 G4int verbosityLevel; 288 G4int verbosityLevel; 289 289 290 G4PhysicsFreeVector ZeroPhysVector; // for 290 G4PhysicsFreeVector ZeroPhysVector; // for re-set only 291 291 292 std::vector<G4DataInterpolation*> SplineIn 292 std::vector<G4DataInterpolation*> SplineInt; 293 // Holds Spline stuff required for sampl 293 // Holds Spline stuff required for sampling 294 G4DataInterpolation* Splinetemp = nullptr; 294 G4DataInterpolation* Splinetemp = nullptr; 295 // Holds a temp Spline used for calculat 295 // Holds a temp Spline used for calculating area 296 296 297 G4Mutex mutex; // protect access to shared 297 G4Mutex mutex; // protect access to shared resources 298 298 299 // Thread local data (non-invariant during 299 // Thread local data (non-invariant during event loop). 300 // These are copied from master one at the 300 // These are copied from master one at the beginning of 301 // generation of each event 301 // generation of each event 302 // 302 // 303 struct threadLocal_t 303 struct threadLocal_t 304 { 304 { 305 G4double Emin; 305 G4double Emin; 306 G4double Emax; 306 G4double Emax; 307 G4double alpha; 307 G4double alpha; 308 G4double Ezero; 308 G4double Ezero; 309 G4double grad; 309 G4double grad; 310 G4double cept; 310 G4double cept; 311 G4ParticleDefinition* particle_definitio 311 G4ParticleDefinition* particle_definition; 312 G4double weight; 312 G4double weight; 313 G4double particle_energy; 313 G4double particle_energy; 314 }; 314 }; 315 G4Cache<threadLocal_t> threadLocalData; 315 G4Cache<threadLocal_t> threadLocalData; 316 }; 316 }; 317 317 318 #endif 318 #endif 319 319