Geant4 11.2.2
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 (G4bool master=true)
 
 ~G4LossTableBuilder ()
 
void BuildDEDXTable (G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
 
void BuildRangeTable (const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable)
 
void BuildInverseRangeTable (const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable)
 
G4PhysicsTableBuildTableForModel (G4PhysicsTable *table, G4VEmModel *model, const G4ParticleDefinition *, G4double emin, G4double emax, G4bool spline)
 
void InitialiseBaseMaterials (const G4PhysicsTable *table=nullptr)
 
const std::vector< G4int > * GetCoupleIndexes () const
 
const std::vector< G4double > * GetDensityFactors () const
 
G4bool GetFlag (size_t idx)
 
G4bool GetBaseMaterialFlag ()
 
void SetSplineFlag (G4bool flag)
 
void SetInitialisationFlag (G4bool flag)
 
void SetBaseMaterialActive (G4bool flag)
 
G4LossTableBuilderoperator= (const G4LossTableBuilder &right)=delete
 
 G4LossTableBuilder (const G4LossTableBuilder &)=delete
 

Detailed Description

Definition at line 59 of file G4LossTableBuilder.hh.

Constructor & Destructor Documentation

◆ G4LossTableBuilder() [1/2]

G4LossTableBuilder::G4LossTableBuilder ( G4bool master = true)

Definition at line 75 of file G4LossTableBuilder.cc.

76{
77 theParameters = G4EmParameters::Instance();
78 if (nullptr == theFlag) {
79 if (!master) {
81 ed << "The table builder is instantiated in a worker thread ";
82 G4Exception("G4LossTableBuilder::G4LossTableBuilder ", "em0001",
83 JustWarning, ed);
84 }
85 theDensityFactor = new std::vector<G4double>;
86 theDensityIdx = new std::vector<G4int>;
87 theFlag = new std::vector<G4bool>;
88 isInitializer = true;
89 }
90}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
static G4EmParameters * Instance()

◆ ~G4LossTableBuilder()

G4LossTableBuilder::~G4LossTableBuilder ( )

Definition at line 94 of file G4LossTableBuilder.cc.

95{
96 if (isInitializer) {
97 delete theDensityFactor;
98 delete theDensityIdx;
99 delete theFlag;
100 theDensityFactor = nullptr;
101 theDensityIdx = nullptr;
102 theFlag = nullptr;
103 }
104}

◆ G4LossTableBuilder() [2/2]

G4LossTableBuilder::G4LossTableBuilder ( const G4LossTableBuilder & )
delete

Member Function Documentation

◆ BuildDEDXTable()

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

Definition at line 139 of file G4LossTableBuilder.cc.

141{
142 InitialiseBaseMaterials(dedxTable);
143 std::size_t n_processes = list.size();
144 if(1 >= n_processes) { return; }
145
146 std::size_t nCouples = dedxTable->size();
147 //G4cout << "Nproc= " << n_processes << " nCouples=" << nCouples << " Nv= "
148 // << dedxTable->size() << G4endl;
149 if(0 >= nCouples) { return; }
150
151 for (std::size_t i=0; i<nCouples; ++i) {
152 auto pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[i]);
153 if(pv0 == nullptr) { continue; }
154 std::size_t npoints = pv0->GetVectorLength();
155 auto pv = new G4PhysicsLogVector(*pv0);
156 for (std::size_t j=0; j<npoints; ++j) {
157 G4double dedx = 0.0;
158 for (std::size_t k=0; k<n_processes; ++k) {
159 const G4PhysicsVector* pv1 = (*(list[k]))[i];
160 dedx += (*pv1)[j];
161 }
162 pv->PutValue(j, dedx);
163 }
164 if(splineFlag) { pv->FillSecondDerivatives(); }
166 }
167 //G4cout << "### G4LossTableBuilder::BuildDEDXTable " << G4endl;
168 //G4cout << *dedxTable << G4endl;
169}
double G4double
Definition G4Types.hh:83
void InitialiseBaseMaterials(const G4PhysicsTable *table=nullptr)
static void SetPhysicsVector(G4PhysicsTable *physTable, std::size_t idx, G4PhysicsVector *vec)
std::size_t GetVectorLength() const

◆ BuildInverseRangeTable()

void G4LossTableBuilder::BuildInverseRangeTable ( const G4PhysicsTable * rangeTable,
G4PhysicsTable * invRangeTable )

Definition at line 255 of file G4LossTableBuilder.cc.

