Main Page   Compound List   File List   Compound Members   File Members  

ReactorScint.cpp

00001 #include "ReactorConstants.hh"
00002 #include "ReactorScint.hh"
00003 #include "ReactorFortran.hh"
00004 #include "ReactorXC.hh"
00005 #include <cmath>
00006 #include <iostream>
00007 using namespace std;
00008 ReactorScint::ReactorScint(){
00009 
00010   Points = 0;
00011   RxyzPoints = new double[4*Points];
00012   PxyzPoints = new double[4*Points];
00013   NextXYZ = RxyzPoints+1;
00014   NextEnergy = PxyzPoints;
00015 
00016 }
00017 //
00018 //  This constructor puts all the light at the point and time specified by
00019 //  rxyz.    
00020 //
00021 ReactorScint::ReactorScint(double e,double t,double* rxyz){
00022 
00023   RxyzPoints = new double[4];
00024   PxyzPoints = new double[4];
00025   //
00026   for(int i=0;i<3;i++){
00027     *(RxyzPoints+i+1) = *(rxyz+i);
00028     *(PxyzPoints+i+1) = 0;
00029   }
00030   *RxyzPoints=t;
00031   *PxyzPoints=e;
00032   //
00033   Points = 1;
00034   NextEnergy = PxyzPoints;
00035   NextTime = RxyzPoints;
00036   NextXYZ = RxyzPoints+1;
00037 }
00038 //
00039 // This constructor takes a photon and generates an array of light outputs via
00040 // Compton scatters
00041 //
00042 ReactorScint::ReactorScint(ReactorConstants& RC,
00043                            double t,double* rxyz,double* pxyz){
00044 
00045   //
00046   // make a guess at max number of hits
00047   //
00048   Points = 25;
00049   RxyzPoints = new double[4*Points];
00050   PxyzPoints = new double[4*Points];
00051   NextTime = RxyzPoints;
00052   NextXYZ = RxyzPoints+1;
00053   NextEnergy = PxyzPoints;
00054   
00055   int scatters=0;
00056   double k[4];
00057   double r[4];
00058   for(int i=1;i<4;i++){
00059     k[i]=pxyz[i];
00060     r[i]=rxyz[i-1];
00061   }
00062   r[0] = t;
00063   k[0] = pxyz[0];
00064   scatters++;
00065   //
00066   double egamma = pxyz[0];
00067   double* Rptr=RxyzPoints;
00068   double* Pptr=PxyzPoints;
00069   while(egamma>TooSoftToTrack&&scatters<Points){
00070     GammaCompton(RC,k);
00071     //
00072     double range = GammaComptonRange("scintillator",egamma);
00073     float rv[1];
00074     int len=1;
00075     ranlux_(rv,len);
00076     range*=log(1/rv[0]);
00077     //
00078     scatters++;
00079     for(int i=1;i<4;i++){
00080       *(Pptr+i) = k[i]; 
00081       r[i]+=range*k[i]/k[0];
00082       *(Rptr+i) = r[i];
00083     }
00084     double egammalast = egamma;
00085     egamma = k[0];
00086     *Pptr = egammalast-egamma;
00087     *Rptr = *(Rptr-4)+range/RC.c*RC.refracSc;
00088     //
00089     Pptr+=4;
00090     Rptr+=4;
00091   }
00092   //
00093   // put remaining energy in the last point
00094   //
00095   *Pptr=egamma;
00096   *Rptr=-1;
00097   for(int i = 1;i<4;i++)*Pptr++=0;
00098   for(int i = 1;i<4;i++)*Rptr++=0;
00099   //
00100   // Trim the size
00101   //
00102   double* Ptemp = new double[4*scatters];
00103   double* Rtemp = new double[4*scatters];
00104   for(int i=0;i<4*scatters;i++){
00105     *(Ptemp+i) = *(PxyzPoints+i);
00106     *(Rtemp+i) = *(RxyzPoints+i);
00107   }
00108   Points=scatters;
00109   delete[] PxyzPoints;
00110   delete[] RxyzPoints;
00111   RxyzPoints = new double[4*Points];
00112   PxyzPoints = new double[4*Points];
00113   for(int i=0;i<4*scatters;i++){
00114     *(PxyzPoints+i)=*(Ptemp+i);
00115     *(RxyzPoints+i)=*(Rtemp+i);
00116   }
00117   NextEnergy = PxyzPoints;
00118   NextTime = RxyzPoints;
00119   NextXYZ = RxyzPoints+1;
00120   delete[] Ptemp;
00121   delete[] Rtemp;
00122 }
00123 
00124 ReactorScint::~ReactorScint(){
00125 
00126   delete[] RxyzPoints;
00127   delete[] PxyzPoints;
00128 
00129 }
00130 
00131 ReactorScint::ReactorScint(const ReactorScint& G){
00132 
00133   Points = G.Points;
00134   RxyzPoints = new double[4*Points];
00135   double* pold = G.RxyzPoints+4*Points;
00136   double* pnew = RxyzPoints+4*Points;
00137   while(pnew>RxyzPoints)*--pnew = *--pold;
00138 
00139   PxyzPoints = new double[4*Points];
00140   pold = G.PxyzPoints+4*Points;
00141   pnew = PxyzPoints+4*Points;
00142   while(pnew>PxyzPoints)*--pnew = *--pold;
00143 
00144   NextXYZ = RxyzPoints+1;
00145   NextTime = RxyzPoints;
00146   NextEnergy = PxyzPoints;
00147 
00148 }
00149 
00150 
00151 ReactorScint& ReactorScint::operator=(const ReactorScint& rhs){
00152 
00153   if(this == &rhs)return *this;
00154 
00155   Points = rhs.Points;
00156   delete[] RxyzPoints;
00157   RxyzPoints = new double[4*Points];
00158   double* pold = rhs.RxyzPoints+4*Points;
00159   double* pnew = RxyzPoints+4*Points;
00160   while(pnew>RxyzPoints)*--pnew = *--pold;
00161 
00162   delete[] PxyzPoints;
00163   PxyzPoints = new double[4*Points];
00164   pold = rhs.PxyzPoints+4*Points;
00165   pnew = PxyzPoints+4*Points;
00166   while(pnew>PxyzPoints)*--pnew = *--pold;
00167 
00168   NextXYZ = RxyzPoints+1;
00169   NextTime = RxyzPoints;
00170   NextEnergy = PxyzPoints;
00171 
00172   return *this;
00173 }
00174 double ReactorScint::GetNextEnergy(){
00175 
00176   if(NextEnergy>=PxyzPoints+4*Points){
00177     return -1;
00178   }
00179   NextEnergy+=4;
00180   return *(NextEnergy-4);
00181 }
00182 double ReactorScint::GetNextTime(){
00183 
00184   if(NextTime>=RxyzPoints+4*Points){
00185     return -1;
00186   }
00187   NextTime+=4;
00188   return *(NextTime-4);
00189 }
00190 double* ReactorScint::GetNextXYZ(){
00191 
00192   if(NextXYZ>=RxyzPoints+4*Points){
00193     return 0;
00194   }
00195   NextXYZ+=4;
00196   return NextXYZ-4;
00197 }
00198 
00199 void ReactorScint::ResetNext(){
00200   NextTime = RxyzPoints;
00201   NextXYZ = NextTime+1;
00202   NextEnergy = PxyzPoints;
00203 }
00204 

Generated on Fri Oct 22 13:56:26 2004 for ReactorFsim by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002