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 // G4SPSRandomGenerator << 26 /////////////////////////////////////////////////////////////////////////////// >> 27 // >> 28 // MODULE: G4SPSRandomGenerator.hh >> 29 // >> 30 // Version: 1.0 >> 31 // Date: 5/02/04 >> 32 // Author: Fan Lei >> 33 // Organisation: QinetiQ ltd. >> 34 // Customer: ESA/ESTEC >> 35 // >> 36 /////////////////////////////////////////////////////////////////////////////// >> 37 // >> 38 // CHANGE HISTORY >> 39 // -------------- >> 40 // 06/06/2014 A Dotti >> 41 // Note on thread safety: added a mutex to protect access to shared >> 42 // resources (data members). >> 43 // Getters and Setters are mutex'd but not the GetRand* methods, >> 44 // because it is assumed these are called only during the event loop >> 45 // during which the status of this class is invariant. >> 46 // >> 47 // 26/10/2004 F Lei >> 48 // Created separated the theta, phi generators for position distributions. >> 49 // >> 50 // Version 1.0, 05/02/2004, Fan Lei, Created. >> 51 // Based on the G4GeneralParticleSource class in Geant4 v6.0 >> 52 // >> 53 /////////////////////////////////////////////////////////////////////////////// 27 // 54 // 28 // Class Description: 55 // Class Description: 29 // 56 // 30 // Special random number generator used by G4G 57 // Special random number generator used by G4GeneralParticleSource to allow 31 // biasing applied at the lowest level for all 58 // biasing applied at the lowest level for all distributions. 32 // This is a shared class between threads. << 59 // 33 // Only one thread should use the set-methods << 60 /////////////////////////////////////////////////////////////////////////////// 34 // Note that this is exactly what is achieved << 61 // 35 // If you use the set methods to set defaults << 62 // MEMBER FUNCTIONS 36 // application take care that only one thread << 63 // ---------------- 37 // In addition take care of calling these meth << 64 // 38 // Do not use the setters during the event loo << 65 // G4SPSRandomGenerator () 39 << 66 // Constructor: Initializes variables 40 // Author: Fan Lei, QinetiQ ltd. << 67 // 41 // Customer: ESA/ESTEC << 68 // ~G4SPSRandomGenerator () 42 // History: << 69 // Destructor: 43 // - 05/02/2004, Fan Lei - Created. << 70 // 44 // Based on the G4GeneralParticleSource cl << 71 // void SetXBias(G4ThreeVector) 45 // - 06/06/2014, Andrea Dotti << 72 // Allows the user to re-distribute the random 46 // Added a mutex to protect access to shar << 73 // numbers used to generate x co-ordinates. 47 // Getters and Setters are mutex'd but not << 74 // 48 // because it is assumed these are called << 75 // void SetYBias(G4ThreeVector) 49 // during which the status of this class i << 76 // Allows the user to re-distribute the random 50 // ------------------------------------------- << 77 // numbers used to generate y co-ordinates. 51 #ifndef G4SPSRandomGenerator_hh << 78 // 52 #define G4SPSRandomGenerator_hh 1 << 79 // void SetZBias(G4ThreeVector) >> 80 // Allows the user to re-distribute the random >> 81 // numbers used to generate z co-ordinates. >> 82 // >> 83 // void SetThetaBias(G4ThreeVector) >> 84 // Allows the user to re-distribute the random >> 85 // numbers used to generate values of theta. >> 86 // >> 87 // void SetPhiBias(G4ThreeVector) >> 88 // Allows the user to re-distribute the random >> 89 // numbers used to generate values of phi. >> 90 // >> 91 // void SetPosThetaBias(G4ThreeVector) >> 92 // Allows the user to re-distribute the random >> 93 // numbers used to generate values of theta for position distribution. >> 94 // >> 95 // void SetPosPhiBias(G4ThreeVector) >> 96 // Allows the user to re-distribute the random >> 97 // numbers used to generate values of phi for position distribution. >> 98 // >> 99 // void SetEnergyBias(G4ThreeVector) >> 100 // Allows the user to re-distribute the random >> 101 // numbers used to generate the energies. >> 102 // >> 103 // G4double GenRandX() >> 104 // Generates the random number for x, with or without biasing. >> 105 // >> 106 // G4double GenRandY() >> 107 // Generates the random number for y, with or without biasing. >> 108 // >> 109 // G4double GenRandZ() >> 110 // Generates the random number for z, with or without biasing. >> 111 // >> 112 // G4double GenRandTheta() >> 113 // Generates the random number for theta, with or without biasing. >> 114 // >> 115 // G4double GenRandPhi() >> 116 // Generates the random number for phi, with or without biasing. >> 117 // >> 118 // G4double GenRandEnergy() >> 119 // Generates the random number for energy, with or without biasing. >> 120 // >> 121 // G4double GenRandPosTheta() >> 122 // Generates the random number for theta, with or without biasing for position distribution. >> 123 // >> 124 // G4double GenRandPosPhi() >> 125 // Generates the random number for phi, with or without biasing for position distribution. >> 126 // >> 127 // inline G4double GetBiasWeight() >> 128 // Returns the weight change after biasing >> 129 // >> 130 // void ReSetHist(G4String); >> 131 // Re-sets the histogram for user defined distribution >> 132 // >> 133 // void SetVerbosity(G4int) >> 134 // Sets the verbosity level. >> 135 // >> 136 /////////////////////////////////////////////////////////////////////////////// >> 137 // >> 138 #ifndef G4SPSRandomGenerator_h >> 139 #define G4SPSRandomGenerator_h 1 53 140 54 #include "G4PhysicsFreeVector.hh" << 141 #include "G4PhysicsOrderedFreeVector.hh" 55 #include "G4DataInterpolation.hh" 142 #include "G4DataInterpolation.hh" 56 #include "G4ThreeVector.hh" 143 #include "G4ThreeVector.hh" 57 #include "G4Threading.hh" 144 #include "G4Threading.hh" 58 #include "G4Cache.hh" 145 #include "G4Cache.hh" 59 146 60 class G4SPSRandomGenerator << 147 /** Andrea Dotti Feb 2015 61 { << 148 * Important: This is a shared class between threads. 62 public: << 149 * Only one thread should use the set-methods here. 63 << 150 * Note that this is exactly what is achieved using UI commands. 64 G4SPSRandomGenerator(); << 151 * If you use the set methods to set defaults in your 65 // Constructor: initializes variables << 152 * application take care that only one thread is executing them. 66 << 153 * In addition take care of calling these methods before the run is started 67 ~G4SPSRandomGenerator(); << 154 * Do not use these setters during the event loop 68 // Destructor << 155 */ 69 << 156 70 // Biasing Methods << 157 class G4SPSRandomGenerator { 71 << 158 public: 72 void SetXBias(const G4ThreeVector&); << 159 G4SPSRandomGenerator(); 73 // Allows the user to re-distribute the << 160 ~G4SPSRandomGenerator(); 74 // numbers used to generate x co-ordinat << 161 75 << 162 // static G4SPSRandomGenerator* getInstance (); 76 void SetYBias(const G4ThreeVector&); << 163 77 // Allows the user to re-distribute the << 164 // Biasing Methods 78 // numbers used to generate y co-ordinat << 165 void SetXBias(G4ThreeVector); 79 << 166 void SetYBias(G4ThreeVector); 80 void SetZBias(const G4ThreeVector&); << 167 void SetZBias(G4ThreeVector); 81 // Allows the user to re-distribute the << 168 void SetThetaBias(G4ThreeVector); 82 // numbers used to generate z co-ordinat << 169 void SetPhiBias(G4ThreeVector); >> 170 void SetEnergyBias(G4ThreeVector); >> 171 void SetPosThetaBias(G4ThreeVector); >> 172 void SetPosPhiBias(G4ThreeVector); >> 173 G4double GenRandX(); >> 174 G4double GenRandY(); >> 175 G4double GenRandZ(); >> 176 G4double GenRandTheta(); >> 177 G4double GenRandPhi(); >> 178 G4double GenRandEnergy(); >> 179 G4double GenRandPosTheta(); >> 180 G4double GenRandPosPhi(); 83 181 84 void SetThetaBias(const G4ThreeVector&); << 182 void SetIntensityWeight(G4double weight); 85 // Allows the user to re-distribute the << 86 // numbers used to generate values of th << 87 << 88 void SetPhiBias(const G4ThreeVector&); << 89 // Allows the user to re-distribute the << 90 // numbers used to generate values of ph << 91 << 92 void SetEnergyBias(const G4ThreeVector&); << 93 // Allows the user to re-distribute the ra << 94 // numbers used to generate the energies << 95 << 96 void SetPosThetaBias(const G4ThreeVector&) << 97 // Allows the user to re-distribute the << 98 // numbers used to generate values of th << 99 << 100 void SetPosPhiBias(const G4ThreeVector&); << 101 // Allows the user to re-distribute the << 102 // numbers used to generate values of ph << 103 << 104 G4double GenRandX(); << 105 // Generates the random number for x, wi << 106 << 107 G4double GenRandY(); << 108 // Generates the random number for y, wi << 109 << 110 G4double GenRandZ(); << 111 // Generates the random number for z, wi << 112 << 113 G4double GenRandTheta(); << 114 // Generates the random number for theta << 115 << 116 G4double GenRandPhi(); << 117 // Generates the random number for phi, << 118 183 119 G4double GenRandEnergy(); << 184 G4double GetBiasWeight(); 120 // Generates the random number for energ << 121 185 122 G4double GenRandPosTheta(); << 186 // method to re-set the histograms 123 // Generates the random number for theta << 187 void ReSetHist(G4String); 124 // for position distribution << 125 188 126 G4double GenRandPosPhi(); << 189 // Set the verbosity level. 127 // Generates the random number for phi, << 190 void SetVerbosity(G4int a); 128 // for position distribution << 129 191 130 void SetIntensityWeight(G4double weight); << 192 private: >> 193 //Encapsulate in a struct >> 194 //to gurantee that correct >> 195 //initial state is set via constructor >> 196 struct a_check { >> 197 G4bool val; >> 198 a_check() { val = false; } >> 199 }; >> 200 //See .cc for an explanation of this >> 201 //in method GenRandX() >> 202 G4Cache<a_check> local_IPDFXBias; >> 203 G4bool XBias, IPDFXBias; >> 204 G4PhysicsOrderedFreeVector XBiasH; >> 205 G4PhysicsOrderedFreeVector IPDFXBiasH; >> 206 G4Cache<a_check> local_IPDFYBias; >> 207 G4bool YBias, IPDFYBias; >> 208 G4PhysicsOrderedFreeVector YBiasH; >> 209 G4PhysicsOrderedFreeVector IPDFYBiasH; >> 210 G4Cache<a_check> local_IPDFZBias; >> 211 G4bool ZBias, IPDFZBias; >> 212 G4PhysicsOrderedFreeVector ZBiasH; >> 213 G4PhysicsOrderedFreeVector IPDFZBiasH; >> 214 G4Cache<a_check> local_IPDFThetaBias; >> 215 G4bool ThetaBias, IPDFThetaBias; >> 216 G4PhysicsOrderedFreeVector ThetaBiasH; >> 217 G4PhysicsOrderedFreeVector IPDFThetaBiasH; >> 218 G4Cache<a_check> local_IPDFPhiBias; >> 219 G4bool PhiBias, IPDFPhiBias; >> 220 G4PhysicsOrderedFreeVector PhiBiasH; >> 221 G4PhysicsOrderedFreeVector IPDFPhiBiasH; >> 222 G4Cache<a_check> local_IPDFEnergyBias; >> 223 G4bool EnergyBias, IPDFEnergyBias; >> 224 G4PhysicsOrderedFreeVector EnergyBiasH; >> 225 G4PhysicsOrderedFreeVector IPDFEnergyBiasH; >> 226 G4Cache<a_check> local_IPDFPosThetaBias; >> 227 G4bool PosThetaBias, IPDFPosThetaBias; >> 228 G4PhysicsOrderedFreeVector PosThetaBiasH; >> 229 G4PhysicsOrderedFreeVector IPDFPosThetaBiasH; >> 230 G4Cache<a_check> local_IPDFPosPhiBias; >> 231 G4bool PosPhiBias, IPDFPosPhiBias; >> 232 G4PhysicsOrderedFreeVector PosPhiBiasH; >> 233 G4PhysicsOrderedFreeVector IPDFPosPhiBiasH; >> 234 >> 235 //G4double alpha; // for biasing energy >> 236 struct bweights_t { >> 237 G4double w[9]; >> 238 bweights_t(); >> 239 G4double& operator[] (const int i); >> 240 }; >> 241 G4Cache<bweights_t> bweights; >> 242 //G4double bweights[9]; //record x,y,z,theta,phi,energy,posThet,posPhi,intensity weights 131 243 132 G4double GetBiasWeight() const ; << 244 // Verbosity 133 // Returns the weight change after biasi << 245 G4int verbosityLevel; 134 246 135 // method to re-set the histograms << 247 G4Mutex mutex; //protect shared resources 136 void ReSetHist(const G4String&); << 137 // Resets the histogram for user defined << 138 << 139 void SetVerbosity(G4int a); << 140 // Sets the verbosity level << 141 << 142 private: << 143 << 144 // Encapsulate in a struct to guarantee th << 145 // initial state is set via constructor << 146 // << 147 struct a_check << 148 { << 149 G4bool val; << 150 a_check() { val = false; } << 151 }; << 152 << 153 // See .cc for an explanation of this in m << 154 // << 155 G4Cache<a_check> local_IPDFXBias; << 156 G4bool XBias, IPDFXBias; << 157 G4PhysicsFreeVector XBiasH; << 158 G4PhysicsFreeVector IPDFXBiasH; << 159 G4Cache<a_check> local_IPDFYBias; << 160 G4bool YBias, IPDFYBias; << 161 G4PhysicsFreeVector YBiasH; << 162 G4PhysicsFreeVector IPDFYBiasH; << 163 G4Cache<a_check> local_IPDFZBias; << 164 G4bool ZBias, IPDFZBias; << 165 G4PhysicsFreeVector ZBiasH; << 166 G4PhysicsFreeVector IPDFZBiasH; << 167 G4Cache<a_check> local_IPDFThetaBias; << 168 G4bool ThetaBias, IPDFThetaBias; << 169 G4PhysicsFreeVector ThetaBiasH; << 170 G4PhysicsFreeVector IPDFThetaBiasH; << 171 G4Cache<a_check> local_IPDFPhiBias; << 172 G4bool PhiBias, IPDFPhiBias; << 173 G4PhysicsFreeVector PhiBiasH; << 174 G4PhysicsFreeVector IPDFPhiBiasH; << 175 G4Cache<a_check> local_IPDFEnergyBias; << 176 G4bool EnergyBias, IPDFEnergyBias; << 177 G4PhysicsFreeVector EnergyBiasH; << 178 G4PhysicsFreeVector IPDFEnergyBiasH; << 179 G4Cache<a_check> local_IPDFPosThetaBias; << 180 G4bool PosThetaBias, IPDFPosThetaBias; << 181 G4PhysicsFreeVector PosThetaBiasH; << 182 G4PhysicsFreeVector IPDFPosThetaBiasH; << 183 G4Cache<a_check> local_IPDFPosPhiBias; << 184 G4bool PosPhiBias, IPDFPosPhiBias; << 185 G4PhysicsFreeVector PosPhiBiasH; << 186 G4PhysicsFreeVector IPDFPosPhiBiasH; << 187 << 188 struct bweights_t << 189 { << 190 G4double w[9]; << 191 bweights_t(); << 192 G4double& operator[] (const int i); << 193 }; << 194 G4Cache<bweights_t> bweights; << 195 // record x,y,z,theta,phi,energy,posThet << 196 << 197 G4int verbosityLevel; << 198 // Verbosity << 199 << 200 G4Mutex mutex; << 201 // Protect shared resources << 202 }; 248 }; 203 249 204 #endif 250 #endif >> 251 205 252