Geant4 10.7.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 (G4bool master=true)
 
virtual ~G4LossTableBuilder ()
 
void BuildDEDXTable (G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
 
void BuildRangeTable (const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable, G4bool useBM=false)
 
void BuildInverseRangeTable (const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable, G4bool useBM=false)
 
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)
 
void SetSplineFlag (G4bool flag)
 
void SetInitialisationFlag (G4bool flag)
 

Detailed Description

Definition at line 60 of file G4LossTableBuilder.hh.

Constructor & Destructor Documentation

◆ G4LossTableBuilder()

G4LossTableBuilder::G4LossTableBuilder ( G4bool  master = true)

Definition at line 78 of file G4LossTableBuilder.cc.

78 : isMaster(master)
79{
80 theParameters = G4EmParameters::Instance();
81 splineFlag = true;
82 isInitialized = false;
83 if(isMaster || !theFlag) {
84#ifdef G4MULTITHREADED
85 G4MUTEXLOCK(&ltbMutex);
86 if(isMaster || !theFlag) {
87#endif
88 isMaster = true;
89 theDensityFactor = new std::vector<G4double>;
90 theDensityIdx = new std::vector<G4int>;
91 theFlag = new std::vector<G4bool>;
92 } else {
93 isMaster = false;
94#ifdef G4MULTITHREADED
95 }
96 G4MUTEXUNLOCK(&ltbMutex);
97#endif
98 }
99}
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
static G4EmParameters * Instance()

◆ ~G4LossTableBuilder()

G4LossTableBuilder::~G4LossTableBuilder ( )
virtual

Definition at line 103 of file G4LossTableBuilder.cc.

104{
105 if(isMaster) {
106 delete theDensityFactor;
107 delete theDensityIdx;
108 delete theFlag;
109 theDensityFactor = nullptr;
110 theDensityIdx = nullptr;
111 theFlag = nullptr;
112 }
113}

Member Function Documentation

◆ BuildDEDXTable()

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

Definition at line 140 of file G4LossTableBuilder.cc.

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

◆ BuildInverseRangeTable()

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

Definition at line 259 of file G4LossTableBuilder.cc.

263{
264 size_t nCouples = rangeTable->size();
265 if(0 >= nCouples) { return; }
266
267 for (size_t i=0; i<nCouples; ++i) {
268 G4PhysicsVector* pv = (*rangeTable)[i];
269 if((pv == nullptr) || (useBM && !(*theFlag)[i])) { continue; }
270 size_t npoints = pv->GetVectorLength();
271 G4double rlow = (*pv)[0];
272 G4double rhigh = (*pv)[npoints-1];
273
274 delete (*invRangeTable)[i];
275 G4LPhysicsFreeVector* v = new G4LPhysicsFreeVector(npoints,rlow,rhigh);
276 v->SetSpline(splineFlag);
277
278 for (size_t j=0; j<npoints; ++j) {
279 G4double e = pv->Energy(j);
280 G4double r = (*pv)[j];
281 v->PutValues(j,r,e);
282 }
283 if(splineFlag) { v->FillSecondDerivatives(); }
284
285 G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v);
286 }
287}
void PutValues(std::size_t index, G4double e, G4double dataValue)
G4double Energy(std::size_t index) const

Referenced by G4TablesForExtrapolator::Initialisation().

◆ BuildRangeTable()

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

Definition at line 174 of file G4LossTableBuilder.cc.

