69std::vector<G4double>* G4LossTableBuilder::theDensityFactor =
nullptr;
70std::vector<G4int>* G4LossTableBuilder::theDensityIdx =
nullptr;
71std::vector<G4bool>* G4LossTableBuilder::theFlag =
nullptr;
78 if (
nullptr == theFlag) {
81 ed <<
"The table builder is instantiated in a worker thread ";
82 G4Exception(
"G4LossTableBuilder::G4LossTableBuilder ",
"em0001",
85 theDensityFactor =
new std::vector<G4double>;
86 theDensityIdx =
new std::vector<G4int>;
87 theFlag =
new std::vector<G4bool>;
97 delete theDensityFactor;
100 theDensityFactor =
nullptr;
101 theDensityIdx =
nullptr;
110 return theDensityIdx;
117 return theDensityFactor;
125 return (idx < theFlag->size()) ? (*theFlag)[idx] :
false;
140 const std::vector<G4PhysicsTable*>& list)
143 std::size_t n_processes = list.size();
144 if(1 >= n_processes) {
return; }
146 std::size_t nCouples = dedxTable->size();
149 if(0 >= nCouples) {
return; }
151 for (std::size_t i=0; i<nCouples; ++i) {
153 if(pv0 ==
nullptr) {
continue; }
156 for (std::size_t j=0; j<npoints; ++j) {
158 for (std::size_t k=0; k<n_processes; ++k) {
162 pv->PutValue(j, dedx);
164 if(splineFlag) { pv->FillSecondDerivatives(); }
179 const std::size_t nCouples = dedxTable->size();
180 if(0 >= nCouples) {
return; }
182 const std::size_t n = 100;
185 for (std::size_t i=0; i<nCouples; ++i) {
187 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
189 std::size_t bin0 = 0;
191 G4double ehigh = pv->Energy(npoints-1);
196 for (std::size_t k=1; k<npoints; ++k) {
198 elow = pv->Energy(k);
200 if(dedx1 > 0.0) {
break; }
206 if(npoints < 3) { npoints = 3; }
208 delete (*rangeTable)[i];
224 for (std::size_t j=1; j<npoints; ++j) {
227 G4double de = (energy2 - energy1) * del;
230 std::size_t idx = j - 1;
231 for (std::size_t k=0; k<n; ++k) {
233 dedx1 = pv->Value(energy, idx);
234 if(dedx1 > 0.0) { sum += de/dedx1; }
259 std::size_t nCouples = rangeTable->size();
260 if(0 >= nCouples) {
return; }
262 for (std::size_t i=0; i<nCouples; ++i) {
264 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
267 delete (*invRangeTable)[i];
270 for (std::size_t j=0; j<npoints; ++j) {
275 if (splineFlag) { v->FillSecondDerivatives(); }
288 if(!isInitializer) {
return; }
292 std::size_t nFlags = theFlag->size();
299 if(isBaseMatActive && !baseMatFlag) {
303 isInitialized =
false;
309 if(nFlags != nCouples) { isInitialized =
false; }
310 if(isInitialized) {
return; }
313 theFlag->resize(nCouples,
true);
314 if(
nullptr == table) {
return; }
317 theDensityFactor->resize(nCouples,1.0);
318 theDensityIdx->resize(nCouples);
323 (*theFlag)[i] = table->
GetFlag(i);
324 if(baseMatFlag) { (*theDensityIdx)[i] = i; }
326 isInitialized =
true;
334 auto mat = couple->GetMaterial();
335 auto bmat = mat->GetBaseMaterial();
338 if(
nullptr != bmat) {
340 if(j == i) {
continue; }
343 if(bcouple->GetMaterial() == bmat &&
344 bcouple->GetProductionCuts() == pcuts) {
347 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
348 (*theDensityIdx)[i] = j;
349 (*theFlag)[i] =
false;
352 (*theDensityFactor)[j] = 1.0;
353 (*theDensityIdx)[j] = j;
354 (*theFlag)[j] =
true;
385 if(
nullptr == table) {
return table; }
398 std::size_t numOfCouples = theCoupleTable->
GetTableSize();
414 if(0.0 >= tmin) { tmin = CLHEP::eV; }
420 n *=
G4lrint(std::log10(emax/tmin));
425 if(
nullptr != aVector) {
428 for(
G4int j=0; j<=n; ++j) {
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
static G4EmParameters * Instance()
G4int NumberOfBinsPerDecade() const
G4int NumberForFreeVector() const
G4bool GetBaseMaterialFlag()
void BuildRangeTable(const G4PhysicsTable *dedxTable, G4PhysicsTable *rangeTable)
void BuildDEDXTable(G4PhysicsTable *dedxTable, const std::vector< G4PhysicsTable * > &)
const std::vector< G4double > * GetDensityFactors() const
const std::vector< G4int > * GetCoupleIndexes() const
void InitialiseBaseMaterials(const G4PhysicsTable *table=nullptr)
G4PhysicsTable * BuildTableForModel(G4PhysicsTable *table, G4VEmModel *model, const G4ParticleDefinition *, G4double emin, G4double emax, G4bool spline)
G4bool GetFlag(size_t idx)
G4LossTableBuilder(G4bool master=true)
void BuildInverseRangeTable(const G4PhysicsTable *rangeTable, G4PhysicsTable *invRangeTable)
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)
G4bool GetFlag(std::size_t i) const
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)