Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4AdjointCSMatrix.cc,v 1.4 2009/11/20 10:31:20 ldesorgh Exp $ >> 27 // GEANT4 tag $Name: geant4-09-03-patch-01 $ >> 28 // 26 29 27 #include "G4AdjointCSMatrix.hh" 30 #include "G4AdjointCSMatrix.hh" 28 << 29 #include "G4AdjointInterpolator.hh" << 30 #include "G4SystemOfUnits.hh" << 31 << 32 #include <iomanip> 31 #include <iomanip> 33 #include <fstream> 32 #include <fstream> 34 << 33 #include "G4AdjointInterpolator.hh" 35 ////////////////////////////////////////////// 34 /////////////////////////////////////////////////////// 36 G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aB << 35 // 37 << 36 G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aBool){ >> 37 theLogPrimEnergyVector.clear(); >> 38 theLogCrossSectionVector.clear(); >> 39 theLogSecondEnergyMatrix.clear(); >> 40 theLogProbMatrix.clear(); >> 41 theLogProbMatrixIndex.clear(); >> 42 log0Vector.clear(); >> 43 nb_of_PrimEnergy=0; >> 44 is_scat_proj_to_proj_case =aBool; >> 45 } 38 ////////////////////////////////////////////// 46 /////////////////////////////////////////////////////// 39 G4AdjointCSMatrix::~G4AdjointCSMatrix() << 47 // 40 { << 48 G4AdjointCSMatrix::~G4AdjointCSMatrix(){ 41 fLogPrimEnergyVector.clear(); << 49 theLogPrimEnergyVector.clear(); 42 fLogCrossSectionVector.clear(); << 50 theLogCrossSectionVector.clear(); 43 << 51 theLogSecondEnergyMatrix.clear(); 44 for (auto p : fLogSecondEnergyMatrix) { << 52 theLogProbMatrix.clear(); 45 p->clear(); << 46 delete p; << 47 p = nullptr; << 48 } << 49 fLogSecondEnergyMatrix.clear(); << 50 << 51 for (auto p : fLogProbMatrix) { << 52 p->clear(); << 53 delete p; << 54 p = nullptr; << 55 } << 56 fLogProbMatrix.clear(); << 57 << 58 for (auto p : fLogProbMatrixIndex) { << 59 if (p) { << 60 p->clear(); << 61 delete p; << 62 p = nullptr; << 63 } << 64 } << 65 fLogProbMatrixIndex.clear(); << 66 } 53 } 67 << 68 ////////////////////////////////////////////// 54 /////////////////////////////////////////////////////// >> 55 // 69 void G4AdjointCSMatrix::Clear() 56 void G4AdjointCSMatrix::Clear() 70 { 57 { 71 fLogPrimEnergyVector.clear(); << 58 theLogPrimEnergyVector.clear(); 72 fLogCrossSectionVector.clear(); << 59 theLogCrossSectionVector.clear(); 73 fLogSecondEnergyMatrix.clear(); << 60 theLogSecondEnergyMatrix.clear(); 74 fLogProbMatrix.clear(); << 61 theLogProbMatrix.clear(); 75 fLogProbMatrixIndex.clear(); << 62 theLogProbMatrixIndex.clear(); 76 fLog0Vector.clear(); << 63 log0Vector.clear(); 77 fNbPrimEnergy = 0; << 64 nb_of_PrimEnergy=0; 78 } 65 } 79 << 80 ////////////////////////////////////////////// 66 /////////////////////////////////////////////////////// 81 void G4AdjointCSMatrix::AddData(G4double aLogP << 67 // 82 std::vector<G4 << 68 void G4AdjointCSMatrix::AddData(G4double aLogPrimEnergy,G4double aLogCS, std::vector< double>* aLogSecondEnergyVector, 83 std::vector<G4 << 69 std::vector< double>* aLogProbVector,size_t n_pro_decade){ 84 std::size_t n_ << 70 85 { << 71 G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance(); 86 G4AdjointInterpolator* theInterpolator = G4A << 72 87 << 73 //At this time we consider that the energy is increasing monotically 88 // At this time we consider that the energy << 74 theLogPrimEnergyVector.push_back(aLogPrimEnergy); 89 fLogPrimEnergyVector.push_back(aLogPrimEnerg << 75 theLogCrossSectionVector.push_back(aLogCS); 90 fLogCrossSectionVector.push_back(aLogCS); << 76 theLogSecondEnergyMatrix.push_back(aLogSecondEnergyVector); 91 fLogSecondEnergyMatrix.push_back(aLogSecondE << 77 theLogProbMatrix.push_back(aLogProbVector); 92 fLogProbMatrix.push_back(aLogProbVector); << 78 93 << 79 std::vector< size_t>* aLogProbVectorIndex = 0; 94 std::vector<std::size_t>* aLogProbVectorInde << 80 dlog =0; 95 << 81 96 if(n_pro_decade > 0 && !aLogProbVector->empt << 82 if (n_pro_decade > 0 && aLogProbVector->size()>0) { 97 { << 83 aLogProbVectorIndex = new std::vector< size_t>(); 98 aLogProbVectorIndex = new std::vector<std: << 84 dlog=std::log(10.)/n_pro_decade; 99 G4double dlog = std::log(10.) / n_pr << 85 G4double log_val = int(std::min((*aLogProbVector)[0],aLogProbVector->back())/dlog)*dlog; 100 G4double log_val = << 86 log0Vector.push_back(log_val); 101 G4int(std::min((*aLogProbVector)[0], aLo << 87 102 fLog0Vector.push_back(log_val); << 88 while(log_val<0.) { 103 << 89 aLogProbVectorIndex->push_back(theInterpolator->FindPosition(log_val,(*aLogProbVector))); 104 // Loop checking, 07-Aug-2015, Vladimir Iv << 90 log_val+=dlog; 105 while(log_val < 0.) << 91 } 106 { << 92 } 107 aLogProbVectorIndex->push_back( << 93 else { 108 theInterpolator->FindPosition(log_val, << 94 log0Vector.push_back(0.); 109 log_val += dlog; << 95 } 110 } << 96 theLogProbMatrixIndex.push_back(aLogProbVectorIndex); 111 } << 97 112 else << 98 113 { << 99 nb_of_PrimEnergy++; 114 fLog0Vector.push_back(0.); << 100 115 } << 101 116 fLogProbMatrixIndex.push_back(aLogProbVector << 117 << 118 ++fNbPrimEnergy; << 119 } 102 } 120 << 121 ////////////////////////////////////////////// 103 /////////////////////////////////////////////////////// 122 G4bool G4AdjointCSMatrix::GetData(unsigned int << 104 // 123 G4double& aL << 105 G4bool G4AdjointCSMatrix::GetData(unsigned int i, G4double& aLogPrimEnergy,G4double& aLogCS,G4double& log0, std::vector< double>*& aLogSecondEnergyVector, 124 std::vector< << 106 std::vector< double>*& aLogProbVector, std::vector< size_t>*& aLogProbVectorIndex) 125 std::vector< << 107 { if (i>= nb_of_PrimEnergy) return false; 126 std::vector< << 108 //G4cout<<"Test Get Data "<<G4endl; 127 { << 109 aLogPrimEnergy = theLogPrimEnergyVector[i]; 128 if(i >= fNbPrimEnergy) << 110 aLogCS = theLogCrossSectionVector[i]; 129 return false; << 111 aLogSecondEnergyVector = theLogSecondEnergyMatrix[i]; 130 aLogPrimEnergy = fLogPrimEnergyVecto << 112 aLogProbVector = theLogProbMatrix[i]; 131 aLogCS = fLogCrossSectionVec << 113 aLogProbVectorIndex = theLogProbMatrixIndex[i]; 132 aLogSecondEnergyVector = fLogSecondEnergyMat << 114 log0=log0Vector[i]; 133 aLogProbVector = fLogProbMatrix[i]; << 115 return true; 134 aLogProbVectorIndex = fLogProbMatrixIndex << 116 135 log0 = fLog0Vector[i]; << 136 return true; << 137 } 117 } 138 << 139 ////////////////////////////////////////////// 118 /////////////////////////////////////////////////////// 140 void G4AdjointCSMatrix::Write(const G4String& << 119 // 141 { << 120 void G4AdjointCSMatrix::Write(G4String file_name) 142 std::fstream FileOutput(file_name, std::ios: << 121 { std::fstream FileOutput(file_name, std::ios::out); 143 FileOutput << std::setiosflags(std::ios::sci << 122 FileOutput<<std::setiosflags(std::ios::scientific); 144 FileOutput << std::setprecision(6); << 123 FileOutput<<std::setprecision(6); 145 FileOutput << fLogPrimEnergyVector.size() << << 124 FileOutput<<theLogPrimEnergyVector.size()<<G4endl; 146 for(std::size_t i = 0; i < fLogPrimEnergyVec << 125 for (size_t i=0;i<theLogPrimEnergyVector.size();i++){ 147 { << 126 FileOutput<<std::exp(theLogPrimEnergyVector[i])/MeV<<'\t'<<std::exp(theLogCrossSectionVector[i])<<G4endl; 148 FileOutput << std::exp(fLogPrimEnergyVecto << 127 size_t j1=0; 149 << std::exp(fLogCrossSectionVec << 128 FileOutput<<theLogSecondEnergyMatrix[i]->size()<<G4endl; 150 std::size_t j1 = 0; << 129 for (size_t j=0;j<theLogSecondEnergyMatrix[i]->size();j++){ 151 FileOutput << fLogSecondEnergyMatrix[i]->s << 130 FileOutput<<std::exp((*theLogSecondEnergyMatrix[i])[j]); 152 for(std::size_t j = 0; j < fLogSecondEnerg << 131 j1++; 153 { << 132 if (j1<10) FileOutput<<'\t'; 154 FileOutput << std::exp((*fLogSecondEnerg << 133 else { 155 ++j1; << 134 FileOutput<<G4endl; 156 if(j1 < 10) << 135 j1=0; 157 FileOutput << '\t'; << 136 } 158 else << 137 } 159 { << 138 if (j1>0) FileOutput<<G4endl; 160 FileOutput << G4endl; << 139 j1=0; 161 j1 = 0; << 140 FileOutput<<theLogProbMatrix[i]->size()<<G4endl; 162 } << 141 for (size_t j=0;j<theLogProbMatrix[i]->size();j++){ 163 } << 142 FileOutput<<std::exp((*theLogProbMatrix[i])[j]); 164 if(j1 > 0) << 143 j1++; 165 FileOutput << G4endl; << 144 if (j1<10) FileOutput<<'\t'; 166 j1 = 0; << 145 else { 167 FileOutput << fLogProbMatrix[i]->size() << << 146 FileOutput<<G4endl; 168 for(std::size_t j = 0; j < fLogProbMatrix[ << 147 j1=0; 169 { << 148 } 170 FileOutput << std::exp((*fLogProbMatrix[ << 149 } 171 ++j1; << 150 if (j1>0) FileOutput<<G4endl; 172 if(j1 < 10) << 151 173 FileOutput << '\t'; << 152 174 else << 153 } 175 { << 154 176 FileOutput << G4endl; << 177 j1 = 0; << 178 } << 179 } << 180 if(j1 > 0) << 181 FileOutput << G4endl; << 182 } << 183 } 155 } 184 << 185 ////////////////////////////////////////////// 156 /////////////////////////////////////////////////////// 186 void G4AdjointCSMatrix::Read(const G4String& f << 157 // 187 { << 158 void G4AdjointCSMatrix::Read(G4String file_name) 188 std::fstream FileOutput(file_name, std::ios: << 159 { std::fstream FileOutput(file_name, std::ios::in); 189 std::size_t n1, n2; << 160 size_t n1,n2; 190 << 161 191 fLogPrimEnergyVector.clear(); << 162 192 fLogCrossSectionVector.clear(); << 163 theLogPrimEnergyVector.clear(); 193 fLogSecondEnergyMatrix.clear(); << 164 theLogCrossSectionVector.clear(); 194 fLogProbMatrix.clear(); << 165 theLogSecondEnergyMatrix.clear(); 195 FileOutput >> n1; << 166 theLogProbMatrix.clear(); 196 for(std::size_t i = 0; i < n1; ++i) << 167 FileOutput>>n1; 197 { << 168 for (size_t i=0; i<n1;i++){ 198 G4double E, CS; << 169 G4double E,CS; 199 FileOutput >> E >> CS; << 170 FileOutput>>E>>CS; 200 fLogPrimEnergyVector.push_back(E); << 171 theLogPrimEnergyVector.push_back(E); 201 fLogCrossSectionVector.push_back(CS); << 172 theLogCrossSectionVector.push_back(CS); 202 FileOutput >> n2; << 173 FileOutput>>n2; 203 fLogSecondEnergyMatrix.push_back(new std:: << 174 theLogSecondEnergyMatrix.push_back(new std::vector<G4double>()); 204 fLogProbMatrix.push_back(new std::vector<G << 175 theLogProbMatrix.push_back(new std::vector<G4double>()); 205 << 176 206 for(std::size_t j = 0; j < n2; ++j) << 177 for (size_t j=0; j<n2;j++){ 207 { << 178 G4double E1; 208 G4double E1; << 179 FileOutput>>E1; 209 FileOutput >> E1; << 180 theLogSecondEnergyMatrix[i]->push_back(E1); 210 fLogSecondEnergyMatrix[i]->push_back(E1) << 181 } 211 } << 182 FileOutput>>n2; 212 FileOutput >> n2; << 183 for (size_t j=0; j<n2;j++){ 213 for(std::size_t j = 0; j < n2; ++j) << 184 G4double prob; 214 { << 185 FileOutput>>prob; 215 G4double prob; << 186 theLogProbMatrix[i]->push_back(prob); 216 FileOutput >> prob; << 187 } 217 fLogProbMatrix[i]->push_back(prob); << 188 218 } << 189 219 } << 190 >> 191 } >> 192 >> 193 >> 194 >> 195 220 } 196 } 221 197