Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4ImportanceAlgorithm implementation << 27 // 23 // 28 // Author: Michael Dressel (CERN), 2002 << 24 // $Id: G4ImportanceAlgorithm.cc,v 1.9 2002/11/04 10:43:07 dressel Exp $ >> 25 // GEANT4 tag $Name: geant4-05-00 $ >> 26 // >> 27 // ---------------------------------------------------------------------- >> 28 // GEANT 4 class source file >> 29 // >> 30 // G4ImportanceAlgorithm.cc >> 31 // 29 // ------------------------------------------- 32 // ---------------------------------------------------------------------- 30 33 31 #include "G4Types.hh" << 34 #include "g4std/strstream" 32 #include "Randomize.hh" 35 #include "Randomize.hh" 33 #include "G4Threading.hh" << 34 #include "G4AutoLock.hh" << 35 36 36 #include "G4ImportanceAlgorithm.hh" 37 #include "G4ImportanceAlgorithm.hh" 37 38 38 #include <sstream> << 39 G4ImportanceAlgorithm::G4ImportanceAlgorithm(): fWorned(false) >> 40 {} 39 41 40 namespace << 42 G4ImportanceAlgorithm::~G4ImportanceAlgorithm() 41 { 43 { 42 G4Mutex ImportanceMutex = G4MUTEX_INITIALIZE << 44 if(fWorned) { >> 45 G4cout << G4endl; >> 46 Warning("~G4ImportanceAlgorithm: ipre_over_ipost ! in [0.25, 4] seen"); >> 47 G4cout << G4endl; >> 48 } 43 } 49 } 44 50 45 G4ImportanceAlgorithm::G4ImportanceAlgorithm() << 46 << 47 G4ImportanceAlgorithm::~G4ImportanceAlgorithm( << 48 << 49 G4Nsplit_Weight 51 G4Nsplit_Weight 50 G4ImportanceAlgorithm::Calculate(G4double ipre 52 G4ImportanceAlgorithm::Calculate(G4double ipre, 51 G4double ipos << 53 G4double ipost, 52 G4double init 54 G4double init_w) const 53 { 55 { 54 G4AutoLock l(&ImportanceMutex); << 56 G4Nsplit_Weight nw = {0,0}; 55 G4Nsplit_Weight nw; << 57 if (ipost>0.){ 56 if (ipost>0.) << 58 if (!(ipre>0.)){ 57 { << 59 G4Exception("Error: G4ImportanceAlgorithm::Calculate: ipre==0."); 58 if (!(ipre>0.)) << 59 { << 60 Error("Calculate() - ipre==0."); << 61 } 60 } 62 G4double ipre_over_ipost = ipre/ipost; 61 G4double ipre_over_ipost = ipre/ipost; 63 if ((ipre_over_ipost<0.25 || ipre_over_ipo << 62 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) { 64 { << 63 G4std::ostrstream os; 65 std::ostringstream os; << 64 os << "Calculate: ipre_over_ipost ! in [0.25, 4]: ipre_over_ipost = " 66 os << "Calculate() - ipre_over_ipost ! i << 65 << ipre_over_ipost << '\0' << G4endl; 67 << "ipre_over_ipost = " << ipre_over_ << 68 Warning(os.str()); 66 Warning(os.str()); 69 fWarned = true; << 67 fWorned = true; 70 if (ipre_over_ipost<=0) << 68 if (ipre_over_ipost<=0) { 71 { << 69 Error("Calculate: ipre_over_ipost<=0"); 72 Error("Calculate() - ipre_over_ipost<= << 73 } 70 } 74 } 71 } 75 if (init_w<=0.) << 72 if (init_w<=0.) { 76 { << 73 Error("Calculate: iniitweight<= 0. found"); 77 Error("Calculate() - iniitweight<= 0. fo << 78 } 74 } 79 75 80 // default geometrical splitting 76 // default geometrical splitting 81 // in integer mode 77 // in integer mode 82 // for ipre_over_ipost <= 1 78 // for ipre_over_ipost <= 1 83 G4double inv = 1./ipre_over_ipost; 79 G4double inv = 1./ipre_over_ipost; 84 nw.fN = static_cast<G4int>(inv); 80 nw.fN = static_cast<G4int>(inv); 85 nw.fW = init_w * ipre_over_ipost; 81 nw.fW = init_w * ipre_over_ipost; 86 82 87 // geometrical splitting for double mode 83 // geometrical splitting for double mode 88 if (ipre_over_ipost<1) << 84 if (ipre_over_ipost<1) { 89 { << 85 if ( static_cast<G4double>(nw.fN) != inv) { 90 if ( static_cast<G4double>(nw.fN) != inv << 86 // double mode 91 { << 87 // probability p for splitting into n+1 tracks 92 // double mode << 88 G4double p = inv - nw.fN; 93 // probability p for splitting into n+ << 89 // get a random number out of [0,1) 94 G4double p = inv - nw.fN; << 90 G4double r = G4UniformRand(); 95 // get a random number out of [0,1) << 91 if (r<p) { 96 G4double r = G4UniformRand(); << 92 nw.fN++; 97 if (r<p) << 93 } 98 { << 99 ++nw.fN; << 100 } << 101 } 94 } 102 } 95 } 103 else if (ipre_over_ipost>1) // russian r << 96 // ipre_over_ipost > 1 104 { << 97 // russian roulett >> 98 else if (ipre_over_ipost>1) { 105 // probabiity for killing track 99 // probabiity for killing track 106 G4double p = 1-inv; 100 G4double p = 1-inv; 107 // get a random number out of [0,1) 101 // get a random number out of [0,1) 108 G4double r = G4UniformRand(); 102 G4double r = G4UniformRand(); 109 if (r<p) << 103 if (r<p) { 110 { << 104 // kill track 111 // kill track << 105 nw.fN = 0; 112 nw.fN = 0; << 106 nw.fW = 0; 113 nw.fW = 0; << 114 } 107 } 115 else << 108 else { 116 { << 109 nw.fN = 1; 117 nw.fN = 1; << 118 } 110 } 119 } 111 } 120 } 112 } 121 l.unlock(); << 122 << 123 return nw; 113 return nw; 124 } 114 } 125 115 126 void G4ImportanceAlgorithm::Error(const G4Stri << 116 void G4ImportanceAlgorithm::Error(const G4String &m) const 127 { 117 { 128 G4Exception("G4ImportanceAlgorithm::Error()" << 118 G4cout << "ERROR - G4ImportanceAlgorithm::" << m << G4endl; 129 "GeomBias0002", FatalException, << 119 G4Exception("Program aborted."); 130 } 120 } 131 121 132 void G4ImportanceAlgorithm::Warning(const G4St << 122 void G4ImportanceAlgorithm::Warning(const G4String &m) const 133 { 123 { 134 G4Exception("G4ImportanceAlgorithm::Warning( << 124 G4cout << "WARNING - G4ImportanceAlgorithm::" << m << G4endl; 135 "GeomBias1001", JustWarning, msg << 136 } 125 } 137 126