00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "G4NeutronHPField.hh"
00031 #include "G4HadronicException.hh"
00032 #include "G4ios.hh"
00033
00034
00035 G4NeutronHPField::G4NeutronHPField()
00036 {
00037 theData = new G4NeutronHPFieldPoint[100];
00038 nPoints=100;
00039 nEntries=0;
00040 theData->SetData(0,0,0);
00041 }
00042
00043 G4NeutronHPField::~G4NeutronHPField(){ delete [] theData;}
00044
00045 G4double G4NeutronHPField::GetY(G4double e, G4int j)
00046 {
00047 G4int low = 0;
00048 G4int high = 0;
00049 G4int i;
00050 for (i=1; i<nEntries/10; i++)
00051 {
00052 if(theData[10*i].GetX()>e) break;
00053 }
00054 if(i==(nEntries/10))
00055 {
00056 i=10*i;
00057 while (i<nEntries)
00058 {
00059 if(theData[i++].GetX()>e) break;
00060 }
00061 if (i==nEntries)
00062 {
00063 low = nEntries-1;
00064 high = nEntries-2;
00065 }else{
00066 low = i-1;
00067 high = i;
00068 }
00069 }else{
00070 for (G4int jj=0; jj<10; jj++)
00071 {
00072 if(theData[i].GetX()<e) break;
00073 i--;
00074 }
00075 low = i;
00076 high = i+1;
00077 }
00078 G4double x1, x2, y1, y2, x, y;
00079 x = e;
00080 x1 = theData[low] .GetX();
00081 x2 = theData[high].GetX();
00082 y1 = theData[low] .GetY(j);
00083 y2 = theData[high].GetY(j);
00084 y = x*(y2-y1)/(x2-x1);
00085 return y += y2-x2*(y2-y1)/(x2-x1);
00086 }
00087
00088 void G4NeutronHPField::Dump()
00089 {
00090 G4cout << nEntries<<G4endl;
00091 for(G4int i=0; i<nEntries; i++)
00092 {
00093 G4cout << theData[i].GetX()<<" ";
00094 for(G4int j=0; j<theData[i].GetDepth(); j++)
00095 {
00096 G4cout << theData[i].GetY(j)<<" ";
00097 }
00098 G4cout << G4endl;
00099 }
00100 }
00101
00102 void G4NeutronHPField::Check(G4int i)
00103 {
00104 if(i>nEntries) throw G4HadronicException(__FILE__, __LINE__, "Skipped some index numbers in G4NeutronHPField");
00105 if(i==nPoints)
00106 {
00107 nPoints += 50;
00108 G4NeutronHPFieldPoint * buff = new G4NeutronHPFieldPoint[nPoints];
00109
00110 for (G4int j=0; j<nEntries; j++)
00111 {
00112 buff[j] = theData[j];
00113 }
00114
00115 delete [] theData;
00116 theData = buff;
00117 }
00118 if(i==nEntries) nEntries=i+1;
00119 }