Main Page   Compound List   File List   Compound Members   File Members  

ReactorScint.cpp

00001 #include "ReactorConstants.hh"
00002 #include "ReactorDetector.hh"
00003 #include "ReactorScint.hh"
00004 #include "ReactorFortran.hh"
00005 #include "ReactorXC.hh"
00006 #include "DetectorDefaults.hh"
00007 #include <cmath>
00008 #include <iostream>
00009 using namespace std;
00010 ReactorScint::ReactorScint(){
00011 
00012   Points = 0;
00013   RxyzPoints = new double[4*Points];
00014   PxyzPoints = new double[4*Points];
00015   NextTime = RxyzPoints;
00016   NextXYZ = RxyzPoints+1;
00017   NextEnergy = PxyzPoints;
00018   TooSoftToTrack = 0.1;
00019 
00020 }
00021 //
00022 //  This constructor puts all the light at the point and time specified by
00023 //  rxyz.    
00024 //
00025 ReactorScint::ReactorScint(double e,double t,double* rxyz){
00026 
00027   RxyzPoints = new double[4];
00028   PxyzPoints = new double[4];
00029   //
00030   for(int i=0;i<3;i++){
00031     *(RxyzPoints+i+1) = *(rxyz+i);
00032     *(PxyzPoints+i+1) = 0;
00033   }
00034   *RxyzPoints=t;
00035   *PxyzPoints=e;
00036   //
00037   Points = 1;
00038   NextEnergy = PxyzPoints;
00039   NextTime = RxyzPoints;
00040   NextXYZ = RxyzPoints+1;
00041   //
00042 }
00043 //
00044 // This constructor takes a gamma and generates an array of light outputs via
00045 // Compton scatters
00046 //
00047 ReactorScint::ReactorScint(double e,double t,double* rxyz,double* pxyz,
00048                            double rzero, double rone, double rtwo){
00049   //
00050   // make a guess at max number of hits
00051   //
00052   Points = 25;
00053   RxyzPoints = new double[4*Points];
00054   PxyzPoints = new double[4*Points];
00055   NextTime = RxyzPoints;
00056   NextXYZ = RxyzPoints+1;
00057   NextEnergy = PxyzPoints;
00058   TooSoftToTrack = 0.1;
00059 
00060   int scatters=0;
00061   double k[4];
00062   double r[4];
00063   for(int i=0;i<3;i++){
00064     k[i+1]=pxyz[i];
00065     r[i+1]=rxyz[i];
00066   }
00067   r[0] = t;
00068   k[0] = e;
00069   //
00070   double egamma = e;
00071   double tgamma = t;
00072   //cout << "   initial egamma " << egamma << " tgamma " << tgamma << endl;
00073   double range = 0.;
00074   bool inside = true;
00075   double r1 = rone;
00076   double r2 = rtwo;
00077   double* Rptr=RxyzPoints;
00078   double* Pptr=PxyzPoints;
00079   //
00080   while(egamma>TooSoftToTrack && scatters<Points && inside==true){
00081 
00082     //cout << " scatter " << scatters << endl;
00083 
00084     double rsq = sqrt(r[1]*r[1] + r[2]*r[2] + r[3]*r[3]);
00085     //cout << "   radius " << rsq << endl;
00086     //
00087     // check that we're inside the detector
00088     //
00089     if(rsq > r2){
00090       inside = false;
00091       //cout << " radius " << rsq << " > " << r2 
00092       //   << ": outside steel vessel" << endl;
00093     }
00094     else{
00095       //
00096       // count the scatter
00097       //
00098       scatters++;
00099       //
00100       // set the material
00101       //
00102       std::string material = "scintillator";
00103       if(rsq > r1) material = "oil";
00104       //cout << "   material " << material << endl;
00105       //
00106       GammaCompton(k);
00107       //
00108       range = GammaComptonRange(material,egamma);
00109       float rv[1];
00110       int len=1;
00111       ranlux_(rv,len);
00112       range*=log(1/rv[0]);
00113       //cout << "   range " << range << endl;
00114       //
00115       for(int i=1;i<4;i++){
00116         *(Pptr+i) = k[i]; 
00117         r[i]+=range*k[i]/k[0];
00118         *(Rptr+i) = r[i];
00119       }
00120       //
00121       double egammalast = egamma;
00122       egamma = k[0];
00123       tgamma += range/c*REFRACSC;
00124       //cout << "   egamma " << egamma << " tgamma " << tgamma << endl;
00125       //
00126       //cout << "   egammalast-egamma " << egammalast-egamma << endl;
00127       *Pptr = egammalast-egamma;
00128       *Rptr = tgamma;
00129       //
00130       Pptr+=4;
00131       Rptr+=4;
00132     }
00133   }
00134   //
00135   // if still inside put remaining energy in the last point
00136   //
00137   if(inside){
00138     scatters++;
00139     //
00140     for(int i=1;i<4;i++){
00141       *(Pptr+i) = k[i]; 
00142       r[i]+=range*k[i]/k[0];
00143       *(Rptr+i) = r[i];
00144     }
00145     *Pptr++=egamma;
00146     *Rptr++=tgamma;
00147   }
00148   //
00149   // Trim the size
00150   //
00151   double* Ptemp = new double[4*scatters];
00152   double* Rtemp = new double[4*scatters];
00153   for(int i=0;i<4*scatters;i++){
00154     *(Ptemp+i) = *(PxyzPoints+i);
00155     *(Rtemp+i) = *(RxyzPoints+i);
00156   }
00157   Points=scatters;
00158   delete[] PxyzPoints;
00159   delete[] RxyzPoints;
00160   RxyzPoints = new double[4*Points];
00161   PxyzPoints = new double[4*Points];
00162   for(int i=0;i<4*scatters;i++){
00163     *(PxyzPoints+i)=*(Ptemp+i);
00164     *(RxyzPoints+i)=*(Rtemp+i);
00165   }
00166   NextEnergy = PxyzPoints;
00167   NextTime = RxyzPoints;
00168   NextXYZ = RxyzPoints+1;
00169   delete[] Ptemp;
00170   delete[] Rtemp;
00171 
00172   /*
00173   cout << " " << scatters << " scatters:" << endl;
00174   for(int i = 0;i<scatters*4;i++)
00175     cout << "  PxyzPoints[" << i << "] " << PxyzPoints[i] << endl;
00176   for(int i = 0;i<scatters*4;i++)
00177     cout << "   RxyzPoints[" << i << "] " << RxyzPoints[i] << endl;
00178   */
00179 
00180 }
00181 
00182 ReactorScint::~ReactorScint(){
00183 
00184   delete[] RxyzPoints;
00185   delete[] PxyzPoints;
00186 
00187 }
00188 
00189 ReactorScint::ReactorScint(const ReactorScint& G){
00190 
00191   Points = G.Points;
00192   RxyzPoints = new double[4*Points];
00193   double* pold = G.RxyzPoints+4*Points;
00194   double* pnew = RxyzPoints+4*Points;
00195   while(pnew>RxyzPoints)*--pnew = *--pold;
00196 
00197   PxyzPoints = new double[4*Points];
00198   pold = G.PxyzPoints+4*Points;
00199   pnew = PxyzPoints+4*Points;
00200   while(pnew>PxyzPoints)*--pnew = *--pold;
00201 
00202   NextXYZ = RxyzPoints+1;
00203   NextTime = RxyzPoints;
00204   NextEnergy = PxyzPoints;
00205 
00206 }
00207 
00208 
00209 ReactorScint& ReactorScint::operator=(const ReactorScint& rhs){
00210 
00211   if(this == &rhs)return *this;
00212 
00213   Points = rhs.Points;
00214   delete[] RxyzPoints;
00215   RxyzPoints = new double[4*Points];
00216   double* pold = rhs.RxyzPoints+4*Points;
00217   double* pnew = RxyzPoints+4*Points;
00218   while(pnew>RxyzPoints)*--pnew = *--pold;
00219 
00220   delete[] PxyzPoints;
00221   PxyzPoints = new double[4*Points];
00222   pold = rhs.PxyzPoints+4*Points;
00223   pnew = PxyzPoints+4*Points;
00224   while(pnew>PxyzPoints)*--pnew = *--pold;
00225 
00226   NextXYZ = RxyzPoints+1;
00227   NextTime = RxyzPoints;
00228   NextEnergy = PxyzPoints;
00229 
00230   return *this;
00231 }
00232 double ReactorScint::GetNextEnergy(){
00233 
00234   if(NextEnergy>=PxyzPoints+4*Points){
00235     return -1.;
00236   }
00237   NextEnergy+=4;
00238   return *(NextEnergy-4);
00239 }
00240 double ReactorScint::GetNextTime(){
00241 
00242   if(NextTime>=RxyzPoints+4*Points){
00243     return -1.;
00244   }
00245   NextTime+=4;
00246   return *(NextTime-4);
00247 }
00248 double* ReactorScint::GetNextXYZ(){
00249 
00250   if(NextXYZ>=RxyzPoints+4*Points){
00251     return 0;
00252   }
00253   NextXYZ++;
00254   return NextXYZ-1;
00255 }
00256 
00257 void ReactorScint::ResetNext(){
00258   NextTime = RxyzPoints;
00259   NextXYZ = NextTime+1;
00260   NextEnergy = PxyzPoints;
00261 }
00262 

Generated on Mon Feb 21 16:11:19 2005 for ReactorFsim by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002