source: trunk/source/processes/electromagnetic/utils/src/G4LossTableBuilder.cc@ 1199

Last change on this file since 1199 was 1196, checked in by garnier, 16 years ago

update CVS release candidate geant4.9.3.01

File size: 7.5 KB
RevLine 
[819]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//
[1196]26// $Id: G4LossTableBuilder.cc,v 1.32 2009/08/11 17:24:53 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
[819]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)
[1196]49// 24-06-09 Removed hidden bin in G4PhysicsVector (V.Ivanchenko)
[819]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
66G4LossTableBuilder::G4LossTableBuilder()
[961]67{
68 splineFlag = true;
69}
[819]70
71//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
72
73G4LossTableBuilder::~G4LossTableBuilder()
74{}
75
76//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
77
[961]78void
79G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable,
80 const std::vector<G4PhysicsTable*>& list)
[819]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
[1196]88 G4PhysicsLogVector* pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[0]);
89 size_t npoints = pv0->GetVectorLength();
[819]90 for (size_t i=0; i<n_vectors; i++) {
91
[1196]92 G4PhysicsLogVector* pv = new G4PhysicsLogVector(*pv0);
93 // pv = new G4PhysicsLogVector(elow, ehigh, npoints-1);
[961]94 pv->SetSpline(splineFlag);
[1196]95 for (size_t j=0; j<npoints; j++) {
[819]96 G4double dedx = 0.0;
97 for (size_t k=0; k<n_processes; k++) {
[1196]98 G4PhysicsVector* pv1 = (*(list[k]))[i];
99 dedx += (*pv1)[j];
[819]100 }
101 pv->PutValue(j, dedx);
102 }
[1196]103 if(splineFlag) pv->FillSecondDerivatives();
104 G4PhysicsTableHelper::SetPhysicsVector(dedxTable, i, pv);
[819]105 }
106}
107
108//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
109
110void 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) {
[1196]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);
[819]131
[1055]132 //G4cout << "nbins= " << nbins << " dedx1= " << dedx1 << G4endl;
133
[961]134 // protection for specific cases dedx=0
[819]135 if(dedx1 == 0.0) {
[1196]136 for (size_t k=1; k<npoints; k++) {
[819]137 bin0++;
[1196]138 elow = pv->Energy(k);
139 dedx1 = (*pv)[k];
[819]140 if(dedx1 > 0.0) break;
141 }
[1196]142 npoints -= bin0;
[819]143 }
[1196]144 // G4cout<<"New Range vector" << G4endl;
145 // G4cout<<"nbins= "<<npoints-1<<" elow= "<<elow<<" ehigh= "<<ehigh<<G4endl;
[961]146 // initialisation of a new vector
[1196]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); }
[1055]151 // dedx is exect zero
[1196]152 if(2 == npoints) {
[1055]153 v->PutValue(0,1000.);
154 v->PutValue(1,2000.);
155 G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v);
156 return;
157 }
[961]158 v->SetSpline(splineFlag);
[819]159
[961]160 // assumed dedx proportional to beta
[819]161 G4double range = 2.*elow/dedx1;
162 v->PutValue(0,range);
163 G4double energy1 = elow;
164
[1196]165 for (size_t j=1; j<npoints; j++) {
[819]166
[1196]167 G4double energy2 = pv->Energy(j+bin0);
[819]168 G4double de = (energy2 - energy1) * del;
[961]169 G4double energy = energy2 + de*0.5;
[1196]170 G4double sum = 0.0;
[961]171 for (size_t k=0; k<n; k++) {
172 energy -= de;
[1196]173 dedx1 = pv->Value(energy);
174 if(dedx1 > 0.0) sum += de/dedx1;
[961]175 }
[1196]176 range += sum;
[819]177 // G4cout << "Range i= " <<i << " j= " << j << G4endl;
178 v->PutValue(j,range);
179 energy1 = energy2;
180 }
[1196]181 if(splineFlag) v->FillSecondDerivatives();
[819]182 G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v);
183 }
184 }
185}
186
187//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
188
189void 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];
[1196]201 size_t npoints = pv->GetVectorLength();
202 G4double rlow = (*pv)[0];
203 G4double rhigh = (*pv)[npoints-1];
[819]204
[1196]205 G4LPhysicsFreeVector* v = new G4LPhysicsFreeVector(npoints,rlow,rhigh);
[961]206 v->SetSpline(splineFlag);
207
[1196]208 for (size_t j=0; j<npoints; j++) {
209 G4double e = pv->Energy(j);
210 G4double r = (*pv)[j];
[819]211 v->PutValues(j,r,e);
212 }
[1196]213 if(splineFlag) v->FillSecondDerivatives();
[819]214
215 G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v);
216 }
217 }
218}
219
220//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
221
Note: See TracBrowser for help on using the repository browser.