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 #include <iomanip>
00030 #include <fstream>
00031
00032 #include "G4AdjointCSMatrix.hh"
00033 #include "G4SystemOfUnits.hh"
00034 #include "G4AdjointInterpolator.hh"
00035
00037
00038 G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aBool){
00039 theLogPrimEnergyVector.clear();
00040 theLogCrossSectionVector.clear();
00041 theLogSecondEnergyMatrix.clear();
00042 theLogProbMatrix.clear();
00043 theLogProbMatrixIndex.clear();
00044 log0Vector.clear();
00045 nb_of_PrimEnergy=0;
00046 is_scat_proj_to_proj_case =aBool;
00047 dlog =0;
00048 }
00050
00051 G4AdjointCSMatrix::~G4AdjointCSMatrix(){
00052 theLogPrimEnergyVector.clear();
00053 theLogCrossSectionVector.clear();
00054 theLogSecondEnergyMatrix.clear();
00055 theLogProbMatrix.clear();
00056 }
00058
00059 void G4AdjointCSMatrix::Clear()
00060 {
00061 theLogPrimEnergyVector.clear();
00062 theLogCrossSectionVector.clear();
00063 theLogSecondEnergyMatrix.clear();
00064 theLogProbMatrix.clear();
00065 theLogProbMatrixIndex.clear();
00066 log0Vector.clear();
00067 nb_of_PrimEnergy=0;
00068 }
00070
00071 void G4AdjointCSMatrix::AddData(G4double aLogPrimEnergy,G4double aLogCS, std::vector< double>* aLogSecondEnergyVector,
00072 std::vector< double>* aLogProbVector,size_t n_pro_decade){
00073
00074 G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance();
00075
00076
00077 theLogPrimEnergyVector.push_back(aLogPrimEnergy);
00078 theLogCrossSectionVector.push_back(aLogCS);
00079 theLogSecondEnergyMatrix.push_back(aLogSecondEnergyVector);
00080 theLogProbMatrix.push_back(aLogProbVector);
00081
00082 std::vector< size_t>* aLogProbVectorIndex = 0;
00083 dlog =0;
00084
00085 if (n_pro_decade > 0 && aLogProbVector->size()>0) {
00086 aLogProbVectorIndex = new std::vector< size_t>();
00087 dlog=std::log(10.)/n_pro_decade;
00088 G4double log_val = int(std::min((*aLogProbVector)[0],aLogProbVector->back())/dlog)*dlog;
00089 log0Vector.push_back(log_val);
00090
00091 while(log_val<0.) {
00092 aLogProbVectorIndex->push_back(theInterpolator->FindPosition(log_val,(*aLogProbVector)));
00093 log_val+=dlog;
00094 }
00095 }
00096 else {
00097 log0Vector.push_back(0.);
00098 }
00099 theLogProbMatrixIndex.push_back(aLogProbVectorIndex);
00100
00101
00102 nb_of_PrimEnergy++;
00103
00104
00105 }
00107
00108 G4bool G4AdjointCSMatrix::GetData(unsigned int i, G4double& aLogPrimEnergy,G4double& aLogCS,G4double& log0, std::vector< double>*& aLogSecondEnergyVector,
00109 std::vector< double>*& aLogProbVector, std::vector< size_t>*& aLogProbVectorIndex)
00110 { if (i>= nb_of_PrimEnergy) return false;
00111
00112 aLogPrimEnergy = theLogPrimEnergyVector[i];
00113 aLogCS = theLogCrossSectionVector[i];
00114 aLogSecondEnergyVector = theLogSecondEnergyMatrix[i];
00115 aLogProbVector = theLogProbMatrix[i];
00116 aLogProbVectorIndex = theLogProbMatrixIndex[i];
00117 log0=log0Vector[i];
00118 return true;
00119
00120 }
00122
00123 void G4AdjointCSMatrix::Write(G4String file_name)
00124 { std::fstream FileOutput(file_name, std::ios::out);
00125 FileOutput<<std::setiosflags(std::ios::scientific);
00126 FileOutput<<std::setprecision(6);
00127 FileOutput<<theLogPrimEnergyVector.size()<<G4endl;
00128 for (size_t i=0;i<theLogPrimEnergyVector.size();i++){
00129 FileOutput<<std::exp(theLogPrimEnergyVector[i])/MeV<<'\t'<<std::exp(theLogCrossSectionVector[i])<<G4endl;
00130 size_t j1=0;
00131 FileOutput<<theLogSecondEnergyMatrix[i]->size()<<G4endl;
00132 for (size_t j=0;j<theLogSecondEnergyMatrix[i]->size();j++){
00133 FileOutput<<std::exp((*theLogSecondEnergyMatrix[i])[j]);
00134 j1++;
00135 if (j1<10) FileOutput<<'\t';
00136 else {
00137 FileOutput<<G4endl;
00138 j1=0;
00139 }
00140 }
00141 if (j1>0) FileOutput<<G4endl;
00142 j1=0;
00143 FileOutput<<theLogProbMatrix[i]->size()<<G4endl;
00144 for (size_t j=0;j<theLogProbMatrix[i]->size();j++){
00145 FileOutput<<std::exp((*theLogProbMatrix[i])[j]);
00146 j1++;
00147 if (j1<10) FileOutput<<'\t';
00148 else {
00149 FileOutput<<G4endl;
00150 j1=0;
00151 }
00152 }
00153 if (j1>0) FileOutput<<G4endl;
00154
00155
00156 }
00157
00158 }
00160
00161 void G4AdjointCSMatrix::Read(G4String file_name)
00162 { std::fstream FileOutput(file_name, std::ios::in);
00163 size_t n1,n2;
00164
00165
00166 theLogPrimEnergyVector.clear();
00167 theLogCrossSectionVector.clear();
00168 theLogSecondEnergyMatrix.clear();
00169 theLogProbMatrix.clear();
00170 FileOutput>>n1;
00171 for (size_t i=0; i<n1;i++){
00172 G4double E,CS;
00173 FileOutput>>E>>CS;
00174 theLogPrimEnergyVector.push_back(E);
00175 theLogCrossSectionVector.push_back(CS);
00176 FileOutput>>n2;
00177 theLogSecondEnergyMatrix.push_back(new std::vector<G4double>());
00178 theLogProbMatrix.push_back(new std::vector<G4double>());
00179
00180 for (size_t j=0; j<n2;j++){
00181 G4double E1;
00182 FileOutput>>E1;
00183 theLogSecondEnergyMatrix[i]->push_back(E1);
00184 }
00185 FileOutput>>n2;
00186 for (size_t j=0; j<n2;j++){
00187 G4double prob;
00188 FileOutput>>prob;
00189 theLogProbMatrix[i]->push_back(prob);
00190 }
00191
00192
00193
00194 }
00195
00196
00197
00198
00199 }