178{
179 size_t nCouples = dedxTable->size();
180 if(0 >= nCouples) { return; }
181
182 size_t n = 100;
183 G4double del = 1.0/(G4double)n;
184
185 for (size_t i=0; i<nCouples; ++i) {
186 G4PhysicsLogVector* pv = static_cast<G4PhysicsLogVector*>((*dedxTable)[i]);
187 if((pv == nullptr) || (useBM && !(*theFlag)[i])) { continue; }
188 size_t npoints = pv->GetVectorLength();
189 size_t bin0 = 0;
190 G4double elow = pv->Energy(0);
191 G4double ehigh = pv->Energy(npoints-1);
192 G4double dedx1 = (*pv)[0];
193
194 //G4cout << "i= " << i << "npoints= " << npoints << " dedx1= "
195 //<< dedx1 << G4endl;
196
197 // protection for specific cases dedx=0
198 if(dedx1 == 0.0) {
199 for (size_t k=1; k<npoints; ++k) {
200 ++bin0;
201 elow = pv->Energy(k);
202 dedx1 = (*pv)[k];
203 if(dedx1 > 0.0) { break; }
204 }
205 npoints -= bin0;
206 }
207 //G4cout<<"New Range vector" << G4endl;
208 //G4cout<<"nbins= "<<npoints-1<<" elow= "<<elow<<" ehigh= "<<ehigh
209 // <<" bin0= " << bin0 <<G4endl;
210
211 // initialisation of a new vector
212 if(npoints < 2) { npoints = 2; }
213
214 delete (*rangeTable)[i];
216 if(0 == bin0) { v = new G4PhysicsLogVector(*pv); }
217 else { v = new G4PhysicsLogVector(elow, ehigh, npoints-1); }
218
219 // dedx is exact zero cannot build range table
220 if(2 == npoints) {
221 v->PutValue(0,1000.);
222 v->PutValue(1,2000.);
224 return;
225 }
226 v->SetSpline(splineFlag);
227
228 // assumed dedx proportional to beta
229 G4double energy1 = v->Energy(0);
230 G4double range = 2.*energy1/dedx1;
231 //G4cout << "range0= " << range << G4endl;
232 v->PutValue(0,range);
233
234 for (size_t j=1; j<npoints; ++j) {
235
236 G4double energy2 = v->Energy(j);
237 G4double de = (energy2 - energy1) * del;
238 G4double energy = energy2 + de*0.5;
239 G4double sum = 0.0;
240 //G4cout << "j= " << j << " e1= " << energy1 << " e2= " << energy2
241 // << " n= " << n << G4endl;
242 for (size_t k=0; k<n; ++k) {
243 energy -= de;
244 dedx1 = pv->Value(energy);
245 if(dedx1 > 0.0) { sum += de/dedx1; }
246 }
247 range += sum;
248 v->PutValue(j,range);
249 energy1 = energy2;
250 }
251 if(splineFlag) { v->FillSecondDerivatives(); }
253 }
254}
G4double Value(G4double theEnergy, std::size_t &lastidx) const
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 360 of file G4LossTableBuilder.cc.

365{
366 // check input
368 if(!table) { return table; }
369 if(emin >= emax) {
370 table->clearAndDestroy();
371 delete table;
372 table = nullptr;
373 return table;
374 }
376 G4int nbins = theParameters->NumberOfBinsPerDecade();
377 G4bool useMB = model->UseBaseMaterials();
378
379 // Access to materials
380 const G4ProductionCutsTable* theCoupleTable=
382 size_t numOfCouples = theCoupleTable->GetTableSize();
383
384 G4PhysicsLogVector* aVector = nullptr;
385
386 for(size_t i=0; i<numOfCouples; ++i) {
387 if ((useMB && GetFlag(i)) || (!useMB && table->GetFlag(i))) {
388
389 // create physics vector and fill it
390 auto couple = theCoupleTable->GetMaterialCutsCouple(i);
391 delete (*table)[i];
392
393 // if start from zero then change the scale
394
395 const G4Material* mat = couple->GetMaterial();
396
397 G4double tmin = std::max(emin,model->MinPrimaryEnergy(mat,part));
398 if(0.0 >= tmin) { tmin = CLHEP::eV; }
399 G4int n = nbins;
400
401 if(tmin >= emax) {
402 aVector = nullptr;
403 } else {
404 n *= (G4int)(std::log10(emax/tmin) + 0.5);
405 n = std::max(n, 3);
406 aVector = new G4PhysicsLogVector(tmin, emax, n);
407 }
408
409 if(aVector) {
410 aVector->SetSpline(spline);
411 //G4cout << part->GetParticleName() << " in " << mat->GetName()
412 // << " tmin= " << tmin << G4endl;
413 for(G4int j=0; j<=n; ++j) {
414 aVector->PutValue(j, model->Value(couple, part,
415 aVector->Energy(j)));
416 }
417 if(spline) { aVector->FillSecondDerivatives(); }
418 }
420 }
421 }
422 /*
423 G4cout << "G4LossTableBuilder::BuildTableForModel done for "
424 << part->GetParticleName() << " and "<< model->GetName()
425 << " " << table << G4endl;
426 */
427 return table;
428}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4int NumberOfBinsPerDecade() const
G4bool GetFlag(size_t idx)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:651
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
void clearAndDestroy()
G4bool GetFlag(std::size_t i) const
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)
Definition: G4VEmModel.cc:424
virtual G4double Value(const G4MaterialCutsCouple *, const G4ParticleDefinition *, G4double kineticEnergy)
Definition: G4VEmModel.cc:415
G4bool UseBaseMaterials() const
Definition: G4VEmModel.hh:750

