G4NeutronHPArbitaryTab.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 // neutron_hp -- source file
00027 // J.P. Wellisch, Nov-1996
00028 // A prototype of the low energy neutron transport model.
00029 //
00030 #include "G4NeutronHPArbitaryTab.hh"
00031 #include "G4ios.hh"
00032 
00033   G4double G4NeutronHPArbitaryTab::Sample(G4double anEnergy) 
00034   {
00035     G4int i;
00036     for(i=0;i<nDistFunc;i++)
00037     {
00038       if(anEnergy<theDistFunc[i].GetLabel()) break; // that is the energy we need
00039     }
00040     G4int low(0), high(0);
00041     if(i==nDistFunc) 
00042     {
00043       low = i-2;
00044       high = i-1;
00045     }
00046     else if(i==0)
00047     {
00048       if(nDistFunc==0)
00049       {
00050         G4cerr << "No distribution functions to sample "
00051              << "from in G4NeutronHPArbitaryTab::Sample"<<G4endl;
00052         throw G4HadronicException(__FILE__, __LINE__, "nDistFunc==0");
00053       } 
00054       else 
00055       {
00056         return theDistFunc[0].Sample();
00057       }
00058     }
00059     else
00060     {
00061       low = i-1;
00062       high = i;
00063     }
00064     //************************************************************************
00065     //EMendoza
00066     /*
00067       theBuffer.Merge(theManager.GetScheme(low), anEnergy, 
00068       theDistFunc+low, theDistFunc+high);
00069       return theBuffer.Sample();
00070     */
00071     //************************************************************************
00072     //New way to perform the 2D sampling:
00073     G4double elow=theDistFunc[low].GetLabel();
00074     G4double ehigh=theDistFunc[high].GetLabel();
00075     G4double rval=(anEnergy-elow)/(ehigh-elow);//rval is 0 for elow and 1 for ehigh
00076     G4double eoutlow=theLowThreshold[low]+rval*(theLowThreshold[high]-theLowThreshold[low]);
00077     G4double eouthigh=theHighThreshold[low]+rval*(theHighThreshold[high]-theHighThreshold[low]);
00078     G4double rand=G4UniformRand();
00079     G4double Eout_1=0,Eout_2=0;
00080     if(rval<rand){
00081       Eout_1=theDistFunc[low].Sample();
00082       Eout_2=eoutlow+(Eout_1-theLowThreshold[low])*(eouthigh-eoutlow)/(theHighThreshold[low]-theLowThreshold[low]);
00083     }
00084     else{
00085       Eout_1=theDistFunc[high].Sample();
00086       Eout_2=eoutlow+(Eout_1-theLowThreshold[high])*(eouthigh-eoutlow)/(theHighThreshold[high]-theLowThreshold[high]);
00087     }
00088     return Eout_2;
00089 
00090     //************************************************************************
00091   }

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