Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EGS.cxx

Go to the documentation of this file.
00001 // -*- C++ -*-  $Id: EGS.cxx,v 1.2 2001/01/25 22:24:33 burnett Exp $
00002 //
00003 // This file is part of Gismo 2
00004 //
00005 // file: egs.cpp
00006 // created 1-Dec-1991, T. Burnett
00007 
00008 
00009 // Contents ----------------------------------------------------------------
00010 //
00011 //      EGS::EGS
00012 //      EGS::~EGS
00013 //      EGS::rotate
00014 //      EGS::interact
00015 //      EGS::meanFreePath
00016 //      EGS::dedx
00017 //
00018 // Description
00019 //
00020 //      Implementation of EGS particle routines
00021 //
00022 // End --------------------------------------------------------------------
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include "config.h"
00026 #endif
00027 
00028 #include "EGS.h"
00029 
00030 #include "PEGSData.h"
00031 
00032 #include "Random.h"
00033 #include "facilities/error.h"
00034 #include <math.h>
00035 #include <iomanip>
00036 
00037 // ----------------constructor EGS::EGS ----------------------------------
00038 
00039 EGS::EGS(EGS* old)
00040 {
00041     // if arg present, assume that it is the top of the particle stack:
00042     // add this entry to it, and copy all data
00043 
00044     if (old )
00045     {
00046         *this = *old;   // copy data
00047         old->next = this; // link in
00048         prev = old;
00049         next = 0;
00050 
00051     }
00052     else
00053     {   // this is the TOS: set up defaults
00054         next=prev=0;
00055         x=y=z=0;
00056         u=v=0; w=1.;
00057         iq = 0;
00058     }
00059 }
00060 
00061 // ----------------destructor   EGS::~EGS ------------------------------
00062 
00063 EGS::~EGS()
00064 {
00065    // remove this particle and all following it in the stack
00066 
00067    EGS* pt = next;
00068    if (prev ) prev->next = 0;
00069 
00070    if( next )
00071         delete pt;
00072  }
00073 
00074 // ----------------member function EGS::printOn ------------------------
00075 
00076 void EGS::printOn(std::ostream& cout)
00077 {   //cout << setprecision(3);
00078 
00079 #if 1
00080     std::cout << std::setw(5)  << iq
00081          << std::setw(10) << e
00082          << std::setw(10) << u
00083          << std::setw(10) << v
00084          << std::setw(10) << w
00085          << '\n';
00086 #else
00087     std::cout << iq << e << u << v << w << '\n';
00088 #endif
00089     if (next != NULL) next->printOn(cout);
00090 }
00091 
00092 
00093 // ----------------member function EGS::rotate ------------------------
00094 
00095 void EGS::rotate(double costhe, double phi)
00096 {
00097     double sinthsq = 1.-costhe*costhe;
00098     rotate(costhe, phi, sinthsq<0? 0: sqrt(sinthsq)  );
00099 }
00100 void EGS::rotate(double costhe, double phi, double sinthe)
00101 {
00102     // rotate the direction cosines by (theta, phi)
00103     // --------------------------------------------
00104     //  see h.h. nagel dissertation for coordinate system description.
00105     //  a rotation is performed to transform direction cosines of the
00106     //  particle back to the physical frame (from the transport frame)
00107 
00108     static float phiold=0, sinphi=0, cosphi=1;
00109 
00110     if (phi!=phiold)
00111     {   if (phi==phiold+M_PI )
00112         {   // this happpens for the 2nd of correlated particles
00113             sinphi = -sinphi; cosphi = -cosphi;
00114         }
00115         else
00116         {   sinphi = sin(phi); cosphi = cos(phi);
00117         }
00118         phiold = phi;
00119     }
00120 
00121     float  sinps2=u*u+v*v;
00122 
00123     //   if sinps2 is small, no rotation is needed
00124 
00125     if (sinps2 < 1.0e-20)
00126     {
00127         //small polar angle case
00128         u = sinthe*cosphi;
00129         v = sinthe*sinphi;
00130         w = w*costhe;
00131     }
00132     else
00133     {
00134         //large polar angle case
00135         float a=u, b=v, c=w,
00136               sinpsi=sqrt(sinps2),
00137               us=sinthe*cosphi,
00138               vs=sinthe*sinphi,
00139               sindel=b/sinpsi,
00140               cosdel=a/sinpsi;
00141         u = c*cosdel*us - sindel*vs + a*costhe;
00142         v = c*sindel*us + cosdel*vs + b*costhe;
00143         w =  -sinpsi*us             + c*costhe;
00144     }
00145 }
00146 
00147 // ----------------member function EGS::interact ------------------------
00148 
00149 void EGS::interact(const PEGSData &m)
00150 {
00151     // interact the particle in the material. The particle is assumed
00152     // to be at the top of the stack (but no check is made) It is
00153     // replaced by its daughter(s)
00154 
00155   //    int qIn = iq;
00156 
00157     PEGSData::channel which = m.chooseChannel(Random::flat(),e,iq);
00158     switch (which)    {
00159         case PEGSData::STOP:    e=rm;     break;
00160         case PEGSData::BREMS:   brems(m); break;  //e- -> e- + gamma
00161         case PEGSData::MOLLER:  moller(m);break;  //e- -> e- + e-
00162         case PEGSData::ANNIH:   annih();  break;  //e+ => gamma+gamma
00163         case PEGSData::BHABHA:  bhabha(m);break;  //e+ -> e+ + e-
00164         case PEGSData::PAIR:  pairProd(m);break;  //gamma-> e+ + e-
00165         case PEGSData::COMPT:   compt();  break;  //gamma-> gamma + e-
00166         case PEGSData::PHOTO:   photo(m); break;  //gamma-> e- (+gamma)
00167         case PEGSData::RAYLEIGH: rayleigh(m); break; // gamma->gamma
00168         
00169 
00170     }
00171 //    if(!next && qIn)
00172 //         WARNING("EGS::interact -- next == 0!! ");
00173 }
00174 //--------------------------------------------------------------------
00175 //------------------member function EGS::rayleigh --------------------
00176 //--------------------------------------------------------------------
00177 
00178 /* should duplicate the following EGS4 2.0 mortran:
00179     :sampling-loop: loop [
00180 
00181         $randomset xxx;
00182         $set interval xxx,rco;
00183         $evaluate x2 using rsct(xxx);
00184 
00185         q2=x2*rmsq/(20.60744*20.60744);
00186         costhe=1.-q2/(2.*e(np)*e(np));
00187         if (abs(costhe).gt.1.0) go to :sampling-loop:;
00188 
00189         csqthe=costhe*costhe;
00190         rejf=(1.0+csqthe)/2.0;
00191         $randomset rnnorj;
00192 
00193     ] until rnnorj.le.rejf;
00194 
00195     sinthe=sqrt(1.0-csqthe);
00196     call uphi(2,1);
00197 
00198 */
00199 void EGS::rayleigh(const PEGSData &m )
00200 {
00201     float costhe, rejf;
00202     do {
00203         float x2 = m.ph.rsct(Random::flat());
00204         float q2 = x2*rmsq/(20.60744*20.60744);
00205         costhe=1.-q2/(2.*e*e);
00206         if( abs(costhe) > 1.0 ) continue;
00207         float csqthe=costhe*costhe;
00208         rejf=(1.0+csqthe)/2.0;
00209         if( Random::flat() <= rejf ) break;
00210     } while(1);
00211 
00212     rotate( costhe, Random::flat(2.*M_PI) );
00213 }
00214 
00215 // ----------------- static variables ------------------------------
00216 double EGS::rm2 = 0.51100340; // electron mass in MeV
00217 double EGS::rm = rm2;
00218 
00219 double EGS::rmsq = rm2*rm2;
00220 
00221 
00222 

Generated at Wed Nov 21 12:20:25 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000