[1199] | 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: G4RandDistributionTest.cc,v 1.5 2006/06/29 19:00:52 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | // ---------------------------------------------------------------------- |
---|
| 32 | #include "Randomize.hh" |
---|
| 33 | #include "G4ios.hh" |
---|
| 34 | |
---|
| 35 | HepJamesRandom theJamesEngine; |
---|
| 36 | RandEngine theRandEngine; |
---|
| 37 | DRand48Engine theDRand48Engine; |
---|
| 38 | RanluxEngine theRanluxEngine(19780503,4); |
---|
| 39 | RanecuEngine theRanecuEngine; |
---|
| 40 | |
---|
| 41 | void init() |
---|
| 42 | { |
---|
| 43 | char Pause; |
---|
| 44 | |
---|
| 45 | G4cout << G4endl << G4endl; |
---|
| 46 | G4cout << "---------------------------- Random shooting test -----------------------------" << G4endl; |
---|
| 47 | G4cout << " -------------------- " << G4endl; |
---|
| 48 | G4cout << " >>> Random Engines available <<<" << G4endl << G4endl; |
---|
| 49 | G4cout << " > HepJamesRandom (default)" << G4endl; |
---|
| 50 | G4cout << " > Rand" << G4endl; |
---|
| 51 | G4cout << " > DRand48" << G4endl; |
---|
| 52 | G4cout << " > Ranlux" << G4endl; |
---|
| 53 | G4cout << " > Ranecu" << G4endl << G4endl; |
---|
| 54 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 55 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 56 | G4cout << G4endl; |
---|
| 57 | |
---|
| 58 | } // end init() |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | void layout() |
---|
| 62 | { |
---|
| 63 | HepFloat m=3.0; |
---|
| 64 | const HepInt size=5; |
---|
| 65 | HepDouble vect[size]; |
---|
| 66 | |
---|
| 67 | G4cout << " Flat ]0,1[ : " << RandFlat::shoot() << G4endl; |
---|
| 68 | G4cout << " Flat ]0,5[ : " << RandFlat::shoot(5) << G4endl; |
---|
| 69 | G4cout << " Flat ]-5,3[ : " << RandFlat::shoot(-5,3) << G4endl; |
---|
| 70 | G4cout << " Exp (m=1) : " << RandExponential::shoot() << G4endl; |
---|
| 71 | G4cout << " Exp (m=3) : " << RandExponential::shoot(3) << G4endl; |
---|
| 72 | G4cout << " Gauss (m=1) : " << RandGauss::shoot() << G4endl; |
---|
| 73 | G4cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(3,1) << G4endl; |
---|
| 74 | G4cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(1,0.2) << G4endl; |
---|
| 75 | G4cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(1,0.2,1) << G4endl; |
---|
| 76 | G4cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(1,0.2) << G4endl; |
---|
| 77 | G4cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(1,0.2,1) << G4endl; |
---|
| 78 | G4cout << " IntFlat [0,99[ : " << RandFlat::shootInt(99) << G4endl; |
---|
| 79 | G4cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(-99,37) << G4endl; |
---|
| 80 | G4cout << " Poisson (m=3.0) : " << RandPoisson::shoot(m) << G4endl; |
---|
| 81 | G4cout << G4endl; |
---|
| 82 | G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl; |
---|
| 83 | RandFlat::shootArray(size,vect); |
---|
| 84 | for ( HepInt i=0; i<size; ++i ) |
---|
| 85 | G4cout << " " << vect[i]; |
---|
| 86 | G4cout << G4endl << G4endl; |
---|
| 87 | } // end layout() |
---|
| 88 | |
---|
| 89 | void dist_layout() |
---|
| 90 | { |
---|
| 91 | HepFloat m=3.0; |
---|
| 92 | const HepInt size=5; |
---|
| 93 | HepDouble vect[size]; |
---|
| 94 | char Pause; |
---|
| 95 | |
---|
| 96 | HepJamesRandom aJamesEngine; |
---|
| 97 | RandEngine aRandEngine; |
---|
| 98 | DRand48Engine aDRand48Engine; |
---|
| 99 | RanluxEngine aRanluxEngine(19780503,4); |
---|
| 100 | RanecuEngine aRanecuEngine; |
---|
| 101 | |
---|
| 102 | RandFlat aFlatObj(aJamesEngine); |
---|
| 103 | RandExponential anExponentialObj(aRandEngine); |
---|
| 104 | RandGauss aGaussObj(aDRand48Engine); |
---|
| 105 | RandBreitWigner aBreitObj(aRanluxEngine); |
---|
| 106 | RandPoisson aPoissonObj(aRanecuEngine); |
---|
| 107 | |
---|
| 108 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 109 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 110 | G4cout << "-------------------- Shooting test on distribution objects --------------------" << G4endl; |
---|
| 111 | G4cout << G4endl; |
---|
| 112 | G4cout << " Flat ]0,1[ : " << aFlatObj.fire() << G4endl; |
---|
| 113 | G4cout << " Flat ]0,5[ : " << aFlatObj.fire(5) << G4endl; |
---|
| 114 | G4cout << " Flat ]-5,3[ : " << aFlatObj.fire(-5,3) << G4endl; |
---|
| 115 | G4cout << " Exp (m=1) : " << anExponentialObj.fire() << G4endl; |
---|
| 116 | G4cout << " Exp (m=3) : " << anExponentialObj.fire(3) << G4endl; |
---|
| 117 | G4cout << " Gauss (m=1) : " << aGaussObj.fire() << G4endl; |
---|
| 118 | G4cout << " Gauss (m=3,v=1) : " << aGaussObj.fire(3,1) << G4endl; |
---|
| 119 | G4cout << " Wigner(1,0.2) : " << aBreitObj.fire(1,0.2) << G4endl; |
---|
| 120 | G4cout << " Wigner(1,0.2,1) : " << aBreitObj.fire(1,0.2,1) << G4endl; |
---|
| 121 | G4cout << " Wigner2(1,0.2) : " << aBreitObj.fireM2(1,0.2) << G4endl; |
---|
| 122 | G4cout << " Wigner2(1,0.2,1) : " << aBreitObj.fireM2(1,0.2,1) << G4endl; |
---|
| 123 | G4cout << " IntFlat [0,99[ : " << aFlatObj.fireInt(99) << G4endl; |
---|
| 124 | G4cout << " IntFlat [-99,37[ : " << aFlatObj.fireInt(-99,37) << G4endl; |
---|
| 125 | G4cout << " Poisson (m=3.0) : " << aPoissonObj.fire(m) << G4endl; |
---|
| 126 | G4cout << G4endl; |
---|
| 127 | G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl; |
---|
| 128 | aFlatObj.fireArray(size,vect); |
---|
| 129 | for ( HepInt i=0; i<size; ++i ) |
---|
| 130 | G4cout << " " << vect[i]; |
---|
| 131 | G4cout << G4endl << G4endl; |
---|
| 132 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 133 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 134 | } // end dist_layout() |
---|
| 135 | |
---|
| 136 | void user_layout() |
---|
| 137 | { |
---|
| 138 | HepFloat m=3.0; |
---|
| 139 | const HepInt size=5; |
---|
| 140 | HepDouble vect[size]; |
---|
| 141 | char sel; |
---|
| 142 | HepRandomEngine* anEngine; |
---|
| 143 | |
---|
| 144 | G4cout << G4endl << G4endl; |
---|
| 145 | G4cout << "-------------------- Shooting test skeeping the generator ---------------------" << G4endl; |
---|
| 146 | G4cout << G4endl; |
---|
| 147 | G4cout << " >>> Select a Random Engine <<<" << G4endl << G4endl; |
---|
| 148 | G4cout << " 1. HepJamesRandom (default)" << G4endl; |
---|
| 149 | G4cout << " 2. Rand" << G4endl; |
---|
| 150 | G4cout << " 3. DRand48" << G4endl; |
---|
| 151 | G4cout << " 4. Ranlux" << G4endl; |
---|
| 152 | G4cout << " 5. Ranecu" << G4endl << G4endl; |
---|
| 153 | G4cout << " > "; |
---|
| 154 | G4cin >> sel; |
---|
| 155 | while ((sel!='1')&&(sel!='2')&&(sel!='3')&&(sel!='4')&&(sel!='5')) { |
---|
| 156 | G4cout << G4endl << " >>> Choice not legal !! [1..5]<<<" << G4endl; |
---|
| 157 | G4cin >> sel; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | switch (sel) { |
---|
| 161 | case '1': |
---|
| 162 | anEngine = &theJamesEngine; |
---|
| 163 | break; |
---|
| 164 | case '2': |
---|
| 165 | anEngine = &theRandEngine; |
---|
| 166 | break; |
---|
| 167 | case '3': |
---|
| 168 | anEngine = &theDRand48Engine; |
---|
| 169 | break; |
---|
| 170 | case '4': |
---|
| 171 | anEngine = &theRanluxEngine; |
---|
| 172 | break; |
---|
| 173 | case '5': |
---|
| 174 | anEngine = &theRanecuEngine; |
---|
| 175 | break; |
---|
| 176 | |
---|
| 177 | default: |
---|
| 178 | anEngine = &theJamesEngine; |
---|
| 179 | break; |
---|
| 180 | } |
---|
| 181 | G4cout << G4endl; |
---|
| 182 | |
---|
| 183 | G4cout << " Flat ]0,1[ : " << RandFlat::shoot(anEngine) << G4endl; |
---|
| 184 | G4cout << " Flat ]0,5[ : " << RandFlat::shoot(anEngine,5) << G4endl; |
---|
| 185 | G4cout << " Flat ]-5,3[ : " << RandFlat::shoot(anEngine,-5,3) << G4endl; |
---|
| 186 | G4cout << " Exp (m=1) : " << RandExponential::shoot(anEngine) << G4endl; |
---|
| 187 | G4cout << " Exp (m=3) : " << RandExponential::shoot(anEngine,3) << G4endl; |
---|
| 188 | G4cout << " Gauss (m=1) : " << RandGauss::shoot(anEngine) << G4endl; |
---|
| 189 | G4cout << " Gauss (m=3,v=1) : " << RandGauss::shoot(anEngine,3,1) << G4endl; |
---|
| 190 | G4cout << " Wigner(1,0.2) : " << RandBreitWigner::shoot(anEngine,1,0.2) << G4endl; |
---|
| 191 | G4cout << " Wigner(1,0.2,1) : " << RandBreitWigner::shoot(anEngine,1,0.2,1) << G4endl; |
---|
| 192 | G4cout << " Wigner2(1,0.2) : " << RandBreitWigner::shootM2(anEngine,1,0.2) << G4endl; |
---|
| 193 | G4cout << " Wigner2(1,0.2,1) : " << RandBreitWigner::shootM2(anEngine,1,0.2,1) << G4endl; |
---|
| 194 | G4cout << " IntFlat [0,99[ : " << RandFlat::shootInt(anEngine,99) << G4endl; |
---|
| 195 | G4cout << " IntFlat [-99,37[ : " << RandFlat::shootInt(anEngine,-99,37) << G4endl; |
---|
| 196 | G4cout << " Poisson (m=3.0) : " << RandPoisson::shoot(anEngine,m) << G4endl; |
---|
| 197 | G4cout << G4endl; |
---|
| 198 | G4cout << " Shooting an array of 5 flat numbers ..." << G4endl << G4endl; |
---|
| 199 | RandFlat::shootArray(anEngine,size,vect); |
---|
| 200 | for ( HepInt i=0; i<size; ++i ) |
---|
| 201 | G4cout << " " << vect[i]; |
---|
| 202 | G4cout << G4endl << G4endl; |
---|
| 203 | } // end layout() |
---|
| 204 | |
---|
| 205 | void start_test() |
---|
| 206 | { |
---|
| 207 | char Pause; |
---|
| 208 | |
---|
| 209 | G4cout << "------------------------- Test on HepJamesRandom ----------------------------" << G4endl; |
---|
| 210 | G4cout << G4endl; |
---|
| 211 | layout(); |
---|
| 212 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 213 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 214 | G4cout << G4endl; |
---|
| 215 | G4cout << "--------------------------- Test on RandEngine ------------------------------" << G4endl; |
---|
| 216 | G4cout << G4endl; |
---|
| 217 | HepRandom::setTheEngine(&theRandEngine); |
---|
| 218 | layout(); |
---|
| 219 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 220 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 221 | G4cout << G4endl; |
---|
| 222 | G4cout << "------------------------- Test on DRand48Engine -----------------------------" << G4endl; |
---|
| 223 | G4cout << G4endl; |
---|
| 224 | HepRandom::setTheEngine(&theDRand48Engine); |
---|
| 225 | layout(); |
---|
| 226 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 227 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 228 | G4cout << G4endl; |
---|
| 229 | G4cout << "--------------------- Test on RanluxEngine (luxury 4) ------------------------" << G4endl; |
---|
| 230 | G4cout << G4endl; |
---|
| 231 | HepRandom::setTheEngine(&theRanluxEngine); |
---|
| 232 | layout(); |
---|
| 233 | G4cout << " ----- Press <ENTER> to continue -----"; |
---|
| 234 | if ( (Pause = G4cin.get()) != '\n') exit(0); |
---|
| 235 | G4cout << G4endl; |
---|
| 236 | G4cout << "-------------------------- Test on RanecuEngine ------------------------------" << G4endl; |
---|
| 237 | G4cout << G4endl; |
---|
| 238 | HepRandom::setTheEngine(&theRanecuEngine); |
---|
| 239 | layout(); |
---|
| 240 | dist_layout(); |
---|
| 241 | user_layout(); |
---|
| 242 | } // end start_test() |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | HepInt main() { |
---|
| 246 | |
---|
| 247 | init(); |
---|
| 248 | start_test(); |
---|
| 249 | |
---|
| 250 | return 0; |
---|
| 251 | } |
---|
| 252 | |
---|