G4AdjointCSMatrix.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4AdjointCSMatrix.cc 69844 2013-05-16 09:19:33Z gcosmo $
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         //At this time we consider that the energy is increasing monotically
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         //G4cout<<"Test Get Data "<<G4endl;
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 }

Generated on Mon May 27 17:47:37 2013 for Geant4 by  doxygen 1.4.7