258{
259 std::size_t nCouples = rangeTable->size();
260 if(0 >= nCouples) { return; }
261
262 for (std::size_t i=0; i<nCouples; ++i) {
263 G4PhysicsVector* pv = (*rangeTable)[i];
264 if((pv == nullptr) || (isBaseMatActive && !(*theFlag)[i])) { continue; }
265 std::size_t npoints = pv->GetVectorLength();
266
267 delete (*invRangeTable)[i];
268 auto v = new G4PhysicsFreeVector(npoints, splineFlag);
269
270 for (std::size_t j=0; j<npoints; ++j) {
271 G4double e = pv->Energy(j);
272 G4double r = (*pv)[j];
273 v->PutValues(j,r,e);
274 }
275 if (splineFlag) { v->FillSecondDerivatives(); }
276 v->EnableLogBinSearch(theParameters->NumberForFreeVector());
277
278 G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v);
279 }
280 //G4cout << "### Inverse range table" << G4endl;
281 //G4cout << *invRangeTable << G4endl;
282}
G4int NumberForFreeVector() const
G4double Energy(const std::size_t index) const

Referenced by G4TablesForExtrapolator::Initialisation().

◆ BuildRangeTable()

void G4LossTableBuilder::BuildRangeTable ( const G4PhysicsTable * dedxTable,
G4PhysicsTable * rangeTable )

Definition at line 173 of file G4LossTableBuilder.cc.

176{
177 //G4cout << "### G4LossTableBuilder::BuildRangeTable: DEDX table" << G4endl;
178 //G4cout << *const_cast<G4PhysicsTable*>(dedxTable) << G4endl;
179 const std::size_t nCouples = dedxTable->size();
180 if(0 >= nCouples) { return; }
181
182 const std::size_t n = 100;
183 const G4double del = 1.0/(G4double)n;
184
185 for (std::size_t i=0; i<nCouples; ++i) {
186 auto pv = static_cast<G4PhysicsLogVector*>((*dedxTable)[i]);
187 if((pv == nullptr) || (isBaseMatActive && !(*theFlag)[i])) { continue; }
188 std::size_t npoints = pv->GetVectorLength();
189 std::size_t bin0 = 0;
190 G4double elow = pv->Energy(0);
191 G4double ehigh = pv->Energy(npoints-1);
192 G4double dedx1 = (*pv)[0];
193
194 // protection for specific cases dedx=0
195 if(dedx1 == 0.0) {
196 for (std::size_t k=1; k<npoints; ++k) {
197 ++bin0;
198 elow = pv->Energy(k);
199 dedx1 = (*pv)[k];
200 if(dedx1 > 0.0) { break; }
201 }
202 npoints -= bin0;
203 }
204
205 // initialisation of a new vector
206 if(npoints < 3) { npoints = 3; }
207
208 delete (*rangeTable)[i];
210 if(0 == bin0) { v = new G4PhysicsLogVector(*pv); }
211 else { v = new G4PhysicsLogVector(elow, ehigh, npoints-1, splineFlag); }
212
213 // assumed dedx proportional to beta
214 G4double energy1 = v->Energy(0);
215 G4double range = 2.*energy1/dedx1;
216 /*
217 G4cout << "New Range vector Npoints=" << v->GetVectorLength()
218 << " coupleIdx=" << i << " spline=" << v->GetSpline()
219 << " Elow=" << v->GetMinEnergy() <<" Ehigh=" << v->GetMinEnergy()
220 << " DEDX(Elow)=" << dedx1 << " R(Elow)=" << range << G4endl;
221 */
222 v->PutValue(0,range);
223
224 for (std::size_t j=1; j<npoints; ++j) {
225
226 G4double energy2 = v->Energy(j);
227 G4double de = (energy2 - energy1) * del;
228 G4double energy = energy2 + de*0.5;
229 G4double sum = 0.0;
230 std::size_t idx = j - 1;
231 for (std::size_t k=0; k<n; ++k) {
232 energy -= de;
233 dedx1 = pv->Value(energy, idx);
234 if(dedx1 > 0.0) { sum += de/dedx1; }
235 }
236 range += sum;
237 /*
238 if(energy < 10.)
239 G4cout << "j= " << j << " e1= " << energy1 << " e2= " << energy2
240 << " n= " << n << " range=" << range<< G4endl;
241 */
242 v->PutValue(j,range);
243 energy1 = energy2;
244 }
245 if(splineFlag) { v->FillSecondDerivatives(); }
247 }
248 //G4cout << "### Range table" << G4endl;
249 //G4cout << *rangeTable << G4endl;
250}
void PutValue(const std::size_t index, const G4double value)
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)
G4double energy(const ThreeVector &p, const G4double m)

