G4PenelopeSamplingData Class Reference

#include <G4PenelopeSamplingData.hh>


Public Member Functions

 G4PenelopeSamplingData (G4int npoints=150)
 ~G4PenelopeSamplingData ()
void AddPoint (G4double x0, G4double pac0, G4double a0, G4double b0, size_t ITTL0, size_t ITTU0)
size_t GetNumberOfStoredPoints ()
void Clear ()
void DumpTable ()
G4double GetX (size_t index)
G4double GetPAC (size_t index)
G4double GetA (size_t index)
G4double GetB (size_t index)
G4double SampleValue (G4double rndm)


Detailed Description

Definition at line 49 of file G4PenelopeSamplingData.hh.


Constructor & Destructor Documentation

G4PenelopeSamplingData::G4PenelopeSamplingData ( G4int  npoints = 150  ) 

Definition at line 37 of file G4PenelopeSamplingData.cc.

00037                                                             : 
00038   np(nPoints)
00039 {
00040   //create vectors
00041   x = new G4DataVector();
00042   pac = new G4DataVector();
00043   a = new G4DataVector();
00044   b = new G4DataVector();
00045   ITTL = new std::vector<size_t>;
00046   ITTU = new std::vector<size_t>;
00047 }

G4PenelopeSamplingData::~G4PenelopeSamplingData (  ) 

Definition at line 50 of file G4PenelopeSamplingData.cc.

00051 {
00052   if (x) delete x;
00053   if (pac) delete pac;
00054   if (a) delete a;
00055   if (b) delete b;
00056   if (ITTL) delete ITTL;
00057   if (ITTU) delete ITTU;
00058 }


Member Function Documentation

void G4PenelopeSamplingData::AddPoint ( G4double  x0,
G4double  pac0,
G4double  a0,
G4double  b0,
size_t  ITTL0,
size_t  ITTU0 
)

Definition at line 97 of file G4PenelopeSamplingData.cc.

References G4cout, G4endl, and GetNumberOfStoredPoints().

00099 {
00100   x->push_back(x0);
00101   pac->push_back(pac0);
00102   a->push_back(a0);
00103   b->push_back(b0);
00104   ITTL->push_back(ITTL0);
00105   ITTU->push_back(ITTU0);
00106 
00107   //check how many points we do have now
00108   size_t nOfPoints = GetNumberOfStoredPoints();
00109 
00110   if (nOfPoints > ((size_t)np))
00111     {
00112       G4cout << "G4PenelopeSamplingData::AddPoint() " << G4endl;
00113       G4cout << "WARNING: Up to now there are " << nOfPoints << " points in the table" << G4endl;
00114       G4cout << "while the anticipated (declared) number is " << np << G4endl;
00115     }
00116     return;
00117 }

void G4PenelopeSamplingData::Clear (  ) 

Definition at line 79 of file G4PenelopeSamplingData.cc.

00080 {
00081   if (x) delete x;
00082   if (pac) delete pac;
00083   if (a) delete a;
00084   if (b) delete b;
00085   if (ITTL) delete ITTL;
00086   if (ITTU) delete ITTU;
00087   //create vectors
00088   x = new G4DataVector();
00089   pac = new G4DataVector();
00090   a = new G4DataVector();
00091   b = new G4DataVector();
00092   ITTL = new std::vector<size_t>;
00093   ITTU = new std::vector<size_t>;
00094 }

void G4PenelopeSamplingData::DumpTable (  ) 

Definition at line 120 of file G4PenelopeSamplingData.cc.

References G4cout, G4endl, and GetNumberOfStoredPoints().

