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 << 26 // $Id$ 27 #include "G4AdjointCSMatrix.hh" << 27 // 28 << 29 #include "G4AdjointInterpolator.hh" << 30 #include "G4SystemOfUnits.hh" << 31 28 32 #include <iomanip> 29 #include <iomanip> 33 #include <fstream> 30 #include <fstream> 34 31 35 ////////////////////////////////////////////// << 32 #include "G4AdjointCSMatrix.hh" 36 G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aB << 33 #include "G4SystemOfUnits.hh" >> 34 #include "G4AdjointInterpolator.hh" 37 35 38 ////////////////////////////////////////////// 36 /////////////////////////////////////////////////////// 39 G4AdjointCSMatrix::~G4AdjointCSMatrix() << 37 // 40 { << 38 G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aBool){ 41 fLogPrimEnergyVector.clear(); << 39 theLogPrimEnergyVector.clear(); 42 fLogCrossSectionVector.clear(); << 40 theLogCrossSectionVector.clear(); 43 << 41 theLogSecondEnergyMatrix.clear(); 44 for (auto p : fLogSecondEnergyMatrix) { << 42 theLogProbMatrix.clear(); 45 p->clear(); << 43 theLogProbMatrixIndex.clear(); 46 delete p; << 44 log0Vector.clear(); 47 p = nullptr; << 45 nb_of_PrimEnergy=0; 48 } << 46 is_scat_proj_to_proj_case =aBool; 49 fLogSecondEnergyMatrix.clear(); << 47 dlog =0; 50 << 48 } 51 for (auto p : fLogProbMatrix) { << 49 /////////////////////////////////////////////////////// 52 p->clear(); << 50 // 53 delete p; << 51 G4AdjointCSMatrix::~G4AdjointCSMatrix(){ 54 p = nullptr; << 52 theLogPrimEnergyVector.clear(); 55 } << 53 theLogCrossSectionVector.clear(); 56 fLogProbMatrix.clear(); << 54 theLogSecondEnergyMatrix.clear(); 57 << 55 theLogProbMatrix.clear(); 58 for (auto p : fLogProbMatrixIndex) { << 59 if (p) { << 60 p->clear(); << 61 delete p; << 62 p = nullptr; << 63 } << 64 } << 65 fLogProbMatrixIndex.clear(); << 66 } 56 } 67 << 68 ////////////////////////////////////////////// 57 /////////////////////////////////////////////////////// >> 58 // 69 void G4AdjointCSMatrix::Clear() 59 void G4AdjointCSMatrix::Clear() 70 { 60 { 71 fLogPrimEnergyVector.clear(); << 61 theLogPrimEnergyVector.clear(); 72 fLogCrossSectionVector.clear(); << 62 theLogCrossSectionVector.clear(); 73 fLogSecondEnergyMatrix.clear(); << 63 theLogSecondEnergyMatrix.clear(); 74 fLogProbMatrix.clear(); << 64 theLogProbMatrix.clear(); 75 fLogProbMatrixIndex.clear(); << 65 theLogProbMatrixIndex.clear(); 76 fLog0Vector.clear(); << 66 log0Vector.clear(); 77 fNbPrimEnergy = 0; << 67 nb_of_PrimEnergy=0; 78 } 68 } 79 << 80 ////////////////////////////////////////////// 69 /////////////////////////////////////////////////////// 81 void G4AdjointCSMatrix::AddData(G4double aLogP << 70 // 82 std::vector<G4 << 71 void G4AdjointCSMatrix::AddData(G4double aLogPrimEnergy,G4double aLogCS, std::vector< double>* aLogSecondEnergyVector, 83 std::vector<G4 << 72 std::vector< double>* aLogProbVector,size_t n_pro_decade){ 84 std::size_t n_ << 73 85 { << 74 G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance(); 86 G4AdjointInterpolator* theInterpolator = G4A << 75 87 << 76 //At this time we consider that the energy is increasing monotically 88 // At this time we consider that the energy << 77 theLogPrimEnergyVector.push_back(aLogPrimEnergy); 89 fLogPrimEnergyVector.push_back(aLogPrimEnerg << 78 theLogCrossSectionVector.push_back(aLogCS); 90 fLogCrossSectionVector.push_back(aLogCS); << 79 theLogSecondEnergyMatrix.push_back(aLogSecondEnergyVector); 91 fLogSecondEnergyMatrix.push_back(aLogSecondE << 80 theLogProbMatrix.push_back(aLogProbVector); 92 fLogProbMatrix.push_back(aLogProbVector); << 81 93 << 82 std::vector< size_t>* aLogProbVectorIndex = 0; 94 std::vector<std::size_t>* aLogProbVectorInde << 83 dlog =0; 95 << 84 96 if(n_pro_decade > 0 && !aLogProbVector->empt << 85 if (n_pro_decade > 0 && aLogProbVector->size()>0) { 97 { << 86 aLogProbVectorIndex = new std::vector< size_t>(); 98 aLogProbVectorIndex = new std::vector<std: << 87 dlog=std::log(10.)/n_pro_decade; 99 G4double dlog = std::log(10.) / n_pr << 88 G4double log_val = int(std::min((*aLogProbVector)[0],aLogProbVector->back())/dlog)*dlog; 100 G4double log_val = << 89 log0Vector.push_back(log_val); 101 G4int(std::min((*aLogProbVector)[0], aLo << 90 102 fLog0Vector.push_back(log_val); << 91 // Loop checking, 07-Aug-2015, Vladimir Ivanchenko 103 << 92 while(log_val<0.) { 104 // Loop checking, 07-Aug-2015, Vladimir Iv << 93 aLogProbVectorIndex->push_back(theInterpolator->FindPosition(log_val,(*aLogProbVector))); 105 while(log_val < 0.) << 94 log_val+=dlog; 106 { << 95 } 107 aLogProbVectorIndex->push_back( << 96 } 108 theInterpolator->FindPosition(log_val, << 97 else { 109 log_val += dlog; << 98 log0Vector.push_back(0.); 110 } << 99 } 111 } << 100 theLogProbMatrixIndex.push_back(aLogProbVectorIndex); 112 else << 101 113 { << 102 114 fLog0Vector.push_back(0.); << 103 nb_of_PrimEnergy++; 115 } << 104 116 fLogProbMatrixIndex.push_back(aLogProbVector << 105 117 << 118 ++fNbPrimEnergy; << 119 } 106 } 120 << 121 ////////////////////////////////////////////// 107 /////////////////////////////////////////////////////// 122 G4bool G4AdjointCSMatrix::GetData(unsigned int << 108 // 123 G4double& aL << 109 G4bool G4AdjointCSMatrix::GetData(unsigned int i, G4double& aLogPrimEnergy,G4double& aLogCS,G4double& log0, std::vector< double>*& aLogSecondEnergyVector, 124 std::vector< << 110 std::vector< double>*& aLogProbVector, std::vector< size_t>*& aLogProbVectorIndex) 125 std::vector< << 111 { if (i>= nb_of_PrimEnergy) return false; 126 std::vector< << 112 //G4cout<<"Test Get Data "<<G4endl; 127 { << 113 aLogPrimEnergy = theLogPrimEnergyVector[i]; 128 if(i >= fNbPrimEnergy) << 114 aLogCS = theLogCrossSectionVector[i]; 129 return false; << 115 aLogSecondEnergyVector = theLogSecondEnergyMatrix[i]; 130 aLogPrimEnergy = fLogPrimEnergyVecto << 116 aLogProbVector = theLogProbMatrix[i]; 131 aLogCS = fLogCrossSectionVec << 117 aLogProbVectorIndex = theLogProbMatrixIndex[i]; 132 aLogSecondEnergyVector = fLogSecondEnergyMat << 118 log0=log0Vector[i]; 133 aLogProbVector = fLogProbMatrix[i]; << 119 return true; 134 aLogProbVectorIndex = fLogProbMatrixIndex << 120 135 log0 = fLog0Vector[i]; << 136 return true; << 137 } 121 } 138 << 139 ////////////////////////////////////////////// 122 /////////////////////////////////////////////////////// 140 void G4AdjointCSMatrix::Write(const G4String& << 123 // 141 { << 124 void G4AdjointCSMatrix::Write(G4String file_name) 142 std::fstream FileOutput(file_name, std::ios: << 125 { std::fstream FileOutput(file_name, std::ios::out); 143 FileOutput << std::setiosflags(std::ios::sci << 126 FileOutput<<std::setiosflags(std::ios::scientific); 144 FileOutput << std::setprecision(6); << 127 FileOutput<<std::setprecision(6); 145 FileOutput << fLogPrimEnergyVector.size() << << 128 FileOutput<<theLogPrimEnergyVector.size()<<G4endl; 146 for(std::size_t i = 0; i < fLogPrimEnergyVec << 129 for (size_t i=0;i<theLogPrimEnergyVector.size();i++){ 147 { << 130 FileOutput<<std::exp(theLogPrimEnergyVector[i])/MeV<<'\t'<<std::exp(theLogCrossSectionVector[i])<<G4endl; 148 FileOutput << std::exp(fLogPrimEnergyVecto << 131 size_t j1=0; 149 << std::exp(fLogCrossSectionVec << 132 FileOutput<<theLogSecondEnergyMatrix[i]->size()<<G4endl; 150 std::size_t j1 = 0; << 133 for (size_t j=0;j<theLogSecondEnergyMatrix[i]->size();j++){ 151 FileOutput << fLogSecondEnergyMatrix[i]->s << 134 FileOutput<<std::exp((*theLogSecondEnergyMatrix[i])[j]); 152 for(std::size_t j = 0; j < fLogSecondEnerg << 135 j1++; 153 { << 136 if (j1<10) FileOutput<<'\t'; 154 FileOutput << std::exp((*fLogSecondEnerg << 137 else { 155 ++j1; << 138 FileOutput<<G4endl; 156 if(j1 < 10) << 139 j1=0; 157 FileOutput << '\t'; << 140 } 158 else << 141 } 159 { << 142 if (j1>0) FileOutput<<G4endl; 160 FileOutput << G4endl; << 143 j1=0; 161 j1 = 0; << 144 FileOutput<<theLogProbMatrix[i]->size()<<G4endl; 162 } << 145 for (size_t j=0;j<theLogProbMatrix[i]->size();j++){ 163 } << 146 FileOutput<<std::exp((*theLogProbMatrix[i])[j]); 164 if(j1 > 0) << 147 j1++; 165 FileOutput << G4endl; << 148 if (j1<10) FileOutput<<'\t'; 166 j1 = 0; << 149 else { 167 FileOutput << fLogProbMatrix[i]->size() << << 150 FileOutput<<G4endl; 168 for(std::size_t j = 0; j < fLogProbMatrix[ << 151 j1=0; 169 { << 152 } 170 FileOutput << std::exp((*fLogProbMatrix[ << 153 } 171 ++j1; << 154 if (j1>0) FileOutput<<G4endl; 172 if(j1 < 10) << 155 173 FileOutput << '\t'; << 156 174 else << 157 } 175 { << 158 176 FileOutput << G4endl; << 177 j1 = 0; << 178 } << 179 } << 180 if(j1 > 0) << 181 FileOutput << G4endl; << 182 } << 183 } 159 } 184 << 185 ////////////////////////////////////////////// 160 /////////////////////////////////////////////////////// 186 void G4AdjointCSMatrix::Read(const G4String& f << 161 // 187 { << 162 void G4AdjointCSMatrix::Read(G4String file_name) 188 std::fstream FileOutput(file_name, std::ios: << 163 { std::fstream FileOutput(file_name, std::ios::in); 189 std::size_t n1, n2; << 164 size_t n1,n2; 190 << 165 191 fLogPrimEnergyVector.clear(); << 166 192 fLogCrossSectionVector.clear(); << 167 theLogPrimEnergyVector.clear(); 193 fLogSecondEnergyMatrix.clear(); << 168 theLogCrossSectionVector.clear(); 194 fLogProbMatrix.clear(); << 169 theLogSecondEnergyMatrix.clear(); 195 FileOutput >> n1; << 170 theLogProbMatrix.clear(); 196 for(std::size_t i = 0; i < n1; ++i) << 171 FileOutput>>n1; 197 { << 172 for (size_t i=0; i<n1;i++){ 198 G4double E, CS; << 173 G4double E,CS; 199 FileOutput >> E >> CS; << 174 FileOutput>>E>>CS; 200 fLogPrimEnergyVector.push_back(E); << 175 theLogPrimEnergyVector.push_back(E); 201 fLogCrossSectionVector.push_back(CS); << 176 theLogCrossSectionVector.push_back(CS); 202 FileOutput >> n2; << 177 FileOutput>>n2; 203 fLogSecondEnergyMatrix.push_back(new std:: << 178 theLogSecondEnergyMatrix.push_back(new std::vector<G4double>()); 204 fLogProbMatrix.push_back(new std::vector<G << 179 theLogProbMatrix.push_back(new std::vector<G4double>()); 205 << 180 206 for(std::size_t j = 0; j < n2; ++j) << 181 for (size_t j=0; j<n2;j++){ 207 { << 182 G4double E1; 208 G4double E1; << 183 FileOutput>>E1; 209 FileOutput >> E1; << 184 theLogSecondEnergyMatrix[i]->push_back(E1); 210 fLogSecondEnergyMatrix[i]->push_back(E1) << 185 } 211 } << 186 FileOutput>>n2; 212 FileOutput >> n2; << 187 for (size_t j=0; j<n2;j++){ 213 for(std::size_t j = 0; j < n2; ++j) << 188 G4double prob; 214 { << 189 FileOutput>>prob; 215 G4double prob; << 190 theLogProbMatrix[i]->push_back(prob); 216 FileOutput >> prob; << 191 } 217 fLogProbMatrix[i]->push_back(prob); << 192 218 } << 193 219 } << 194 >> 195 } >> 196 >> 197 >> 198 >> 199 220 } 200 } 221 201