Referenced by G4TablesForExtrapolator::Initialisation().

◆ BuildTableForModel()

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

Definition at line 377 of file G4LossTableBuilder.cc.

382{
383 // check input
385 if(nullptr == table) { return table; }
386 if(emin >= emax) {
387 table->clearAndDestroy();
388 delete table;
389 table = nullptr;
390 return table;
391 }
393 G4int nbins = theParameters->NumberOfBinsPerDecade();
394
395 // Access to materials
396 const G4ProductionCutsTable* theCoupleTable=
398 std::size_t numOfCouples = theCoupleTable->GetTableSize();
399
400 G4PhysicsLogVector* aVector = nullptr;
401
402 for(G4int i=0; i<(G4int)numOfCouples; ++i) {
403 if ((*theFlag)[i]) {
404
405 // create physics vector and fill it
406 auto couple = theCoupleTable->GetMaterialCutsCouple(i);
407 delete (*table)[i];
408
409 // if start from zero then change the scale
410
411 const G4Material* mat = couple->GetMaterial();
412
413 G4double tmin = std::max(emin,model->MinPrimaryEnergy(mat,part));
414 if(0.0 >= tmin) { tmin = CLHEP::eV; }
415 G4int n = nbins;
416
417 if(tmin >= emax) {
418 aVector = nullptr;
419 } else {
420 n *= G4lrint(std::log10(emax/tmin));
421 n = std::max(n, 3);
422 aVector = new G4PhysicsLogVector(tmin, emax, n, spline);
423 }
424
425 if(nullptr != aVector) {
426 //G4cout << part->GetParticleName() << " in " << mat->GetName()
427 // << " tmin= " << tmin << G4endl;
428 for(G4int j=0; j<=n; ++j) {
429 aVector->PutValue(j, model->Value(couple, part,
430 aVector->Energy(j)));
431 }
432 if(spline) { aVector->FillSecondDerivatives(); }
433 }
435 }
436 }
437 /*
438 G4cout << "G4LossTableBuilder::BuildTableForModel done for "
439 << part->GetParticleName() << " and "<< model->GetName()
440 << " " << table << G4endl;
441 */
442 //G4cout << *table << G4endl;
443 return table;
444}
int G4int
Definition G4Types.hh:85
G4int NumberOfBinsPerDecade() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
void clearAndDestroy()
const G4MaterialCutsCouple * GetMaterialCutsCouple(G4int i) const
std::size_t GetTableSize() const
static G4ProductionCutsTable * GetProductionCutsTable()
virtual G4double MinPrimaryEnergy(const G4Material *, const G4ParticleDefinition *, G4double cut=0.0)
virtual G4double Value(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy)
int G4lrint(double ad)
Definition templates.hh:134

Referenced by G4VMscModel::GetParticleChangeForMSC().

◆ GetBaseMaterialFlag()

◆ GetCoupleIndexes()

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

◆ GetDensityFactors()

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

Definition at line 115 of file G4LossTableBuilder.cc.

116{
117 return theDensityFactor;
118}

Referenced by G4VEmModel::G4VEmModel(), G4VEmProcess::G4VEmProcess(), and G4VEnergyLossProcess::G4VEnergyLossProcess().

◆ GetFlag()

G4bool G4LossTableBuilder::GetFlag ( size_t idx)

Definition at line 122 of file G4LossTableBuilder.cc.

123{
124 if (theFlag->empty()) { InitialiseBaseMaterials(); }
125 return (idx < theFlag->size()) ? (*theFlag)[idx] : false;
126}

Referenced by G4EmTableUtil::BuildDEDXTable(), G4EmTableUtil::BuildLambdaTable(), G4EmTableUtil::BuildLambdaTable(), G4GammaGeneralProcess::BuildPhysicsTable(), and G4TransportationWithMsc::BuildPhysicsTable().

◆ InitialiseBaseMaterials()

void G4LossTableBuilder::InitialiseBaseMaterials ( const G4PhysicsTable * table = nullptr)

Definition at line 286 of file G4LossTableBuilder.cc.

