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 | // $Id: G4LossTableBuilder.cc,v 1.32 2009/08/11 17:24:53 vnivanch Exp $ |
---|
27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
28 | // |
---|
29 | // ------------------------------------------------------------------- |
---|
30 | // |
---|
31 | // GEANT4 Class file |
---|
32 | // |
---|
33 | // |
---|
34 | // File name: G4LossTableBuilder |
---|
35 | // |
---|
36 | // Author: Vladimir Ivanchenko |
---|
37 | // |
---|
38 | // Creation date: 03.01.2002 |
---|
39 | // |
---|
40 | // Modifications: |
---|
41 | // |
---|
42 | // 23-01-03 V.Ivanchenko Cut per region |
---|
43 | // 21-07-04 V.Ivanchenko Fix problem of range for dedx=0 |
---|
44 | // 08-11-04 Migration to new interface of Store/Retrieve tables (V.Ivanchenko) |
---|
45 | // 07-12-04 Fix of BuildDEDX table (V.Ivanchenko) |
---|
46 | // 27-03-06 Add bool options isIonisation (V.Ivanchenko) |
---|
47 | // 16-01-07 Fill new (not old) DEDX table (V.Ivanchenko) |
---|
48 | // 12-02-07 Use G4LPhysicsFreeVector for the inverse range table (V.Ivanchenko) |
---|
49 | // 24-06-09 Removed hidden bin in G4PhysicsVector (V.Ivanchenko) |
---|
50 | // |
---|
51 | // Class Description: |
---|
52 | // |
---|
53 | // ------------------------------------------------------------------- |
---|
54 | // |
---|
55 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
56 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
57 | |
---|
58 | #include "G4LossTableBuilder.hh" |
---|
59 | #include "G4PhysicsTable.hh" |
---|
60 | #include "G4PhysicsLogVector.hh" |
---|
61 | #include "G4PhysicsTableHelper.hh" |
---|
62 | #include "G4LPhysicsFreeVector.hh" |
---|
63 | |
---|
64 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
65 | |
---|
66 | G4LossTableBuilder::G4LossTableBuilder() |
---|
67 | { |
---|
68 | splineFlag = true; |
---|
69 | } |
---|
70 | |
---|
71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
72 | |
---|
73 | G4LossTableBuilder::~G4LossTableBuilder() |
---|
74 | {} |
---|
75 | |
---|
76 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
77 | |
---|
78 | void |
---|
79 | G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable, |
---|
80 | const std::vector<G4PhysicsTable*>& list) |
---|
81 | { |
---|
82 | size_t n_processes = list.size(); |
---|
83 | if(1 >= n_processes) return; |
---|
84 | |
---|
85 | size_t n_vectors = (list[0])->length(); |
---|
86 | if(0 >= n_vectors) return; |
---|
87 | |
---|
88 | G4PhysicsLogVector* pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[0]); |
---|
89 | size_t npoints = pv0->GetVectorLength(); |
---|
90 | for (size_t i=0; i<n_vectors; i++) { |
---|
91 | |
---|
92 | G4PhysicsLogVector* pv = new G4PhysicsLogVector(*pv0); |
---|
93 | // pv = new G4PhysicsLogVector(elow, ehigh, npoints-1); |
---|
94 | pv->SetSpline(splineFlag); |
---|
95 | for (size_t j=0; j<npoints; j++) { |
---|
96 | G4double dedx = 0.0; |
---|
97 | for (size_t k=0; k<n_processes; k++) { |
---|
98 | G4PhysicsVector* pv1 = (*(list[k]))[i]; |
---|
99 | dedx += (*pv1)[j]; |
---|
100 | } |
---|
101 | pv->PutValue(j, dedx); |
---|
102 | } |
---|
103 | if(splineFlag) pv->FillSecondDerivatives(); |
---|
104 | G4PhysicsTableHelper::SetPhysicsVector(dedxTable, i, pv); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
109 | |
---|
110 | void G4LossTableBuilder::BuildRangeTable(const G4PhysicsTable* dedxTable, |
---|
111 | G4PhysicsTable* rangeTable, |
---|
112 | G4bool isIonisation) |
---|
113 | // Build range table from the energy loss table |
---|
114 | { |
---|
115 | size_t n_vectors = dedxTable->length(); |
---|
116 | if(!n_vectors) return; |
---|
117 | |
---|
118 | size_t n = 100; |
---|
119 | G4double del = 1.0/(G4double)n; |
---|
120 | |
---|
121 | for (size_t i=0; i<n_vectors; i++) { |
---|
122 | |
---|
123 | if (rangeTable->GetFlag(i) || !isIonisation) { |
---|
124 | G4PhysicsLogVector* pv = |
---|
125 | static_cast<G4PhysicsLogVector*>((*dedxTable)[i]); |
---|
126 | size_t npoints = pv->GetVectorLength(); |
---|
127 | size_t bin0 = 0; |
---|
128 | G4double elow = pv->Energy(0); |
---|
129 | G4double ehigh = pv->Energy(npoints-1); |
---|
130 | G4double dedx1 = pv->Value(elow); |
---|
131 | |
---|
132 | //G4cout << "nbins= " << nbins << " dedx1= " << dedx1 << G4endl; |
---|
133 | |
---|
134 | // protection for specific cases dedx=0 |
---|
135 | if(dedx1 == 0.0) { |
---|
136 | for (size_t k=1; k<npoints; k++) { |
---|
137 | bin0++; |
---|
138 | elow = pv->Energy(k); |
---|
139 | dedx1 = (*pv)[k]; |
---|
140 | if(dedx1 > 0.0) break; |
---|
141 | } |
---|
142 | npoints -= bin0; |
---|
143 | } |
---|
144 | // G4cout<<"New Range vector" << G4endl; |
---|
145 | // G4cout<<"nbins= "<<npoints-1<<" elow= "<<elow<<" ehigh= "<<ehigh<<G4endl; |
---|
146 | // initialisation of a new vector |
---|
147 | if(npoints < 2) npoints = 2; |
---|
148 | G4PhysicsLogVector* v; |
---|
149 | if(0 == bin0) { v = new G4PhysicsLogVector(*pv); } |
---|
150 | else { v = new G4PhysicsLogVector(elow, ehigh, npoints-1); } |
---|
151 | // dedx is exect zero |
---|
152 | if(2 == npoints) { |
---|
153 | v->PutValue(0,1000.); |
---|
154 | v->PutValue(1,2000.); |
---|
155 | G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v); |
---|
156 | return; |
---|
157 | } |
---|
158 | v->SetSpline(splineFlag); |
---|
159 | |
---|
160 | // assumed dedx proportional to beta |
---|
161 | G4double range = 2.*elow/dedx1; |
---|
162 | v->PutValue(0,range); |
---|
163 | G4double energy1 = elow; |
---|
164 | |
---|
165 | for (size_t j=1; j<npoints; j++) { |
---|
166 | |
---|
167 | G4double energy2 = pv->Energy(j+bin0); |
---|
168 | G4double de = (energy2 - energy1) * del; |
---|
169 | G4double energy = energy2 + de*0.5; |
---|
170 | G4double sum = 0.0; |
---|
171 | for (size_t k=0; k<n; k++) { |
---|
172 | energy -= de; |
---|
173 | dedx1 = pv->Value(energy); |
---|
174 | if(dedx1 > 0.0) sum += de/dedx1; |
---|
175 | } |
---|
176 | range += sum; |
---|
177 | // G4cout << "Range i= " <<i << " j= " << j << G4endl; |
---|
178 | v->PutValue(j,range); |
---|
179 | energy1 = energy2; |
---|
180 | } |
---|
181 | if(splineFlag) v->FillSecondDerivatives(); |
---|
182 | G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v); |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
188 | |
---|
189 | void G4LossTableBuilder::BuildInverseRangeTable(const G4PhysicsTable* rangeTable, |
---|
190 | G4PhysicsTable* invRangeTable, |
---|
191 | G4bool isIonisation) |
---|
192 | // Build inverse range table from the energy loss table |
---|
193 | { |
---|
194 | size_t n_vectors = rangeTable->length(); |
---|
195 | if(!n_vectors) return; |
---|
196 | |
---|
197 | for (size_t i=0; i<n_vectors; i++) { |
---|
198 | |
---|
199 | if (invRangeTable->GetFlag(i) || !isIonisation) { |
---|
200 | G4PhysicsVector* pv = (*rangeTable)[i]; |
---|
201 | size_t npoints = pv->GetVectorLength(); |
---|
202 | G4double rlow = (*pv)[0]; |
---|
203 | G4double rhigh = (*pv)[npoints-1]; |
---|
204 | |
---|
205 | G4LPhysicsFreeVector* v = new G4LPhysicsFreeVector(npoints,rlow,rhigh); |
---|
206 | v->SetSpline(splineFlag); |
---|
207 | |
---|
208 | for (size_t j=0; j<npoints; j++) { |
---|
209 | G4double e = pv->Energy(j); |
---|
210 | G4double r = (*pv)[j]; |
---|
211 | v->PutValues(j,r,e); |
---|
212 | } |
---|
213 | if(splineFlag) v->FillSecondDerivatives(); |
---|
214 | |
---|
215 | G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v); |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
221 | |
---|