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.12 2003/10/22 13:52:10 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ >> 26 // >> 27 // ---------------------------------------------------------------------- >> 28 // GEANT 4 class source file >> 29 // >> 30 // G4ImportanceAlgorithm.cc >> 31 // 29 // ------------------------------------------- 32 // ---------------------------------------------------------------------- 30 33 31 #include "G4Types.hh" 34 #include "G4Types.hh" >> 35 #include <strstream> 32 #include "Randomize.hh" 36 #include "Randomize.hh" 33 #include "G4Threading.hh" << 34 #include "G4AutoLock.hh" << 35 37 36 #include "G4ImportanceAlgorithm.hh" 38 #include "G4ImportanceAlgorithm.hh" 37 39 38 #include <sstream> << 40 G4ImportanceAlgorithm::G4ImportanceAlgorithm(): fWorned(false) >> 41 {} 39 42 40 namespace << 43 G4ImportanceAlgorithm::~G4ImportanceAlgorithm() 41 { 44 { 42 G4Mutex ImportanceMutex = G4MUTEX_INITIALIZE << 45 if(fWorned) { >> 46 G4cout << G4endl; >> 47 Warning("~G4ImportanceAlgorithm: ipre_over_ipost ! in [0.25, 4] seen"); >> 48 G4cout << G4endl; >> 49 } 43 } 50 } 44 51 45 G4ImportanceAlgorithm::G4ImportanceAlgorithm() << 46 << 47 G4ImportanceAlgorithm::~G4ImportanceAlgorithm( << 48 << 49 G4Nsplit_Weight 52 G4Nsplit_Weight 50 G4ImportanceAlgorithm::Calculate(G4double ipre 53 G4ImportanceAlgorithm::Calculate(G4double ipre, 51 G4double ipos << 54 G4double ipost, 52 G4double init 55 G4double init_w) const 53 { 56 { 54 G4AutoLock l(&ImportanceMutex); << 57 G4Nsplit_Weight nw = {0,0}; 55 G4Nsplit_Weight nw; << 58 if (ipost>0.){ 56 if (ipost>0.) << 59 if (!(ipre>0.)){ 57 { << 60 Error("G4ImportanceAlgorithm::Calculate() - ipre==0."); 58 if (!(ipre>0.)) << 59 { << 60 Error("Calculate() - ipre==0."); << 61 } 61 } 62 G4double ipre_over_ipost = ipre/ipost; 62 G4double ipre_over_ipost = ipre/ipost; 63 if ((ipre_over_ipost<0.25 || ipre_over_ipo << 63 if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) { 64 { << 64 std::ostrstream os; 65 std::ostringstream os; << 65 os << "Calculate: ipre_over_ipost ! in [0.25, 4]: ipre_over_ipost = " 66 os << "Calculate() - ipre_over_ipost ! i << 66 << ipre_over_ipost << '\0' << G4endl; 67 << "ipre_over_ipost = " << ipre_over_ << 68 Warning(os.str()); 67 Warning(os.str()); 69 fWarned = true; << 68 fWorned = true; 70 if (ipre_over_ipost<=0) << 69 if (ipre_over_ipost<=0) { 71 { << 70 Error("G4ImportanceAlgorithm::Calculate() - ipre_over_ipost<=0"); 72 Error("Calculate() - ipre_over_ipost<= << 73 } 71 } 74 } 72 } 75 if (init_w<=0.) << 73 if (init_w<=0.) { 76 { << 74 Error("G4ImportanceAlgorithm::Calculate() - iniitweight<= 0. found"); 77 Error("Calculate() - iniitweight<= 0. fo << 78 } 75 } 79 76 80 // default geometrical splitting 77 // default geometrical splitting 81 // in integer mode 78 // in integer mode 82 // for ipre_over_ipost <= 1 79 // for ipre_over_ipost <= 1 83 G4double inv = 1./ipre_over_ipost; 80 G4double inv = 1./ipre_over_ipost; 84 nw.fN = static_cast<G4int>(inv); 81 nw.fN = static_cast<G4int>(inv); 85 nw.fW = init_w * ipre_over_ipost; 82 nw.fW = init_w * ipre_over_ipost; 86 83 87 // geometrical splitting for double mode 84 // geometrical splitting for double mode 88 if (ipre_over_ipost<1) << 85 if (ipre_over_ipost<1) { 89 { << 86 if ( static_cast<G4double>(nw.fN) != inv) { 90 if ( static_cast<G4double>(nw.fN) != inv << 87 // double mode 91 { << 88 // probability p for splitting into n+1 tracks 92 // double mode << 89 G4double p = inv - nw.fN; 93 // probability p for splitting into n+ << 90 // get a random number out of [0,1) 94 G4double p = inv - nw.fN; << 91 G4double r = G4UniformRand(); 95 // get a random number out of [0,1) << 92 if (r<p) { 96 G4double r = G4UniformRand(); << 93 nw.fN++; 97 if (r<p) << 94 } 98 { << 99 ++nw.fN; << 100 } << 101 } 95 } 102 } 96 } 103 else if (ipre_over_ipost>1) // russian r << 97 // ipre_over_ipost > 1 104 { << 98 // russian roulett >> 99 else if (ipre_over_ipost>1) { 105 // probabiity for killing track 100 // probabiity for killing track 106 G4double p = 1-inv; 101 G4double p = 1-inv; 107 // get a random number out of [0,1) 102 // get a random number out of [0,1) 108 G4double r = G4UniformRand(); 103 G4double r = G4UniformRand(); 109 if (r<p) << 104 if (r<p) { 110 { << 105 // kill track 111 // kill track << 106 nw.fN = 0; 112 nw.fN = 0; << 107 nw.fW = 0; 113 nw.fW = 0; << 114 } 108 } 115 else << 109 else { 116 { << 110 nw.fN = 1; 117 nw.fN = 1; << 118 } 111 } 119 } 112 } 120 } 113 } 121 l.unlock(); << 122 << 123 return nw; 114 return nw; 124 } 115 } 125 116 126 void G4ImportanceAlgorithm::Error(const G4Stri << 117 void G4ImportanceAlgorithm::Error(const G4String &m) const 127 { 118 { >> 119 G4cerr << "ERROR - G4ImportanceAlgorithm: " << m << G4endl; 128 G4Exception("G4ImportanceAlgorithm::Error()" 120 G4Exception("G4ImportanceAlgorithm::Error()", 129 "GeomBias0002", FatalException, << 121 "FatalException", FatalException, m); 130 } 122 } 131 123 132 void G4ImportanceAlgorithm::Warning(const G4St << 124 void G4ImportanceAlgorithm::Warning(const G4String &m) const 133 { 125 { 134 G4Exception("G4ImportanceAlgorithm::Warning( 126 G4Exception("G4ImportanceAlgorithm::Warning()", 135 "GeomBias1001", JustWarning, msg << 127 "Notification", JustWarning, m); 136 } 128 } 137 129