Referenced by G4VMscModel::GetParticleChangeForMSC().

◆ GetCoupleIndexes()

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

◆ GetDensityFactors()

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

◆ GetFlag()

G4bool G4LossTableBuilder::GetFlag ( size_t  idx)

Definition at line 131 of file G4LossTableBuilder.cc.

132{
133 if(theFlag->empty()) { InitialiseBaseMaterials(); }
134 return (idx < theFlag->size()) ? (*theFlag)[idx] : false;
135}

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

◆ InitialiseBaseMaterials()

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

Definition at line 291 of file G4LossTableBuilder.cc.

292{
293 if(!isMaster) { return; }
294 const G4ProductionCutsTable* theCoupleTable=
296 size_t nCouples = theCoupleTable->GetTableSize();
297 size_t nFlags = theFlag->size();
298 if(isInitialized && nFlags == nCouples) { return; }
299
300 isInitialized = true;
301 if(0 == nFlags) {
302 theDensityFactor->reserve(nCouples);
303 theDensityIdx->reserve(nCouples);
304 theFlag->reserve(nCouples);
305 }
306 for(size_t i=0; i<nFlags; ++i) {
307 (*theFlag)[i] = (table) ? table->GetFlag(i) : true;
308 }
309 for(size_t i=nFlags; i<nCouples; ++i) {
310 G4bool yes = (table) ? table->GetFlag(i) : true;
311 theDensityFactor->push_back(1.0);
312 theDensityIdx->push_back(i);
313 theFlag->push_back(yes);
314 }
315 // use base materials
316 for(size_t i=0; i<nCouples; ++i) {
317 // base material is needed only for a couple which is not
318 // initialised and for which tables will be computed
319 auto couple = theCoupleTable->GetMaterialCutsCouple(i);
320 auto pcuts = couple->GetProductionCuts();
321 auto mat = couple->GetMaterial();
322 auto bmat = mat->GetBaseMaterial();
323
324 // base material exists - find it and check if it can be reused
325 if(bmat) {
326 for(size_t j=0; j<nCouples; ++j) {
327 if(j == i) { continue; }
328 auto bcouple = theCoupleTable->GetMaterialCutsCouple(j);
329
330 if(bcouple->GetMaterial() == bmat &&
331 bcouple->GetProductionCuts() == pcuts) {
332
333 // based couple exist in the same region
334 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
335 (*theDensityIdx)[i] = j;
336 (*theFlag)[i] = false;
337
338 // ensure that there will no double initialisation
339 (*theDensityFactor)[j] = 1.0;
340 (*theDensityIdx)[j] = j;
341 (*theFlag)[j] = true;
342 break;
343 }
344 }
345 }
346 }
347 /*
348 for(size_t i=0; i<nCouples; ++i) {
349 G4cout << "CoupleIdx= " << i << " Flag= " << theFlag[i]
350 << " TableFlag= " << table->GetFlag(i) << " "
351 << theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName()
352 << G4endl;
353 }
354 */
355}
G4ProductionCuts * GetProductionCuts() const

Referenced by BuildDEDXTable(), BuildTableForModel(), GetFlag(), G4TablesForExtrapolator::Initialisation(), G4VEmProcess::PreparePhysicsTable(), and G4VEnergyLossProcess::PreparePhysicsTable().

◆ 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}

Referenced by G4LossTableManager::ResetParameters().


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