00121 {
00122   
00123   G4cout << "*************************************************************************" << G4endl;
00124   G4cout << GetNumberOfStoredPoints() << " points" << G4endl;
00125   G4cout << "*************************************************************************" << G4endl;
00126   for (size_t i=0;i<GetNumberOfStoredPoints();i++)
00127     {
00128       G4cout << i << " " << (*x)[i] << " " << (*pac)[i] << " " << (*a)[i] << " " << 
00129         (*b)[i] << " " << (*ITTL)[i] << " " << (*ITTU)[i] << G4endl;
00130     }
00131   G4cout << "*************************************************************************" << G4endl;
00132 }

G4double G4PenelopeSamplingData::GetA ( size_t  index  ) 

Definition at line 153 of file G4PenelopeSamplingData.cc.

00154 {
00155   if (index < a->size())
00156     return (*a)[index];
00157   else
00158     return 0;
00159 }

G4double G4PenelopeSamplingData::GetB ( size_t  index  ) 

Definition at line 162 of file G4PenelopeSamplingData.cc.

00163 {
00164   if (index < b->size())
00165     return (*b)[index];
00166   else
00167     return 0;
00168 }

size_t G4PenelopeSamplingData::GetNumberOfStoredPoints (  ) 

Definition at line 61 of file G4PenelopeSamplingData.cc.

References FatalException, G4endl, and G4Exception().

Referenced by AddPoint(), DumpTable(), G4PenelopeRayleighModel::SampleSecondaries(), and SampleValue().

00062 {
00063   size_t points = x->size();
00064 
00065   //check everything is all right
00066   if (pac->size() != points || a->size() != points || 
00067       b->size() != points || ITTL->size() != points ||
00068       ITTU->size() != points)
00069     {
00070       G4ExceptionDescription ed;
00071       ed << "Data vectors look to have different dimensions !" << G4endl;
00072       G4Exception("G4PenelopeSamplingData::GetNumberOfStoredPoints()","em2040",
00073                   FatalException,ed);      
00074     }
00075   return points;
00076 }

G4double G4PenelopeSamplingData::GetPAC ( size_t  index  ) 

Definition at line 144 of file G4PenelopeSamplingData.cc.

00145 {
00146   if (index < pac->size())
00147     return (*pac)[index];
00148   else
00149     return 0;
00150 }

G4double G4PenelopeSamplingData::GetX ( size_t  index  ) 

Definition at line 135 of file G4PenelopeSamplingData.cc.

Referenced by G4PenelopeRayleighModel::SampleSecondaries().

00136 {
00137   if (index < x->size())
00138     return (*x)[index];
00139   else
00140     return 0;
00141 }

G4double G4PenelopeSamplingData::SampleValue ( G4double  rndm  ) 

Definition at line 171 of file G4PenelopeSamplingData.cc.

References GetNumberOfStoredPoints().

Referenced by G4PenelopeRayleighModel::SampleSecondaries().

00172 {
00173   //One passes here a random number in (0,1).
00174   //Notice: it possible that is between (0,b) with b<1
00175   size_t points = GetNumberOfStoredPoints();
00176  
00177   size_t itn = (size_t) (maxRand*(points-1)); 
00178   size_t i = (*ITTL)[itn];
00179   size_t j = (*ITTU)[itn];
00180 
00181   while ((j-i) > 1)
00182     {
00183       size_t k = (i+j)/2;
00184       if (maxRand > (*pac)[k])
00185         i = k;
00186       else
00187         j = k;
00188     }
00189 
00190   //Sampling from the rational inverse cumulative distribution
00191   G4double result = 0;
00192 
00193   G4double rr = maxRand - (*pac)[i];
00194   if (rr > 1e-16)
00195     {
00196       G4double d = (*pac)[i+1]-(*pac)[i];
00197       result = (*x)[i]+
00198         ((1.0+(*a)[i]+(*b)[i])*d*rr/
00199          (d*d+((*a)[i]*d+(*b)[i]*rr)*rr))*((*x)[i+1]-(*x)[i]);      
00200     }
00201   else
00202     result = (*x)[i]; 
00203   
00204   return result;
00205 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:52:53 2013 for Geant4 by  doxygen 1.4.7