69std::vector<G4double>* G4LossTableBuilder::theDensityFactor =
nullptr;
70std::vector<G4int>* G4LossTableBuilder::theDensityIdx =
nullptr;
71std::vector<G4bool>* G4LossTableBuilder::theFlag =
nullptr;
81 if(
nullptr == theFlag) {
84 if(
nullptr == theFlag) {
88 ed <<
"Initialisation called from a worker thread ";
92 theDensityFactor =
new std::vector<G4double>;
93 theDensityIdx =
new std::vector<G4int>;
94 theFlag =
new std::vector<G4bool>;
107 delete theDensityFactor;
108 delete theDensityIdx;
110 theDensityFactor =
nullptr;
111 theDensityIdx =
nullptr;
120 return theDensityIdx;
127 return theDensityFactor;
135 return (idx < theFlag->size()) ? (*theFlag)[idx] :
false;
150 const std::vector<G4PhysicsTable*>& list)
153 std::size_t n_processes = list.size();
154 if(1 >= n_processes) {
return; }
156 std::size_t nCouples = dedxTable->size();
159 if(0 >= nCouples) {
return; }
161 for (std::size_t i=0; i<nCouples; ++i) {
163 if(pv0 ==
nullptr) {
continue; }
166 for (std::size_t j=0; j<npoints; ++j) {
168 for (std::size_t k=0; k<n_processes; ++k) {
174 if(splineFlag) { pv->FillSecondDerivatives(); }
189 const std::size_t nCouples = dedxTable->size();
190 if(0 >= nCouples) {
return; }
192 const std::size_t n = 100;
195 for (std::size_t i=0; i<nCouples; ++i) {
197 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
199 std::size_t bin0 = 0;
201 G4double ehigh = pv->Energy(npoints-1);
209 for (std::size_t k=1; k<npoints; ++k) {
211 elow = pv->Energy(k);
213 if(dedx1 > 0.0) {
break; }
222 if(npoints < 3) { npoints = 3; }
224 delete (*rangeTable)[i];
235 for (std::size_t j=1; j<npoints; ++j) {
238 G4double de = (energy2 - energy1) * del;
241 std::size_t idx = j - 1;
244 for (std::size_t k=0; k<n; ++k) {
246 dedx1 = pv->Value(energy, idx);
247 if(dedx1 > 0.0) { sum += de/dedx1; }
267 std::size_t nCouples = rangeTable->size();
268 if(0 >= nCouples) {
return; }
270 for (std::size_t i=0; i<nCouples; ++i) {
272 if((pv ==
nullptr) || (isBaseMatActive && !(*theFlag)[i])) {
continue; }
275 delete (*invRangeTable)[i];
278 for (std::size_t j=0; j<npoints; ++j) {
283 if(splineFlag) { v->FillSecondDerivatives(); }
295 if(!isMaster) {
return; }
299 std::size_t nFlags = theFlag->size();
306 if(isBaseMatActive && !baseMatFlag) {
310 isInitialized =
false;
316 if(nFlags != nCouples) { isInitialized =
false; }
317 if(isInitialized) {
return; }
320 theFlag->resize(nCouples,
true);
321 if(
nullptr == table) {
return; }
324 theDensityFactor->resize(nCouples,1.0);
325 theDensityIdx->resize(nCouples);
330 (*theFlag)[i] = table->
GetFlag(i);
331 if(baseMatFlag) { (*theDensityIdx)[i] = i; }
333 isInitialized =
true;
341 auto mat = couple->GetMaterial();
342 auto bmat = mat->GetBaseMaterial();
345 if(
nullptr != bmat) {
347 if(j == i) {
continue; }
350 if(bcouple->GetMaterial() == bmat &&
351 bcouple->GetProductionCuts() == pcuts) {
354 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity();
355 (*theDensityIdx)[i] = j;
356 (*theFlag)[i] =
false;
359 (*theDensityFactor)[j] = 1.0;
360 (*theDensityIdx)[j] = j;
361 (*theFlag)[j] =
true;
392 if(
nullptr == table) {
return table; }
405 std::size_t numOfCouples = theCoupleTable->
GetTableSize();
421 if(0.0 >= tmin) { tmin = CLHEP::eV; }
427 n *=
G4lrint(std::log10(emax/tmin));
432 if(
nullptr != aVector) {
435 for(
G4int j=0; j<=n; ++j) {
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
#define G4MUTEXLOCK(mutex)
#define G4MUTEXUNLOCK(mutex)
static G4EmParameters * Instance()
G4int NumberOfBinsPerDecade() 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)