G4CascadeFunctions.icc

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 #ifndef G4_CASCADE_FUNCTIONS_ICC
00027 #define G4_CASCADE_FUNCTIONS_ICC
00028 // $Id$
00029 //
00030 // 20100512  M. Kelsey -- Pass std::vector<> buffer as argument to
00031 //              getOutgoingPartTypes().
00032 // 20100803  M. Kelsey -- Add printing function for debugging
00033 // 20100804  M. Kelsey -- Pretty up printing function
00034 // 20110725  M. Kelsey -- Use ctor to register table in lookup factory
00035 // 20110728  M. Kelsey -- Fix Coverity #22955, recursive #include; fix
00036 //              Coverity #20228, test (mult>maxMult), set to max if over
00037 // 20110916  M. Kelsey -- Drop self-registration due to platform inconsistencies
00038 //              Drop "inline" keyword on complex functions
00039 // 20110923  M. Kelsey -- Add optional ostream& argument to printTable(),
00040 //              pass through to SAMP and DATA
00041 
00042 #include "G4CascadeChannelTables.hh"
00043 #include "globals.hh"
00044 
00045 
00046 // Constructor registers table in lookup
00047 
00048 template <class DATA, class SAMP>
00049 G4CascadeFunctions<DATA,SAMP>::G4CascadeFunctions() : SAMP() {}
00050 
00051 
00052 // Compare summed partial cross section with total cross section
00053 // Truncate multiplicity at maximum if summed < total
00054 
00055 template <class DATA, class SAMP>
00056 G4int G4CascadeFunctions<DATA,SAMP>::getMultiplicity(G4double ke) const {
00057   // Use pointer comparison to see whether tot is just a ref to sum)
00058   if (&DATA::data.sum != &DATA::data.tot) {
00059     G4double summed = this->findCrossSection(ke, DATA::data.sum); 
00060     G4double total  = this->findCrossSection(ke, DATA::data.tot);
00061     if (G4UniformRand() > summed/total) return DATA::data.maxMultiplicity();
00062   }
00063 
00064   return this->findMultiplicity(ke, DATA::data.multiplicities);
00065 }
00066 
00067 
00068 // Generate list of final state particles
00069 
00070 template <class DATA, class SAMP>
00071 void G4CascadeFunctions<DATA,SAMP>::
00072 getOutgoingParticleTypes(std::vector<G4int>& kinds, 
00073                          G4int mult, G4double ke) const {
00074   const G4int maxMult = DATA::data.maxMultiplicity();
00075 
00076   if (mult > maxMult) {
00077     G4cerr << " Illegal multiplicity " << mult << " > " << maxMult << G4endl;
00078     mult = maxMult;
00079   }
00080 
00081   kinds.clear();
00082   kinds.reserve(mult);
00083 
00084   G4int channel = this->findFinalStateIndex(mult, ke, DATA::data.index,
00085                                             DATA::data.crossSections);
00086 #ifdef G4CASCADE_DEBUG_SAMPLER
00087   G4cout << " getOutgoingParticleTypes: mult=" << mult << " KE=" << ke
00088          << ": channel=" << channel << G4endl;
00089 #endif
00090 
00091   // Identify final-state array to be copied
00092   const G4int* chan = 0;
00093   if (mult == 2) chan = DATA::data.x2bfs[channel];
00094   if (mult == 3) chan = DATA::data.x3bfs[channel];
00095   if (mult == 4) chan = DATA::data.x4bfs[channel];
00096   if (mult == 5) chan = DATA::data.x5bfs[channel];
00097   if (mult == 6) chan = DATA::data.x6bfs[channel];
00098   if (mult == 7) chan = DATA::data.x7bfs[channel];
00099   if (mult == 8) chan = DATA::data.x8bfs[channel];
00100   if (mult == 9) chan = DATA::data.x9bfs[channel];
00101 
00102   if (!chan) {
00103     G4cerr << " getOutgoingParticleTypes: invalid multiplicity " << mult
00104            << G4endl;
00105     return;
00106   }
00107 
00108   kinds.insert(kinds.begin(), chan, chan+mult); // Transfer data into vector
00109   return;
00110 }
00111 
00112 
00113 // Dump lookup tables, including interpolation bins, to log file
00114 
00115 template <class DATA, class SAMP>
00116 void G4CascadeFunctions<DATA,SAMP>::printTable(std::ostream& os) const {
00117   os << " ---------- " << DATA::data.name << " ----------" << G4endl;
00118   SAMP::print(os);
00119   DATA::data.print(os);
00120   os << " ------------------------------" << G4endl;
00121 }
00122 
00123 #endif  /* G4_CASCADE_FUNCTIONS_ICC */

Generated on Mon May 27 17:47:49 2013 for Geant4 by  doxygen 1.4.7