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 | // |
---|
27 | // $Id: G4CrossSectionChargeTransferExp.cc,v 1.6 2009/06/10 13:32:36 mantero Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
29 | // |
---|
30 | // Contact Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) |
---|
31 | // |
---|
32 | // Reference: TNS Geant4-DNA paper |
---|
33 | // Reference for implementation model: NIM. 155, pp. 145-156, 1978 |
---|
34 | |
---|
35 | // History: |
---|
36 | // ----------- |
---|
37 | // Date Name Modification |
---|
38 | // 28 Dec 2007 M.G. Pia Created |
---|
39 | // |
---|
40 | // ------------------------------------------------------------------- |
---|
41 | |
---|
42 | // Class description: |
---|
43 | // Total cross section for incident p charge transfer from experimental data |
---|
44 | // interpolation |
---|
45 | // Reference: http://www-cfadc.phy.ornl.gov/astro/ps/data/ |
---|
46 | // |
---|
47 | // The fit formula is: |
---|
48 | // ln(cross section)=\sum C_i T_i(x) |
---|
49 | // x=[2ln(E)-ln(E_min)-ln(E_max)]/[ln(E_max)-ln(E_min)] |
---|
50 | // T_1(x)=1 |
---|
51 | // T_2(x)=x |
---|
52 | // T_n+2(x)=2T_n+1(x)-T_n(x) |
---|
53 | // |
---|
54 | // Where cross section is given in 10^-16 cm2 and E is in keV, |
---|
55 | // E_min=1e-4 keV and E_max=1.e3 keV. |
---|
56 | |
---|
57 | // Further documentation available from http://www.ge.infn.it/geant4/ |
---|
58 | |
---|
59 | // ------------------------------------------------------------------- |
---|
60 | |
---|
61 | #include <sstream> |
---|
62 | |
---|
63 | #include "G4CrossSectionChargeTransferExp.hh" |
---|
64 | #include "G4Track.hh" |
---|
65 | #include "G4DynamicParticle.hh" |
---|
66 | #include "G4Proton.hh" |
---|
67 | #include "G4VEMDataSet.hh" |
---|
68 | #include "G4EMDataSet.hh" |
---|
69 | #include "G4VDataSetAlgorithm.hh" |
---|
70 | #include "G4LogLogInterpolation.hh" |
---|
71 | #include "G4Material.hh" |
---|
72 | #include "G4DataVector.hh" |
---|
73 | |
---|
74 | G4CrossSectionChargeTransferExp::G4CrossSectionChargeTransferExp() |
---|
75 | { |
---|
76 | // Default energy limits (defined for protection against anomalous behaviour only) |
---|
77 | name = "ChargeTransferExp"; |
---|
78 | lowEnergyLimit = 0.1 * eV; |
---|
79 | highEnergyLimit = 1.0 * MeV; |
---|
80 | |
---|
81 | // Units: energies in eV, cross sections in cm2 |
---|
82 | unit1 = eV; |
---|
83 | unit2 = cm2; |
---|
84 | |
---|
85 | // Create DataSets from experimental data to be interpolated |
---|
86 | G4VEMDataSet* dataSet = 0; |
---|
87 | G4String materialName; |
---|
88 | |
---|
89 | // ---- MGP ---- Primitive implementation in 1st iteration |
---|
90 | // Load all experimental data sets available |
---|
91 | // Improvement in later iterations: load only the data sets of materials present in the |
---|
92 | // MaterialTable (i.e. actually used in the simulation), or load on demand |
---|
93 | |
---|
94 | // H2 cross section data |
---|
95 | dataSet = LoadData("/charge_transf/cs-p-H2"); |
---|
96 | materialName = "H2"; |
---|
97 | crossMap[materialName] = dataSet; |
---|
98 | |
---|
99 | // He cross section data |
---|
100 | dataSet = LoadData("/charge_transf/cs-p-He"); |
---|
101 | materialName = "He"; |
---|
102 | crossMap[materialName] = dataSet; |
---|
103 | |
---|
104 | // CO cross section data |
---|
105 | dataSet = LoadData("/charge_transf/cs-p-CO"); |
---|
106 | materialName = "CO"; |
---|
107 | crossMap[materialName] = dataSet; |
---|
108 | |
---|
109 | // CO2 cross section data |
---|
110 | dataSet = LoadData("/charge_transf/cs-p-CO2"); |
---|
111 | materialName = "CO2"; |
---|
112 | crossMap[materialName] = dataSet; |
---|
113 | |
---|
114 | // N2 cross section data |
---|
115 | dataSet = LoadData("/charge_transf/cs-p-N2"); |
---|
116 | materialName = "N2"; |
---|
117 | crossMap[materialName] = dataSet; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | G4CrossSectionChargeTransferExp::~G4CrossSectionChargeTransferExp() |
---|
122 | { |
---|
123 | std::map<G4String,G4VEMDataSet*,std::less<G4String> >::iterator pos; |
---|
124 | for (pos = crossMap.begin(); pos != crossMap.end(); ++pos) |
---|
125 | { |
---|
126 | G4VEMDataSet* dataSet = (*pos).second; |
---|
127 | delete dataSet; |
---|
128 | dataSet = 0; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | G4double G4CrossSectionChargeTransferExp::CrossSection(const G4Track& track) |
---|
134 | { |
---|
135 | G4double sigma = DBL_MIN; |
---|
136 | |
---|
137 | const G4DynamicParticle* particle = track.GetDynamicParticle(); |
---|
138 | G4double e = particle->GetKineticEnergy(); |
---|
139 | |
---|
140 | // Get the material the track is in |
---|
141 | G4Material* material = track.GetMaterial(); |
---|
142 | G4String materialName; |
---|
143 | materialName = material->GetName(); |
---|
144 | |
---|
145 | // Check whether cross section data are available for the current material |
---|
146 | |
---|
147 | std::map<G4String,G4VEMDataSet*,std::less<G4String> >::const_iterator pos; |
---|
148 | pos = crossMap.find(materialName); |
---|
149 | if (pos!= crossMap.end()) |
---|
150 | { |
---|
151 | G4VEMDataSet* dataSet = (*pos).second; |
---|
152 | // G4VEMDataSet* dataSet = crossMap["He"]; |
---|
153 | const G4DataVector energies = dataSet->GetEnergies(0); |
---|
154 | G4int nPoints = energies.size(); |
---|
155 | |
---|
156 | G4double eMin = energies[0]; |
---|
157 | G4double eMax = energies[nPoints-1]; |
---|
158 | |
---|
159 | if (e >= eMin && e <= eMax) |
---|
160 | { |
---|
161 | sigma = dataSet->FindValue(e); |
---|
162 | } |
---|
163 | } |
---|
164 | return sigma; |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | G4VEMDataSet* G4CrossSectionChargeTransferExp::LoadData(const G4String& fileName) |
---|
169 | { |
---|
170 | std::ostringstream ost; |
---|
171 | ost << fileName << ".dat"; |
---|
172 | G4String nameF(ost.str()); |
---|
173 | |
---|
174 | char* path = getenv("G4LEDATA"); |
---|
175 | if (!path) |
---|
176 | { |
---|
177 | G4String excep("G4EMDataSet - G4LEDATA environment variable not set"); |
---|
178 | G4Exception(excep); |
---|
179 | } |
---|
180 | |
---|
181 | G4String pathString(path); |
---|
182 | G4String dirFile = pathString + nameF; |
---|
183 | std::ifstream file(dirFile); |
---|
184 | std::filebuf* lsdp = file.rdbuf(); |
---|
185 | |
---|
186 | if (! (lsdp->is_open()) ) |
---|
187 | { |
---|
188 | G4String s1("G4CrossSectionChargeTransferExp::LoadData data file: "); |
---|
189 | G4String s2(" not found"); |
---|
190 | G4String excep = s1 + dirFile + s2; |
---|
191 | G4Exception(excep); |
---|
192 | } |
---|
193 | |
---|
194 | G4double a = 0; |
---|
195 | G4int k = 1; |
---|
196 | G4DataVector* energies = new G4DataVector; |
---|
197 | G4DataVector* data = new G4DataVector; |
---|
198 | do |
---|
199 | { |
---|
200 | file >> a; |
---|
201 | G4int nColumns = 2; |
---|
202 | // The file is organized into two columns: |
---|
203 | // 1st column is the energy |
---|
204 | // 2nd column is the corresponding value |
---|
205 | // The file terminates with the pattern: -1 -1 |
---|
206 | // -2 -2 |
---|
207 | if (a == -1 || a == -2) |
---|
208 | { |
---|
209 | } |
---|
210 | else |
---|
211 | { |
---|
212 | if (k%nColumns != 0) |
---|
213 | { |
---|
214 | G4double e = a * unit1; |
---|
215 | energies->push_back(e); |
---|
216 | k++; |
---|
217 | } |
---|
218 | else if (k%nColumns == 0) |
---|
219 | { |
---|
220 | G4double value = a * unit2; |
---|
221 | data->push_back(value); |
---|
222 | k = 1; |
---|
223 | } |
---|
224 | } |
---|
225 | } while (a != -2); // end of file |
---|
226 | |
---|
227 | file.close(); |
---|
228 | G4VDataSetAlgorithm* algo = new G4LogLogInterpolation; |
---|
229 | G4VEMDataSet* dataSet = new G4EMDataSet(0,energies,data,algo); |
---|
230 | |
---|
231 | //dataSet->PrintData(); |
---|
232 | |
---|
233 | return dataSet; |
---|
234 | |
---|
235 | } |
---|