Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LossTableBuilder Class Reference

#include <G4LossTableBuilder.hh>

Public Member Functions

 G4LossTableBuilder ()
 
virtual ~G4LossTableBuilder ()
 
void BuildDEDXTable (G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
 
void BuildRangeTable (const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable, G4bool isIonisation=false)
 
void BuildInverseRangeTable (const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable, G4bool isIonisation=false)
 
G4PhysicsTableBuildTableForModel (G4PhysicsTable *table, G4VEmModel *model, const G4ParticleDefinition *, G4double emin, G4double emax, G4bool spline)
 
void InitialiseBaseMaterials (G4PhysicsTable *table)
 
const std::vector< G4int > * GetCoupleIndexes ()
 
const std::vector< G4double > * GetDensityFactors ()
 
G4bool GetFlag (size_t idx) const
 
void SetSplineFlag (G4bool flag)
 
void SetInitialisationFlag (G4bool flag)
 

Detailed Description

Definition at line 61 of file G4LossTableBuilder.hh.

Constructor & Destructor Documentation

◆ G4LossTableBuilder()

G4LossTableBuilder::G4LossTableBuilder ( )

Definition at line 72 of file G4LossTableBuilder.cc.

73{
74 splineFlag = true;
75 isInitialized = false;
76
77 theDensityFactor = new std::vector<G4double>;
78 theDensityIdx = new std::vector<G4int>;
79 theFlag = new std::vector<G4bool>;
80}

◆ ~G4LossTableBuilder()

G4LossTableBuilder::~G4LossTableBuilder ( )
virtual

Definition at line 84 of file G4LossTableBuilder.cc.

85{
86 delete theDensityFactor;
87 delete theDensityIdx;
88 delete theFlag;
89}

Member Function Documentation

◆ BuildDEDXTable()

void G4LossTableBuilder::BuildDEDXTable ( G4PhysicsTable dedxTable,
const std::vector< G4PhysicsTable * > &  list 
)

Definition at line 94 of file G4LossTableBuilder.cc.

96{
97 size_t n_processes = list.size();
98 //G4cout << "Nproc= " << n_processes << " Ncoup= " << dedxTable->size() << G4endl;
99 if(1 >= n_processes) { return; }
100
101 size_t nCouples = dedxTable->size();
102 if(0 >= nCouples) { return; }
103
104 for (size_t i=0; i<nCouples; ++i) {
105 // if ((*theFlag)[i]) {
106 G4PhysicsLogVector* pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[i]);
107 if(pv0) {
108 size_t npoints = pv0->GetVectorLength();
110 // pv = new G4PhysicsLogVector(elow, ehigh, npoints-1);
111 pv->SetSpline(splineFlag);
112 for (size_t j=0; j<npoints; ++j) {
113 G4double dedx = 0.0;
114 for (size_t k=0; k<n_processes; ++k) {
115 G4PhysicsVector* pv1 = (*(list[k]))[i];
116 dedx += (*pv1)[j];
117 }
118 pv->PutValue(j, dedx);
119 }
120 if(splineFlag) { pv->FillSecondDerivatives(); }
122 }
123 }
124}
double G4double
Definition: G4Types.hh:64
static void SetPhysicsVector(G4PhysicsTable *physTable, size_t idx, G4PhysicsVector *vec)
size_t GetVectorLength() const
void FillSecondDerivatives()
void SetSpline(G4bool)
void PutValue(size_t index, G4double theValue)

◆ BuildInverseRangeTable()

void G4LossTableBuilder::BuildInverseRangeTable ( const G4PhysicsTable rangeTable,
G4PhysicsTable invRangeTable,
G4bool  isIonisation = false 
)

Definition at line 213 of file G4LossTableBuilder.cc.

