| 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.28 2009/02/18 16:24:47 vnivanch Exp $
|
|---|
| 27 | // GEANT4 tag $Name: geant4-09-03-beta-cand-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 | //
|
|---|
| 50 | // Class Description:
|
|---|
| 51 | //
|
|---|
| 52 | // -------------------------------------------------------------------
|
|---|
| 53 | //
|
|---|
| 54 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 55 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 56 |
|
|---|
| 57 | #include "G4LossTableBuilder.hh"
|
|---|
| 58 | #include "G4PhysicsTable.hh"
|
|---|
| 59 | #include "G4PhysicsLogVector.hh"
|
|---|
| 60 | #include "G4PhysicsTableHelper.hh"
|
|---|
| 61 | #include "G4LPhysicsFreeVector.hh"
|
|---|
| 62 |
|
|---|
| 63 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 64 |
|
|---|
| 65 | G4LossTableBuilder::G4LossTableBuilder()
|
|---|
| 66 | {
|
|---|
| 67 | splineFlag = true;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 71 |
|
|---|
| 72 | G4LossTableBuilder::~G4LossTableBuilder()
|
|---|
| 73 | {}
|
|---|
| 74 |
|
|---|
| 75 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 76 |
|
|---|
| 77 | void
|
|---|
| 78 | G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable,
|
|---|
| 79 | const std::vector<G4PhysicsTable*>& list)
|
|---|
| 80 | {
|
|---|
| 81 | size_t n_processes = list.size();
|
|---|
| 82 | if(1 >= n_processes) return;
|
|---|
| 83 |
|
|---|
| 84 | size_t n_vectors = (list[0])->length();
|
|---|
| 85 | if(0 >= n_vectors) return;
|
|---|
| 86 |
|
|---|
| 87 | G4bool b;
|
|---|
| 88 |
|
|---|
| 89 | G4PhysicsVector* pv = (*(list[0]))[0];
|
|---|
| 90 | size_t nbins = pv->GetVectorLength();
|
|---|
| 91 | G4double elow = pv->GetLowEdgeEnergy(0);
|
|---|
| 92 | G4double ehigh = pv->GetLowEdgeEnergy(nbins);
|
|---|
| 93 | for (size_t i=0; i<n_vectors; i++) {
|
|---|
| 94 |
|
|---|
| 95 | pv = new G4PhysicsLogVector(elow, ehigh, nbins);
|
|---|
| 96 | pv->SetSpline(splineFlag);
|
|---|
| 97 | for (size_t j=0; j<nbins; j++) {
|
|---|
| 98 | G4double dedx = 0.0;
|
|---|
| 99 | G4double energy = pv->GetLowEdgeEnergy(j);
|
|---|
| 100 |
|
|---|
| 101 | for (size_t k=0; k<n_processes; k++) {
|
|---|
| 102 | dedx += ((*(list[k]))[i])->GetValue(energy, b);
|
|---|
| 103 | }
|
|---|
| 104 | pv->PutValue(j, dedx);
|
|---|
| 105 | G4PhysicsTableHelper::SetPhysicsVector(dedxTable, i, pv);
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 111 |
|
|---|
| 112 | void G4LossTableBuilder::BuildRangeTable(const G4PhysicsTable* dedxTable,
|
|---|
| 113 | G4PhysicsTable* rangeTable,
|
|---|
| 114 | G4bool isIonisation)
|
|---|
| 115 | // Build range table from the energy loss table
|
|---|
| 116 | {
|
|---|
| 117 | size_t n_vectors = dedxTable->length();
|
|---|
| 118 | if(!n_vectors) return;
|
|---|
| 119 |
|
|---|
| 120 | G4bool b;
|
|---|
| 121 | size_t n = 100;
|
|---|
| 122 | G4double del = 1.0/(G4double)n;
|
|---|
| 123 |
|
|---|
| 124 | for (size_t i=0; i<n_vectors; i++) {
|
|---|
| 125 |
|
|---|
| 126 | if (rangeTable->GetFlag(i) || !isIonisation) {
|
|---|
| 127 | G4PhysicsVector* pv = (*dedxTable)[i];
|
|---|
| 128 | size_t nbins = pv->GetVectorLength();
|
|---|
| 129 | size_t bin0 = 0;
|
|---|
| 130 | G4double elow = pv->GetLowEdgeEnergy(0);
|
|---|
| 131 | G4double ehigh = pv->GetLowEdgeEnergy(nbins);
|
|---|
| 132 | G4double dedx1 = pv->GetValue(elow, b);
|
|---|
| 133 |
|
|---|
| 134 | //G4cout << "nbins= " << nbins << " dedx1= " << dedx1 << G4endl;
|
|---|
| 135 |
|
|---|
| 136 | // protection for specific cases dedx=0
|
|---|
| 137 | if(dedx1 == 0.0) {
|
|---|
| 138 | for (size_t k=1; k<nbins-1; k++) {
|
|---|
| 139 | bin0++;
|
|---|
| 140 | elow = pv->GetLowEdgeEnergy(k);
|
|---|
| 141 | dedx1 = pv->GetValue(elow, b);
|
|---|
| 142 | if(dedx1 > 0.0) break;
|
|---|
| 143 | }
|
|---|
| 144 | nbins -= bin0;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | //G4cout << "nbins= " << nbins << " elow= " << elow << " ehigh= " << ehigh << G4endl;
|
|---|
| 148 | // initialisation of a new vector
|
|---|
| 149 | G4PhysicsLogVector* v = new G4PhysicsLogVector(elow, ehigh, nbins);
|
|---|
| 150 | // dedx is exect zero
|
|---|
| 151 | if(nbins <= 2) {
|
|---|
| 152 | v->PutValue(0,1000.);
|
|---|
| 153 | v->PutValue(1,2000.);
|
|---|
| 154 | G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v);
|
|---|
| 155 | return;
|
|---|
| 156 | }
|
|---|
| 157 | v->SetSpline(splineFlag);
|
|---|
| 158 |
|
|---|
| 159 | // assumed dedx proportional to beta
|
|---|
| 160 | G4double range = 2.*elow/dedx1;
|
|---|
| 161 | v->PutValue(0,range);
|
|---|
| 162 | G4double energy1 = elow;
|
|---|
| 163 |
|
|---|
| 164 | for (size_t j=1; j<nbins; j++) {
|
|---|
| 165 |
|
|---|
| 166 | G4double energy2 = pv->GetLowEdgeEnergy(j+bin0);
|
|---|
| 167 | G4double de = (energy2 - energy1) * del;
|
|---|
| 168 | G4double energy = energy2 + de*0.5;
|
|---|
| 169 | for (size_t k=0; k<n; k++) {
|
|---|
| 170 | energy -= de;
|
|---|
| 171 | dedx1 = pv->GetValue(energy, b);
|
|---|
| 172 | if(dedx1 > 0.0) range += de/dedx1;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | // G4cout << "Range i= " <<i << " j= " << j << G4endl;
|
|---|
| 176 | v->PutValue(j,range);
|
|---|
| 177 | energy1 = energy2;
|
|---|
| 178 | }
|
|---|
| 179 | G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v);
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 185 |
|
|---|
| 186 | void G4LossTableBuilder::BuildInverseRangeTable(const G4PhysicsTable* rangeTable,
|
|---|
| 187 | G4PhysicsTable* invRangeTable,
|
|---|
| 188 | G4bool isIonisation)
|
|---|
| 189 | // Build inverse range table from the energy loss table
|
|---|
| 190 | {
|
|---|
| 191 | size_t n_vectors = rangeTable->length();
|
|---|
| 192 | if(!n_vectors) return;
|
|---|
| 193 | G4bool b;
|
|---|
| 194 |
|
|---|
| 195 | for (size_t i=0; i<n_vectors; i++) {
|
|---|
| 196 |
|
|---|
| 197 | if (invRangeTable->GetFlag(i) || !isIonisation) {
|
|---|
| 198 | G4PhysicsVector* pv = (*rangeTable)[i];
|
|---|
| 199 | size_t nbins = pv->GetVectorLength();
|
|---|
| 200 | G4double elow = pv->GetLowEdgeEnergy(0);
|
|---|
| 201 | G4double ehigh = pv->GetLowEdgeEnergy(nbins-1);
|
|---|
| 202 | G4double rlow = pv->GetValue(elow, b);
|
|---|
| 203 | G4double rhigh = pv->GetValue(ehigh, b);
|
|---|
| 204 |
|
|---|
| 205 | G4LPhysicsFreeVector* v = new G4LPhysicsFreeVector(nbins,rlow,rhigh);
|
|---|
| 206 | v->SetSpline(splineFlag);
|
|---|
| 207 |
|
|---|
| 208 | for (size_t j=0; j<nbins; j++) {
|
|---|
| 209 | G4double e = pv->GetLowEdgeEnergy(j);
|
|---|
| 210 | G4double r = pv->GetValue(e, b);
|
|---|
| 211 | v->PutValues(j,r,e);
|
|---|
| 212 | }
|
|---|
| 213 | v->PutValues(nbins,rhigh+rlow,ehigh);
|
|---|
| 214 |
|
|---|
| 215 | G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v);
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 221 |
|
|---|