1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | #include "G4AdjointCSMatrix.hh" |
---|
27 | #include <iomanip> |
---|
28 | #include <fstream> |
---|
29 | |
---|
30 | #include "G4AdjointInterpolator.hh" |
---|
31 | |
---|
32 | /////////////////////////////////////////////////////// |
---|
33 | // |
---|
34 | G4AdjointCSMatrix::G4AdjointCSMatrix(G4bool aBool){ |
---|
35 | theLogPrimEnergyVector.clear(); |
---|
36 | theLogCrossSectionVector.clear(); |
---|
37 | theLogSecondEnergyMatrix.clear(); |
---|
38 | theLogProbMatrix.clear(); |
---|
39 | theLogProbMatrixIndex.clear(); |
---|
40 | log0Vector.clear(); |
---|
41 | nb_of_PrimEnergy=0; |
---|
42 | is_scat_proj_to_proj_case =aBool; |
---|
43 | } |
---|
44 | /////////////////////////////////////////////////////// |
---|
45 | // |
---|
46 | G4AdjointCSMatrix::~G4AdjointCSMatrix(){ |
---|
47 | theLogPrimEnergyVector.clear(); |
---|
48 | theLogCrossSectionVector.clear(); |
---|
49 | theLogSecondEnergyMatrix.clear(); |
---|
50 | theLogProbMatrix.clear(); |
---|
51 | } |
---|
52 | /////////////////////////////////////////////////////// |
---|
53 | // |
---|
54 | void G4AdjointCSMatrix::Clear() |
---|
55 | { |
---|
56 | theLogPrimEnergyVector.clear(); |
---|
57 | theLogCrossSectionVector.clear(); |
---|
58 | theLogSecondEnergyMatrix.clear(); |
---|
59 | theLogProbMatrix.clear(); |
---|
60 | theLogProbMatrixIndex.clear(); |
---|
61 | log0Vector.clear(); |
---|
62 | nb_of_PrimEnergy=0; |
---|
63 | } |
---|
64 | /////////////////////////////////////////////////////// |
---|
65 | // |
---|
66 | void G4AdjointCSMatrix::AddData(G4double aLogPrimEnergy,G4double aLogCS, std::vector< G4double>* aLogSecondEnergyVector, |
---|
67 | std::vector< G4double>* aLogProbVector,size_t n_pro_decade){ |
---|
68 | |
---|
69 | G4AdjointInterpolator* theInterpolator=G4AdjointInterpolator::GetInstance(); |
---|
70 | //Add this time we consider that the energy are given monotically |
---|
71 | |
---|
72 | theLogPrimEnergyVector.push_back(aLogPrimEnergy); |
---|
73 | theLogCrossSectionVector.push_back(aLogCS); |
---|
74 | theLogSecondEnergyMatrix.push_back(aLogSecondEnergyVector); |
---|
75 | //G4cout<<"Test Add Data "<<this<<'\t'<<aSecondEnergyVector->size()<<std::endl; |
---|
76 | //G4cout<<theSecondEnergyMatrix.size()<<std::endl; |
---|
77 | theLogProbMatrix.push_back(aLogProbVector); |
---|
78 | //G4cout<<"Test Add Data 1 "<<this<<'\t'<<aSecondEnergyVector->size()<<std::endl; |
---|
79 | //G4cout<<theSecondEnergyMatrix.size()<<std::endl; |
---|
80 | std::vector< size_t>* aLogProbVectorIndex = 0; |
---|
81 | dlog =0; |
---|
82 | if (n_pro_decade > 0 && aLogProbVector->size()>0) { |
---|
83 | aLogProbVectorIndex = new std::vector< size_t>(); |
---|
84 | dlog=std::log(10.)/n_pro_decade; |
---|
85 | G4double log_val = int(std::min((*aLogProbVector)[0],aLogProbVector->back())/dlog)*dlog; |
---|
86 | log0Vector.push_back(log_val); |
---|
87 | while(log_val<0.) { |
---|
88 | aLogProbVectorIndex->push_back(theInterpolator->FindPosition(log_val,(*aLogProbVector))); |
---|
89 | log_val+=dlog; |
---|
90 | } |
---|
91 | } |
---|
92 | else { |
---|
93 | log0Vector.push_back(0.); |
---|
94 | } |
---|
95 | theLogProbMatrixIndex.push_back(aLogProbVectorIndex); |
---|
96 | |
---|
97 | |
---|
98 | nb_of_PrimEnergy++; |
---|
99 | |
---|
100 | |
---|
101 | } |
---|
102 | /////////////////////////////////////////////////////// |
---|
103 | // |
---|
104 | bool G4AdjointCSMatrix::GetData(unsigned int i, G4double& aLogPrimEnergy,G4double& aLogCS,G4double& log0, std::vector< G4double>*& aLogSecondEnergyVector, |
---|
105 | std::vector< G4double>*& aLogProbVector, std::vector< size_t>*& aLogProbVectorIndex) |
---|
106 | { if (i>= nb_of_PrimEnergy) return false; |
---|
107 | //G4cout<<"Test Get Data "<<std::endl; |
---|
108 | aLogPrimEnergy = theLogPrimEnergyVector[i]; |
---|
109 | aLogCS = theLogCrossSectionVector[i]; |
---|
110 | aLogSecondEnergyVector = theLogSecondEnergyMatrix[i]; |
---|
111 | //G4cout<<"Test Get Data "<<this<<'\t'<<theSecondEnergyMatrix[i]->size()<<std::endl; |
---|
112 | //G4cout<<"Test Get Data "<<this<<'\t'<<aSecondEnergyVector->size()<<std::endl; |
---|
113 | //G4cout<<"Test Get Data "<<this<<'\t'<<aSecondEnergyVector<<std::endl; |
---|
114 | aLogProbVector = theLogProbMatrix[i]; |
---|
115 | aLogProbVectorIndex = theLogProbMatrixIndex[i]; |
---|
116 | log0=log0Vector[i]; |
---|
117 | //G4cout<<"Test Get Data 1 "<<this<<'\t'<<theProbMatrix[i]->size()<<std::endl; |
---|
118 | //G4cout<<"Test Get Data 1 "<<this<<'\t'<<aProbVector->size()<<std::endl; |
---|
119 | //G4cout<<"Test Get Data 1 "<<this<<'\t'<<aLogProbVectorIndex<<std::endl; |
---|
120 | return true; |
---|
121 | |
---|
122 | } |
---|
123 | /////////////////////////////////////////////////////// |
---|
124 | // |
---|
125 | void G4AdjointCSMatrix::Write(G4String file_name) |
---|
126 | { std::fstream FileOutput(file_name, std::ios::out); |
---|
127 | FileOutput<<std::setiosflags(std::ios::scientific); |
---|
128 | FileOutput<<std::setprecision(6); |
---|
129 | FileOutput<<theLogPrimEnergyVector.size()<<std::endl; |
---|
130 | for (size_t i=0;i<theLogPrimEnergyVector.size();i++){ |
---|
131 | FileOutput<<std::exp(theLogPrimEnergyVector[i])/MeV<<'\t'<<std::exp(theLogCrossSectionVector[i])<<std::endl; |
---|
132 | size_t j1=0; |
---|
133 | FileOutput<<theLogSecondEnergyMatrix[i]->size()<<std::endl; |
---|
134 | for (size_t j=0;j<theLogSecondEnergyMatrix[i]->size();j++){ |
---|
135 | FileOutput<<std::exp((*theLogSecondEnergyMatrix[i])[j]); |
---|
136 | j1++; |
---|
137 | if (j1<10) FileOutput<<'\t'; |
---|
138 | else { |
---|
139 | FileOutput<<std::endl; |
---|
140 | j1=0; |
---|
141 | } |
---|
142 | } |
---|
143 | if (j1>0) FileOutput<<std::endl; |
---|
144 | j1=0; |
---|
145 | FileOutput<<theLogProbMatrix[i]->size()<<std::endl; |
---|
146 | for (size_t j=0;j<theLogProbMatrix[i]->size();j++){ |
---|
147 | FileOutput<<std::exp((*theLogProbMatrix[i])[j]); |
---|
148 | j1++; |
---|
149 | if (j1<10) FileOutput<<'\t'; |
---|
150 | else { |
---|
151 | FileOutput<<std::endl; |
---|
152 | j1=0; |
---|
153 | } |
---|
154 | } |
---|
155 | if (j1>0) FileOutput<<std::endl; |
---|
156 | |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | } |
---|
161 | /////////////////////////////////////////////////////// |
---|
162 | // |
---|
163 | void G4AdjointCSMatrix::Read(G4String file_name) |
---|
164 | { std::fstream FileOutput(file_name, std::ios::in); |
---|
165 | size_t n1,n2; |
---|
166 | |
---|
167 | |
---|
168 | theLogPrimEnergyVector.clear(); |
---|
169 | theLogCrossSectionVector.clear(); |
---|
170 | theLogSecondEnergyMatrix.clear(); |
---|
171 | theLogProbMatrix.clear(); |
---|
172 | FileOutput>>n1; |
---|
173 | for (size_t i=0; i<n1;i++){ |
---|
174 | G4double E,CS; |
---|
175 | FileOutput>>E>>CS; |
---|
176 | theLogPrimEnergyVector.push_back(E); |
---|
177 | theLogCrossSectionVector.push_back(CS); |
---|
178 | FileOutput>>n2; |
---|
179 | theLogSecondEnergyMatrix.push_back(new std::vector<double>()); |
---|
180 | theLogProbMatrix.push_back(new std::vector<double>()); |
---|
181 | |
---|
182 | for (size_t j=0; j<n2;j++){ |
---|
183 | G4double E1; |
---|
184 | FileOutput>>E1; |
---|
185 | theLogSecondEnergyMatrix[i]->push_back(E1); |
---|
186 | } |
---|
187 | FileOutput>>n2; |
---|
188 | for (size_t j=0; j<n2;j++){ |
---|
189 | G4double prob; |
---|
190 | FileOutput>>prob; |
---|
191 | theLogProbMatrix[i]->push_back(prob); |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | } |
---|