287{
288 if(!isInitializer) { return; }
289 const G4ProductionCutsTable* theCoupleTable=
291 std::size_t nCouples = theCoupleTable->GetTableSize();
292 std::size_t nFlags = theFlag->size();
293 /*
294 G4cout << "### InitialiseBaseMaterials: nCouples=" << nCouples
295 << " nFlags=" << nFlags << " isInit:" << isInitialized
296 << " baseMat:" << baseMatFlag << G4endl;
297 */
298 // define base material flag
299 if(isBaseMatActive && !baseMatFlag) {
300 for(G4int i=0; i<(G4int)nCouples; ++i) {
301 if(nullptr != theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetBaseMaterial()) {
302 baseMatFlag = true;
303 isInitialized = false;
304 break;
305 }
306 }
307 }
308
309 if(nFlags != nCouples) { isInitialized = false; }
310 if(isInitialized) { return; }
311
312 // reserve memory
313 theFlag->resize(nCouples, true);
314 if(nullptr == table) { return; }
315
316 if(baseMatFlag) {
317 theDensityFactor->resize(nCouples,1.0);
318 theDensityIdx->resize(nCouples);
319 }
320
321 // define default flag and index of used material cut couple
322 for(G4int i=0; i<(G4int)nCouples; ++i) {
323 (*theFlag)[i] = table->GetFlag(i);
324 if(baseMatFlag) { (*theDensityIdx)[i] = i; }
325 }
326 isInitialized = true;
327 if(baseMatFlag) {
328 // use base materials
329 for(G4int i=0; i<(G4int)nCouples; ++i) {
330 // base material is needed only for a couple which is not
331 // initialised and for which tables will be computed
332 auto couple = theCoupleTable->GetMaterialCutsCouple(i);
333 auto pcuts = couple->GetProductionCuts();
334 auto mat = couple->GetMaterial();
335 auto bmat = mat->GetBaseMaterial();
336
337 // base material exists - find it and check if it can be reused
338 if(nullptr != bmat) {
339 for(G4int j=0; j<(G4int)nCouples; ++j) {
340 if(j == i) { continue; }
341 auto bcouple = theCoupleTable->GetMaterialCutsCouple(j);
342
343 if(bcouple->GetMaterial() == bmat &&
344 bcouple->GetProductionCuts() == pcuts) {
345
346 // based couple exist in the same region
347 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
348 (*theDensityIdx)[i] = j;
349 (*theFlag)[i] = false;
350
351 // ensure that there will no double initialisation
352 (*theDensityFactor)[j] = 1.0;
353 (*theDensityIdx)[j] = j;
354 (*theFlag)[j] = true;
355 break;
356 }
357 }
358 }
359 }
360 }
361 /*
362 G4cout << "### G4LossTableBuilder::InitialiseBaseMaterials: flag="
363 << baseMatFlag << G4endl;
364 for(std::size_t i=0; i<nCouples; ++i) {
365 G4cout << "CoupleIdx=" << i << " Flag= " << (*theFlag)[i] << " "
366 << theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName()
367 << " TableFlag= " << table->GetFlag(i)
368 << " " << (*table)[i]
369 << G4endl;
370 }
371 */
372}
const G4Material * GetMaterial() const
G4ProductionCuts * GetProductionCuts() const
const G4Material * GetBaseMaterial() const
G4bool GetFlag(std::size_t i) const

Referenced by BuildDEDXTable(), BuildTableForModel(), GetBaseMaterialFlag(), GetFlag(), G4TransportationWithMsc::PreparePhysicsTable(), G4VEmProcess::PreparePhysicsTable(), and G4VEnergyLossProcess::PreparePhysicsTable().

◆ operator=()

G4LossTableBuilder & G4LossTableBuilder::operator= ( const G4LossTableBuilder & right)
delete

◆ SetBaseMaterialActive()

void G4LossTableBuilder::SetBaseMaterialActive ( G4bool flag)
inline

Definition at line 133 of file G4LossTableBuilder.hh.

134{
135 isBaseMatActive = flag;
136 if(!flag) {
137 baseMatFlag = false;
138 isInitialized = false;
139 }
140}

Referenced by G4TablesForExtrapolator::Initialisation().

◆ SetInitialisationFlag()

void G4LossTableBuilder::SetInitialisationFlag ( G4bool flag)
inline

Definition at line 128 of file G4LossTableBuilder.hh.

129{
130 isInitialized = flag;
131}

Referenced by G4LossTableManager::ResetParameters().

◆ SetSplineFlag()

void G4LossTableBuilder::SetSplineFlag ( G4bool flag)
inline

Definition at line 123 of file G4LossTableBuilder.hh.

124{
125 splineFlag = flag;
126}

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