G4Generator2BS.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 // $Id$
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:     G4Generator2BS
00034 //
00035 // Author:        Andreia Trindade (andreia@lip.pt)
00036 //                Pedro Rodrigues  (psilva@lip.pt)
00037 //                Luis Peralta     (luis@lip.pt)
00038 //
00039 // Creation date: 2 June 2003
00040 //
00041 // Modifications: 
00042 // 02 Jun 2003               First implementation acording with new design
00043 // 05 Nov 2003  MGP          Fixed std namespace
00044 // 17 Nov 2003  MGP          Fixed compilation problem on Windows                  
00045 // 12 Oct 2010  V.Ivanchenko Moved RejectionFunction inline, use G4Pow to speadup
00046 // 09 May 2011  L.Pandola    Initialize private members, to avoid Coverity warning
00047 //
00048 // Class Description: 
00049 //
00050 // Concrete base class for Bremsstrahlung Angular Distribution Generation 
00051 // 2BS Distribution
00052 //
00053 // Class Description: End 
00054 //
00055 // -------------------------------------------------------------------
00056 //
00057 
00058 #include "G4Generator2BS.hh"
00059 #include "Randomize.hh"   
00060 #include "G4PhysicalConstants.hh"
00061 #include "G4SystemOfUnits.hh"
00062 #include "G4Pow.hh"   
00063 
00064 G4Generator2BS::G4Generator2BS(const G4String&)
00065   : G4VEmAngularDistribution("AngularGen2BS"),fz(1),ratio(1),
00066     ratio1(1),ratio2(1),delta(0)
00067 {
00068   g4pow = G4Pow::GetInstance();
00069   nwarn = 0;
00070 }
00071 
00072 G4Generator2BS::~G4Generator2BS() 
00073 {}
00074 
00075 G4ThreeVector& G4Generator2BS::SampleDirection(const G4DynamicParticle* dp,
00076                                                G4double final_energy,
00077                                                G4int Z,
00078                                                const G4Material*)
00079 {
00080 
00081   // Adapted from "Improved bremsstrahlung photon angular sampling in the EGS4 code system"
00082   // by Alex F. Bielajew, Rahde Mohan anc Chen-Shou Chui, PIRS-0203
00083   // Ionizing Radiation Standards
00084   // Institute for National Measurement Standards 
00085   // National Research Council of Canada
00086   // Departement of Medical Physics, Memorial Sloan-Kettering Cancer Center, New York
00087 
00088   G4double energy = dp->GetTotalEnergy();
00089   ratio = final_energy/energy;
00090   ratio1 = (1 + ratio)*(1 + ratio);
00091   ratio2 = 1 + ratio*ratio;
00092 
00093   G4double gamma = energy/electron_mass_c2;
00094   G4double beta  = std::sqrt((gamma - 1)*(gamma + 1))/gamma;
00095 
00096   //G4double Zeff = std::sqrt(static_cast<G4double>(Z) * (static_cast<G4double>(Z) + 1.0));
00097   //z = (0.00008116224*(std::pow(Zeff,0.3333333)));
00098 
00099   // VI speadup
00100   fz = 0.00008116224*g4pow->Z13(Z)*g4pow->Z13(Z+1);
00101 
00102   // majoranta
00103   G4double ymax = 2*beta*(1 + beta)*gamma*gamma;
00104   G4double gMax = RejectionFunction(0.0);
00105   gMax = std::max(gMax,RejectionFunction(ymax));
00106 
00107   G4double y, gfun;
00108 
00109   do{
00110     G4double q = G4UniformRand();
00111     y = q*ymax/(1 + ymax*(1 - q));
00112     gfun = RejectionFunction(y);
00113 
00114     // violation point
00115     if(gfun > gMax && nwarn >= 20) {
00116       ++nwarn;
00117       G4cout << "### WARNING in G4Generator2BS: Etot(MeV)= " << energy/MeV 
00118              << "  Egamma(MeV)" << (energy - final_energy)/MeV
00119              << " gMax= " << gMax << "  < " << gfun
00120              << "  results are not reliable!" 
00121              << G4endl;
00122       if(20 == nwarn) { 
00123         G4cout << "   WARNING in G4Generator2BS is closed" << G4endl; 
00124       }
00125     }
00126 
00127   } while(G4UniformRand()*gMax > gfun || y > ymax);
00128 
00129   
00130   G4double cost = 1 - 2*y/ymax;
00131   G4double sint = std::sqrt((1 - cost)*(1 + cost));
00132   G4double phi  = twopi*G4UniformRand(); 
00133 
00134   fLocalDirection.set(sint*std::cos(phi), sint*std::sin(phi),cost);
00135   fLocalDirection.rotateUz(dp->GetMomentumDirection());
00136 
00137   return fLocalDirection;
00138 }
00139 
00140 void G4Generator2BS::PrintGeneratorInformation() const
00141 {
00142   G4cout << "\n" << G4endl;
00143   G4cout << "Bremsstrahlung Angular Generator is 2BS Generator "
00144          << "from 2BS Koch & Motz distribution (Rev Mod Phys 31(4), 920 (1959))" << G4endl;
00145   G4cout << "Sampling algorithm adapted from PIRS-0203" << G4endl;
00146   G4cout << "\n" << G4endl;
00147 } 
00148 

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