217{
218 size_t nCouples = rangeTable->size();
219 if(0 >= nCouples) { return; }
220
221 for (size_t i=0; i<nCouples; ++i) {
222
223 if(isIonisation) {
224 if( !(*theFlag)[i] ) { continue; }
225 }
226 G4PhysicsVector* pv = (*rangeTable)[i];
227 size_t npoints = pv->GetVectorLength();
228 G4double rlow = (*pv)[0];
229 G4double rhigh = (*pv)[npoints-1];
230
231 delete (*invRangeTable)[i];
232 G4LPhysicsFreeVector* v = new G4LPhysicsFreeVector(npoints,rlow,rhigh);
233 v->SetSpline(splineFlag);
234
235 for (size_t j=0; j<npoints; ++j) {
236 G4double e = pv->Energy(j);
237 G4double r = (*pv)[j];
238 v->PutValues(j,r,e);
239 }
240 if(splineFlag) { v->FillSecondDerivatives(); }
241
242 G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v);
243 }
244}
void PutValues(size_t binNumber, G4double binValue, G4double dataValue)
G4double Energy(size_t index) const

◆ BuildRangeTable()

void G4LossTableBuilder::BuildRangeTable ( const G4PhysicsTable dedxTable,
G4PhysicsTable rangeTable,
G4bool  isIonisation = false 
)

Definition at line 128 of file G4LossTableBuilder.cc.

132{
133 size_t nCouples = dedxTable->size();
134 if(0 >= nCouples) { return; }
135
136 size_t n = 100;
137 G4double del = 1.0/(G4double)n;
138
139 for (size_t i=0; i<nCouples; ++i) {
140 if(isIonisation) {
141 if( !(*theFlag)[i] ) { continue; }
142 }
143 G4PhysicsLogVector* pv = static_cast<G4PhysicsLogVector*>((*dedxTable)[i]);
144 size_t npoints = pv->GetVectorLength();
145 size_t bin0 = 0;
146 G4double elow = pv->Energy(0);
147 G4double ehigh = pv->Energy(npoints-1);
148 G4double dedx1 = (*pv)[0];
149
150 //G4cout << "i= " << i << "npoints= " << npoints << " dedx1= " << dedx1 << G4endl;
151
152 // protection for specific cases dedx=0
153 if(dedx1 == 0.0) {
154 for (size_t k=1; k<npoints; ++k) {
155 bin0++;
156 elow = pv->Energy(k);
157 dedx1 = (*pv)[k];
158 if(dedx1 > 0.0) { break; }
159 }
160 npoints -= bin0;
161 }
162 //G4cout<<"New Range vector" << G4endl;
163 //G4cout<<"nbins= "<<npoints-1<<" elow= "<<elow<<" ehigh= "<<ehigh
164 // <<" bin0= " << bin0 <<G4endl;
165
166 // initialisation of a new vector
167 if(npoints < 2) { npoints = 2; }
168
169 delete (*rangeTable)[i];
171 if(0 == bin0) { v = new G4PhysicsLogVector(*pv); }
172 else { v = new G4PhysicsLogVector(elow, ehigh, npoints-1); }
173
174 // dedx is exact zero cannot build range table
175 if(2 == npoints) {
176 v->PutValue(0,1000.);
177 v->PutValue(1,2000.);
179 return;
180 }
181 v->SetSpline(splineFlag);
182
183 // assumed dedx proportional to beta
184 G4double energy1 = v->Energy(0);
185 G4double range = 2.*energy1/dedx1;
186 //G4cout << "range0= " << range << G4endl;
187 v->PutValue(0,range);
188
189 for (size_t j=1; j<npoints; ++j) {
190
191 G4double energy2 = v->Energy(j);
192 G4double de = (energy2 - energy1) * del;
193 G4double energy = energy2 + de*0.5;
194 G4double sum = 0.0;
195 //G4cout << "j= " << j << " e1= " << energy1 << " e2= " << energy2
196 // << " n= " << n << G4endl;
197 for (size_t k=0; k<n; ++k) {
198 energy -= de;
199 dedx1 = pv->Value(energy);
200 if(dedx1 > 0.0) { sum += de/dedx1; }
201 }
202 range += sum;
203 v->PutValue(j,range);
204 energy1 = energy2;
205 }
206 if(splineFlag) { v->FillSecondDerivatives(); }
208 }
209}
G4double Value(G4double theEnergy)

◆ BuildTableForModel()

G4PhysicsTable * G4LossTableBuilder::BuildTableForModel ( G4PhysicsTable table,
G4VEmModel model,
const G4ParticleDefinition part,
G4double  emin,
G4double  emax,
G4bool  spline 
)

Definition at line 400 of file G4LossTableBuilder.cc.

