G4ImportanceAlgorithm.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4ImportanceAlgorithm.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4Types.hh"
00037 #include <sstream>
00038 #include "Randomize.hh"
00039 
00040 #include "G4ImportanceAlgorithm.hh"
00041 
00042 G4ImportanceAlgorithm::G4ImportanceAlgorithm(): fWorned(false)
00043 {
00044 }
00045 
00046 G4ImportanceAlgorithm::~G4ImportanceAlgorithm()
00047 {
00048 }
00049 
00050 G4Nsplit_Weight
00051 G4ImportanceAlgorithm::Calculate(G4double ipre,
00052                                  G4double ipost,
00053                                  G4double init_w) const
00054 {
00055   G4Nsplit_Weight nw = {0,0};
00056   if (ipost>0.){
00057     if (!(ipre>0.)){
00058       Error("Calculate() - ipre==0.");
00059     }
00060     G4double ipre_over_ipost = ipre/ipost;
00061     if ((ipre_over_ipost<0.25 || ipre_over_ipost> 4) && !fWorned) {
00062       std::ostringstream os;
00063       os << "Calculate() - ipre_over_ipost ! in [0.25, 4]." << G4endl
00064          << "ipre_over_ipost = " << ipre_over_ipost << ".";
00065       Warning(os.str());
00066       fWorned = true;
00067       if (ipre_over_ipost<=0) {
00068         Error("Calculate() - ipre_over_ipost<=0.");
00069       }
00070     }
00071     if (init_w<=0.) {
00072       Error("Calculate() - iniitweight<= 0. found!");
00073     }
00074 
00075     // default geometrical splitting 
00076     // in integer mode 
00077     // for ipre_over_ipost <= 1
00078     G4double inv = 1./ipre_over_ipost;
00079     nw.fN = static_cast<G4int>(inv);
00080     nw.fW = init_w * ipre_over_ipost;
00081     
00082     // geometrical splitting for double mode
00083     if (ipre_over_ipost<1) {
00084       if ( static_cast<G4double>(nw.fN) != inv) {
00085         // double mode
00086         // probability p for splitting into n+1 tracks
00087         G4double p = inv - nw.fN;
00088         // get a random number out of [0,1)
00089         G4double r = G4UniformRand();
00090         if (r<p) {
00091           nw.fN++;
00092         } 
00093       }  
00094     }
00095     // ipre_over_ipost > 1
00096     //  russian roulett
00097     else if (ipre_over_ipost>1) {
00098       // probabiity for killing track
00099       G4double p = 1-inv;
00100       // get a random number out of [0,1)
00101       G4double r = G4UniformRand();
00102       if (r<p) {
00103         // kill track
00104         nw.fN = 0;
00105         nw.fW = 0;
00106       }
00107       else {
00108         nw.fN = 1;     
00109       }
00110     }
00111   }
00112   return nw;
00113 }
00114 
00115 void G4ImportanceAlgorithm::Error(const G4String &msg) const
00116 {
00117   G4Exception("G4ImportanceAlgorithm::Error()",
00118               "GeomBias0002", FatalException, msg);
00119 }
00120 
00121 void G4ImportanceAlgorithm::Warning(const G4String &msg) const
00122 {
00123   G4Exception("G4ImportanceAlgorithm::Warning()",
00124               "GeomBias1001", JustWarning, msg);
00125 }

Generated on Mon May 27 17:48:33 2013 for Geant4 by  doxygen 1.4.7