69G4bool G4LossTableBuilder::baseMatFlag =
false;
70std::vector<G4double>* G4LossTableBuilder::theDensityFactor =
nullptr;
71std::vector<G4int>* G4LossTableBuilder::theDensityIdx =
nullptr;
72std::vector<G4bool>* G4LossTableBuilder::theFlag =
nullptr;
73std::vector<G4bool>* G4LossTableBuilder::theFluct =
nullptr;
78 : isInitializer(master)
81 if (
nullptr == theFlag) {
82 theDensityFactor =
new std::vector<G4double>;
83 theDensityIdx =
new std::vector<G4int>;
84 theFlag =
new std::vector<G4bool>;
85 theFluct =
new std::vector<G4bool>;
94 delete theDensityFactor;
98 theDensityFactor =
nullptr;
99 theDensityIdx =
nullptr;
109 return theDensityIdx;
116 return theDensityFactor;
130 return (idx < theFlag->size()) ? (*theFlag)[idx] :
false;
144 const std::vector<G4PhysicsTable*>& list)
147 std::size_t n_processes = list.size();
148 if(1 >= n_processes) {
return; }
150 std::size_t nCouples = dedxTable->size();
153 if(0 >= nCouples) {
return; }
155 for (std::size_t i=0; i<nCouples; ++i) {
158 if(pv0 ==
nullptr) {
continue; }
161 for (std::size_t j=0; j<npoints; ++j) {
163 for (std::size_t k=0; k<n_processes; ++k) {
168 pv->PutValue(j, dedx);
170 if(splineFlag) { pv->FillSecondDerivatives(); }
185 const std::size_t nCouples = dedxTable->size();
186 if(0 >= nCouples) {
return; }
188 const std::size_t n = 100;
191 for (std::size_t i=0; i<nCouples; ++i) {
193 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
195 std::size_t bin0 = 0;
197 G4double ehigh = pv->Energy(npoints-1);
202 for (std::size_t k=1; k<npoints; ++k) {
204 elow = pv->Energy(k);
206 if(dedx1 > 0.0) {
break; }
212 if(npoints < 3) { npoints = 3; }
214 delete (*rangeTable)[i];
230 for (std::size_t j=1; j<npoints; ++j) {
233 G4double de = (energy2 - energy1) * del;
236 std::size_t idx = j - 1;
237 for (std::size_t k=0; k<n; ++k) {
239 dedx1 = pv->Value(energy, idx);
240 if(dedx1 > 0.0) { sum += de/dedx1; }
265 std::size_t nCouples = rangeTable->size();
266 if(0 >= nCouples) {
return; }
268 for (std::size_t i=0; i<nCouples; ++i) {
270 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
273 delete (*invRangeTable)[i];
276 for (std::size_t j=0; j<npoints; ++j) {
281 if (splineFlag) { v->FillSecondDerivatives(); }
282 v->EnableLogBinSearch(theParameters->NumberForFreeVector());
294 if(!isInitializer) {
return; }
298 std::size_t nFlags = theFlag->size();
305 if(isBaseMatActive && !baseMatFlag) {
309 isInitialized =
false;
315 if(nFlags != nCouples) { isInitialized =
false; }
316 if(isInitialized) {
return; }
319 theFlag->resize(nCouples,
true);
320 theFluct->resize(nCouples, theParameters->LossFluctuation());
321 theParameters->DefineFluctuationFlags(theFluct);
323 theDensityFactor->resize(nCouples,1.0);
324 theDensityIdx->resize(nCouples, 0);
328 (*theFlag)[i] = (
nullptr == table) ?
true : table->GetFlag(i);
329 (*theDensityIdx)[i] = i;
331 isInitialized =
true;
332 if (!baseMatFlag) {
return; }
340 auto mat = couple->GetMaterial();
341 auto bmat = mat->GetBaseMaterial();
344 if(
nullptr != bmat) {
346 if(j == i) {
continue; }
349 if(bcouple->GetMaterial() == bmat &&
350 bcouple->GetProductionCuts() == pcuts) {
353 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
354 (*theDensityIdx)[i] = j;
355 (*theFlag)[i] =
false;
358 (*theDensityFactor)[j] = 1.0;
359 (*theDensityIdx)[j] = j;
360 (*theFlag)[j] =
true;
379 if (
nullptr == table) {
return table; }
380 if (aTable !=
nullptr && aTable != table) {
386 G4int nbins = theParameters->NumberOfBinsPerDecade();
391 std::size_t numOfCouples = theCoupleTable->
GetTableSize();
401 if (table->GetFlag(i)) {
411 if(0.0 >= tmin) { tmin = CLHEP::eV; }
417 n *=
G4lrint(std::log10(emax/tmin));
422 if(
nullptr != aVector) {
425 for(
G4int j=0; j<=n; ++j) {
static G4EmParameters * Instance()
static G4bool GetBaseMaterialFlag()
void BuildRangeTable(const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable)
static const std::vector< G4double > * GetDensityFactors()
void BuildDEDXTable(G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
static const std::vector< G4bool > * GetFluctuationFlags()
void InitialiseBaseMaterials(const G4PhysicsTable *table=nullptr)
G4PhysicsTable * BuildTableForModel(G4PhysicsTable *table, G4VEmModel *model, const G4ParticleDefinition *, G4double emin, G4double emax, G4bool spline)
static G4bool GetFlag(std::size_t idx)
static const std::vector< G4int > * GetCoupleIndexes()
void BuildInverseRangeTable(const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable)
G4LossTableBuilder(G4bool master)
const G4Material * GetMaterial() const
G4ProductionCuts * GetProductionCuts() const
const G4Material * GetBaseMaterial() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
static G4PhysicsTable * PreparePhysicsTable(G4PhysicsTable *physTable)
static void SetPhysicsVector(G4PhysicsTable *physTable, std::size_t idx, G4PhysicsVector *vec)
void PutValue(const std::size_t index, const G4double value)
G4double Energy(const std::size_t index) const
std::size_t GetVectorLength() const
void FillSecondDerivatives(const G4SplineType=G4SplineType::Base, const G4double dir1=0.0, const G4double dir2=0.0)
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)