405{
406 // check input
408 if(!table) { return table; }
409 if(emin >= emax) {
410 table->clearAndDestroy();
411 delete table;
412 table = 0;
413 return table;
414 }
416
417 G4int nbins = G4int(std::log10(emax/emin) + 0.5)
419 if(nbins < 3) { nbins = 3; }
420
421 // Access to materials
422 const G4ProductionCutsTable* theCoupleTable=
424 size_t numOfCouples = theCoupleTable->GetTableSize();
425
426 G4PhysicsLogVector* aVector = 0;
427 G4PhysicsLogVector* bVector = 0;
428
429 for(size_t i=0; i<numOfCouples; ++i) {
430
431 //G4cout<< "i= " << i << " Flag= " << GetFlag(i) << G4endl;
432
433 if (GetFlag(i)) {
434
435 // create physics vector and fill it
436 const G4MaterialCutsCouple* couple =
437 theCoupleTable->GetMaterialCutsCouple(i);
438 delete (*table)[i];
439
440 // if start from zero then change the scale
441
442 const G4Material* mat = couple->GetMaterial();
443
444 G4double tmin = std::max(emin,model->MinPrimaryEnergy(mat,part));
445 if(0.0 >= tmin) { tmin = eV; }
446 G4int n = nbins + 1;
447
448 if(tmin >= emax) {
449 aVector = 0;
450 } else if(tmin > emin) {
451 G4int bin = nbins*G4int(std::log10(emax/tmin) + 0.5);
452 if(bin < 3) { bin = 3; }
453 n = bin + 1;
454 aVector = new G4PhysicsLogVector(tmin, emax, bin);
455
456 } else if(!bVector) {
457 aVector = new G4PhysicsLogVector(emin, emax, nbins);
458 bVector = aVector;
459
460 } else {
461 aVector = new G4PhysicsLogVector(*bVector);
462 }
463
464 if(aVector) {
465 aVector->SetSpline(spline);
466 for(G4int j=0; j<n; ++j) {
467 aVector->PutValue(j, model->Value(couple, part, aVector->Energy(j)));
468 }
469 if(spline) { aVector->FillSecondDerivatives(); }
470 }
472 }
473 }
474 /*
475 G4cout << "G4LossTableBuilder::BuildTableForModel done for "
476 << part->GetParticleName() << " and "<< model->GetName()
477 << " " << table << G4endl;
478 */
479 return table;
480}
int G4int
Definition: G4Types.hh:66
void InitialiseBaseMaterials(G4PhysicsTable *table)
G4bool GetFlag(size_t idx) const
static G4LossTableManager * Instance()
G4int GetNumberOfBinsPerDecade() const
const G4Material * GetMaterial() const
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
void clearAndDestroy()
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4double Value(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:286
virtual G4double MinPrimaryEnergy(const G4Material *, const G4ParticleDefinition *)
Definition: G4VEmModel.cc:295

Referenced by G4VMscModel::GetParticleChangeForMSC().

◆ GetCoupleIndexes()

const std::vector< G4int > * G4LossTableBuilder::GetCoupleIndexes ( )
inline

Definition at line 123 of file G4LossTableBuilder.hh.

124{
125 if(theDensityIdx->size() == 0) { InitialiseCouples(); }
126 return theDensityIdx;
127}

Referenced by G4VMscModel::GetParticleChangeForMSC(), G4VEmProcess::PreparePhysicsTable(), and G4VEnergyLossProcess::PreparePhysicsTable().

◆ GetDensityFactors()

const std::vector< G4double > * G4LossTableBuilder::GetDensityFactors ( )
inline

Definition at line 130 of file G4LossTableBuilder.hh.

131{
132 if(theDensityIdx->size() == 0) { InitialiseCouples(); }
133 return theDensityFactor;
134}

Referenced by G4VMscModel::GetParticleChangeForMSC(), G4VEmProcess::PreparePhysicsTable(), and G4VEnergyLossProcess::PreparePhysicsTable().

◆ GetFlag()

G4bool G4LossTableBuilder::GetFlag ( size_t  idx) const
inline

Definition at line 136 of file G4LossTableBuilder.hh.

137{
138 return (*theFlag)[idx];
139}

Referenced by G4VEnergyLossProcess::BuildDEDXTable(), G4VEnergyLossProcess::BuildLambdaTable(), and BuildTableForModel().

◆ InitialiseBaseMaterials()

void G4LossTableBuilder::InitialiseBaseMaterials ( G4PhysicsTable table)

Definition at line 249 of file G4LossTableBuilder.cc.

250{
251 size_t nCouples = table->size();
252 size_t nFlags = theFlag->size();
253
254 if(nCouples == nFlags && isInitialized) { return; }
255
256 isInitialized = true;
257
258 //G4cout << "%%%%%% G4LossTableBuilder::InitialiseBaseMaterials Ncouples= "
259 // << nCouples << " FlagSize= " << nFlags << G4endl;
260
261 // variable density check
262 const G4ProductionCutsTable* theCoupleTable=
264
265 /*
266 for(size_t i=0; i<nFlags; ++i) {
267 G4cout << "CoupleIdx= " << i << " Flag= " << (*theFlag)[i]
268 << " tableFlag= " << table->GetFlag(i) << " "
269 << theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName()
270 << G4endl;
271 }
272 */
273
274 // expand vectors
275 if(nFlags < nCouples) {
276 for(size_t i=nFlags; i<nCouples; ++i) { theDensityFactor->push_back(1.0); }
277 for(size_t i=nFlags; i<nCouples; ++i) { theDensityIdx->push_back(-1); }
278 for(size_t i=nFlags; i<nCouples; ++i) { theFlag->push_back(true); }
279 }
280 for(size_t i=0; i<nCouples; ++i) {
281
282 // base material is needed only for a couple which is not
283 // initialised and for which tables will be computed
284 (*theFlag)[i] = table->GetFlag(i);
285 if ((*theDensityIdx)[i] < 0) {
286 (*theDensityIdx)[i] = i;
287 const G4MaterialCutsCouple* couple =
288 theCoupleTable->GetMaterialCutsCouple(i);
289 const G4ProductionCuts* pcuts = couple->GetProductionCuts();
290 const G4Material* mat = couple->GetMaterial();
291 const G4Material* bmat = mat->GetBaseMaterial();
292
293 // base material exists - find it and check if it can be reused
294 if(bmat) {
295 for(size_t j=0; j<nCouples; ++j) {
296
297 if(j == i) { continue; }
298 const G4MaterialCutsCouple* bcouple =
299 theCoupleTable->GetMaterialCutsCouple(j);
300
301 if(bcouple->GetMaterial() == bmat &&
302 bcouple->GetProductionCuts() == pcuts) {
303
304 // based couple exist in the same region
305 (*theDensityIdx)[i] = j;
306 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
307 (*theFlag)[i] = false;
308
309 // ensure that there will no double initialisation
310 (*theDensityIdx)[j] = j;
311 (*theDensityFactor)[j] = 1.0;
312 (*theFlag)[j] = true;
313 break;
314 }
315 }
316 }
317 }
318 }
319 /*
320 for(size_t i=0; i<nCouples; ++i) {
321 G4cout << "CoupleIdx= " << i << " Flag= " << (*theFlag)[i]
322 << " TableFlag= " << table->GetFlag(i) << " "
323 << theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName()
324 << G4endl;
325 }
326 G4cout << "%%%%%% G4LossTableBuilder::InitialiseBaseMaterials end"
327 << G4endl;
328 */
329}
G4ProductionCuts * GetProductionCuts() const
G4double GetDensity() const
Definition: G4Material.hh:179
const G4Material * GetBaseMaterial() const
Definition: G4Material.hh:232
G4bool GetFlag(size_t i) const

Referenced by BuildTableForModel(), G4VEmProcess::PreparePhysicsTable(), and G4VEnergyLossProcess::PreparePhysicsTable().

◆ SetInitialisationFlag()

void G4LossTableBuilder::SetInitialisationFlag ( G4bool  flag)
inline

Definition at line 146 of file G4LossTableBuilder.hh.

147{
148 isInitialized = flag;
149}

Referenced by G4LossTableManager::PreparePhysicsTable().

◆ SetSplineFlag()

void G4LossTableBuilder::SetSplineFlag ( G4bool  flag)
inline

Definition at line 141 of file G4LossTableBuilder.hh.

142{
143 splineFlag = flag;
144}

Referenced by G4LossTableManager::SetSplineFlag().


The documentation for this class was generated from the following files: