Import Geant4 11.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2025-06-26 09:17:29 +02:00
parent 20a218bbe1
commit a499fb82e9
1941 changed files with 203285 additions and 95593 deletions
+28 -2
View File
@@ -6,12 +6,38 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2025-04-04 G.Cosmo (emutils-V11-02-21)
## 2025-06-11 V.Ivanchenko (emutils-V11-03-07)
- G4VXRayModel - updated new base class for X-ray processes
## 2025-05-25 V.Ivanchenko (emutils-V11-03-06)
- G4EmUtility, G4EmDataHandler, G4EmDataRegistry - removed minor memory leaks
at exit and improved destruction at exit
## 2025-05-12 V.Ivanchenko (emutils-V11-03-05)
- G4EmParametersMessenger - added UI command to enable/disable 5D pair
production model by muons.
## 2025-04-29 V.Ivanchenko (emutils-V11-03-04)
- G4VXRayModel - new base class
- G4OpticalParameters, G4OpticalParametersMessenger, G4LossTableManager
configure and use this new class
## 2025-04-04 G.Cosmo (emutils-V11-03-03)
- Fix in G4EmTableType header to make self-consistent.
Reported in [GitHub PR#85](https://github.com/Geant4/geant4/pull/85).
## 2025-03-27 V.Ivanchenko
## 2025-03-27 V.Ivanchenko (emutils-V11-03-02)
- G4VAtomDeexcitation - fixed problem #2650 - allowed to simulate PIXE
- G4VEnergyLossProcess - cosmetic change
## 2025-03-25 V.Ivanchenko (emutils-V11-03-01)
- G4EmParameters, G4EmParametersMessenger, G4EmUtility, G4LossTableBuilder,
G4VEnergyLossProcess - implemented a new option to enable/disable
fluctuation of energy loss per G4Region
## 2025-02-12 V.Ivanchenko (emutils-V11-03-00)
- G4VEmProcess - added call StartTracking(...) for all used models, which
is needed for models, which needs access to G4Track pointer
## 2024-10-31 V.Ivanchenko (emutils-V11-02-20)
- G4EmCalculator - fixed Coverity warning
@@ -61,6 +61,7 @@
class G4ParticleDefinition;
class G4VEmProcess;
class G4VEnergyLossProcess;
class G4EmDataRegistry;
class G4EmDataHandler
{
@@ -168,6 +169,7 @@ public:
private:
G4EmDataRegistry* fRegistry;
std::vector<G4PhysicsTable*> data;
std::vector<G4double>* fMaxXS;
std::vector<G4TwoPeaksXS*>* fXSpeaks;
@@ -176,8 +178,8 @@ private:
std::size_t tLength{0};
std::size_t eLength{0};
G4CrossSectionType fXSType{fEmNoIntegral};
G4String fName;
G4bool fUseBaseParticleTable{false};
G4String fName;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -52,6 +52,9 @@ class G4EmDataRegistry
// register a new handler
void Register(G4EmDataHandler*);
// register a new handler
void DeRegister(G4EmDataHandler*);
// hide assignment operator
G4EmDataRegistry& operator=(const G4EmDataRegistry &right) = delete;
G4EmDataRegistry(const G4EmDataRegistry&) = delete;
@@ -126,6 +126,8 @@ public:
G4double factor,
G4double energyLimit);
G4String CheckRegion(const G4String&) const;
// initialisation methods
void DefineRegParamForLoss(G4VEnergyLossProcess*) const;
void DefineRegParamForEM(G4VEmProcess*) const;
@@ -136,8 +138,6 @@ public:
private:
G4String CheckRegion(const G4String&) const;
void PrintWarning(G4ExceptionDescription& ed) const;
G4EmExtraParametersMessenger* theMessenger;
@@ -407,10 +407,14 @@ public:
// create and access saturation class
G4EmSaturation* GetEmSaturation();
// defined fluctuations per G4Region
void SetFluctuationsForRegion(const G4String& regionName, G4bool flag);
// initialisation methods
void DefineRegParamForLoss(G4VEnergyLossProcess*) const;
void DefineRegParamForEM(G4VEmProcess*) const;
void DefineRegParamForDeex(G4VAtomDeexcitation*) const;
void DefineFluctuationFlags(std::vector<G4bool>* theFluctFlags);
const G4String& GetDirLEDATA() const;
@@ -499,6 +503,7 @@ private:
G4PositronAtRestModelType fPositronium;
G4String fDirLEDATA;
std::vector<std::pair<G4String, G4bool> > fluctRegions;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -107,6 +107,7 @@ private:
G4UIcmdWithABool* mscPCmd;
G4UIcmdWithABool* pepicsCmd;
G4UIcmdWithABool* f3gCmd;
G4UIcmdWithABool* fRiGeCmd;
G4UIcmdWithADoubleAndUnit* minEnCmd;
G4UIcmdWithADoubleAndUnit* maxEnCmd;
@@ -144,6 +145,8 @@ private:
G4UIcmdWithAString* nffCmd;
G4UIcmdWithAString* ssCmd;
G4UIcmdWithAString* fluc1Cmd;
G4UIcmdWithAString* fluc2Cmd;
G4UIcmdWithAString* fluc3Cmd;
G4UIcmdWithAString* posiCmd;
G4UIcommand* dumpCmd;
@@ -78,6 +78,11 @@ public:
const G4DataVector& cuts,
const G4double emin,
const G4double emax);
// fluctuations per G4Region
static void FillFluctFlags(std::vector<std::pair<G4String, G4bool> >& reg,
std::vector<G4bool>* flags);
};
#endif
@@ -92,6 +92,8 @@ public:
static const std::vector<G4double>* GetDensityFactors();
static const std::vector<G4bool>* GetFluctuationFlags();
static G4bool GetFlag(std::size_t idx);
static G4bool GetBaseMaterialFlag();
@@ -116,6 +118,7 @@ private:
static std::vector<G4double>* theDensityFactor;
static std::vector<G4int>* theDensityIdx;
static std::vector<G4bool>* theFlag;
static std::vector<G4bool>* theFluct;
};
inline void G4LossTableBuilder::SetSplineFlag(G4bool flag)
@@ -73,6 +73,7 @@ class G4EmCorrections;
class G4LossTableBuilder;
class G4VAtomDeexcitation;
class G4VSubCutProducer;
class G4VXRayModel;
class G4LossTableManager
{
@@ -172,6 +173,10 @@ public:
void DeRegister(G4VEmFluctuationModel* p);
void Register(G4VXRayModel* p);
void DeRegister(G4VXRayModel* p);
void RegisterExtraParticle(const G4ParticleDefinition* aParticle,
G4VEnergyLossProcess* p);
@@ -296,6 +301,7 @@ private:
std::vector<G4VEmProcess*> emp_vector;
std::vector<G4VEmModel*> mod_vector;
std::vector<G4VEmFluctuationModel*> fmod_vector;
std::vector<G4VXRayModel*> xray_vector;
std::vector<G4VProcess*> p_vector;
std::map<PD,G4VEnergyLossProcess*,std::less<PD> > loss_map;
@@ -56,6 +56,7 @@
#include "G4ThreeVector.hh"
#include "G4Threading.hh"
#include <vector>
#include <memory>
class G4OpticalParametersMessenger;
class G4StateManager;
@@ -73,6 +74,12 @@ enum G4OpticalProcessIndex
kNoProcess ///< Number of processes, no selected process
};
enum G4XRayModelType
{
kCerenkovDefault = 0, // default model
kScintillationDefault, // default model
};
/// Return the name for a given optical process index
G4String G4OpticalProcessName(G4int);
@@ -177,6 +184,11 @@ class G4OpticalParameters
void SetMieVerboseLevel(G4int);
G4int GetMieVerboseLevel() const;
// active volumes
const std::vector<std::pair<G4XRayModelType, const G4String> >&
ActiveVolumes() const;
void SetActiveVolume(const G4String& name, G4XRayModelType type);
private:
G4OpticalParameters();
void Initialise();
@@ -244,6 +256,9 @@ class G4OpticalParameters
G4bool boundaryInvokeSD;
G4int boundaryVerboseLevel;
//////////////// active volumes
std::vector<std::pair<G4XRayModelType, const G4String> > xrayVolumes;
#ifdef G4MULTITHREADED
static G4Mutex opticalParametersMutex;
#endif
@@ -149,6 +149,7 @@ class G4OpticalParametersMessenger : public G4UImessenger
G4UIcmdWithAnInteger* fMieVerboseLevelCmd;
G4UIcommand* fDumpCmd;
G4UIcommand* fXRayCmd;
};
#endif // G4OpticalParametersMessenger_h
@@ -284,8 +284,10 @@ public:
void ActivateSecondaryBiasing(const G4String& region, G4double factor,
G4double energyLimit);
inline void SetLossFluctuations(G4bool val);
// obsolete method will be removed in the next major release
void SetLossFluctuations(G4bool);
// interpolation of cross section
inline void SetSpline(G4bool val);
inline void SetCrossSectionType(G4CrossSectionType val);
inline G4CrossSectionType CrossSectionType() const;
@@ -294,7 +296,7 @@ public:
void SetIonisation(G4bool val);
inline G4bool IsIonisationProcess() const;
// Redefine parameteters for stepping control
// Redefine parameteters of stepping control
void SetLinearLossLimit(G4double val);
void SetStepFunction(G4double v1, G4double v2);
void SetLowestEnergyLimit(G4double);
@@ -311,6 +313,7 @@ public:
void SetInverseRangeTable(G4PhysicsTable* p);
void SetLambdaTable(G4PhysicsTable* p);
// set properties of cross section shape
void SetTwoPeaksXS(std::vector<G4TwoPeaksXS*>*);
void SetEnergyOfCrossSectionMax(std::vector<G4double>*);
@@ -446,6 +449,7 @@ private:
const std::vector<G4int>* theDensityIdx = nullptr;
const std::vector<G4double>* theDensityFactor = nullptr;
const G4DataVector* theCuts = nullptr;
const std::vector<G4bool>* theFluctuationFlags = nullptr;
std::vector<G4double>* theEnergyOfCrossSectionMax = nullptr;
std::vector<G4TwoPeaksXS*>* fXSpeaks = nullptr;
@@ -517,8 +521,9 @@ private:
G4bool weightFlag = false;
G4bool isMaster = false;
G4bool baseMat = false;
// flags allowing define table parameters individual for the process
G4bool actLinLossLimit = false;
G4bool actLossFluc = false;
G4bool actBinning = false;
G4bool actMinKinEnergy = false;
G4bool actMaxKinEnergy = false;
@@ -859,14 +864,6 @@ G4VEnergyLossProcess::SecondaryParticle() const
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
inline void G4VEnergyLossProcess::SetLossFluctuations(G4bool val)
{
lossFluctuationFlag = val;
actLossFluc = true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
inline void G4VEnergyLossProcess::SetSpline(G4bool val)
{
spline = val;
@@ -0,0 +1,121 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// -------------------------------------------------------------------
//
// GEANT4 Class header file
//
//
// File name: G4VXRayModel
//
// Author: Vladimir Ivanchenko
//
// Creation date: 28.04.2025
//
//
// Class Description:
//
// Abstract interface to a X-Ray production model
// -------------------------------------------------------------------
//
#ifndef G4VXRayModel_h
#define G4VXRayModel_h 1
#include "globals.hh"
#include <vector>
class G4LogicalVolume;
class G4ParticleDefinition;
class G4DynamicParticle;
class G4LossTableManager;
class G4Track;
class G4Step;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class G4VXRayModel
{
public:
explicit G4VXRayModel(const G4String& nam);
G4VXRayModel(const G4VXRayModel&);
virtual ~G4VXRayModel();
// return minimal beta for Cerenkov in these volumes
G4double Initialise(std::vector<const G4LogicalVolume*>*);
virtual G4double InitialiseModel() = 0;
// check applicability and propose step limit, which may be DBL_MAX
// if these methods return "false", then sampling of X-rays not possible
G4bool StepLimit(const G4LogicalVolume*, const G4Track&,
G4double preStepBeta, G4double& limit);
virtual G4bool StepLimitForVolume(G4double& limit) = 0;
// sampling is called if StepLimit(..) returns "true"
// produced X-rays are inside vector out
// each photon has time, position, and other parameters within the step
virtual void SampleXRays(std::vector<G4Track*>& out, const G4Step&) = 0;
// for automatic documentation
virtual void ModelDescription(std::ostream& outFile) const;
const G4String& GetName() const { return pName; };
G4int GetType() const { return pTypeInt; };
// hide assignment operator
G4VXRayModel& operator=(const G4VXRayModel& right) = delete;
private:
void Register();
protected:
std::vector<const G4LogicalVolume*>* pLogicalVolumes{nullptr};
G4LossTableManager* pEmManager{nullptr};
const G4LogicalVolume* pCurrentLV{nullptr};
const G4Track* pCurrentTrack{nullptr};
G4double pBetaMin{1.0};
G4double pPreStepBeta{0.0};
G4double pMaxBetaChange{0.1};
G4int pMaxPhotons{100};
G4int pNumPhotons{0};
G4int pTypeInt{0};
G4int pVerbose{1};
G4bool isMaster{false};
const G4String pName;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
#endif
@@ -53,6 +53,7 @@ geant4_add_module(G4emutils
G4VMultipleScattering.hh
G4VPositronAtRestModel.hh
G4VSubCutProducer.hh
G4VXRayModel.hh
G4ionEffectiveCharge.hh
SOURCES
G4AngleDirect.cc
@@ -92,6 +93,7 @@ geant4_add_module(G4emutils
G4VEnergyLossProcess.cc
G4VMscModel.cc
G4VMultipleScattering.cc
G4VXRayModel.cc
G4ionEffectiveCharge.cc)
geant4_module_link_libraries(G4emutils
@@ -56,7 +56,8 @@ G4EmDataHandler::G4EmDataHandler(std::size_t n, const G4String& nam)
data.resize(n, nullptr);
fMaxXS = new std::vector<G4double>;
fXSpeaks = new std::vector<G4TwoPeaksXS*>;
G4EmDataRegistry::Instance()->Register(this);
fRegistry = G4EmDataRegistry::Instance();
fRegistry->Register(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -77,7 +78,7 @@ G4EmDataHandler::~G4EmDataHandler()
}
}
}
fRegistry->DeRegister(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -98,7 +99,9 @@ void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, std::size_t idx)
{
// update table pointer but not delete previous
if (idx < tLength) {
if (ptr != data[idx]) { data[idx] = ptr; }
if (ptr != data[idx]) {
data[idx] = ptr;
}
data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]);
} else {
G4cout << "### G4EmDataHandler::UpdateTable fail for idx=" << idx
@@ -62,7 +62,11 @@ G4EmDataRegistry::G4EmDataRegistry()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataRegistry::~G4EmDataRegistry()
{}
{
for (auto const & p : fDataHandlers) {
delete p;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -95,6 +99,20 @@ void G4EmDataRegistry::Register(G4EmDataHandler* ptr)
fDataHandlers.push_back(ptr);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4EmDataRegistry::DeRegister(G4EmDataHandler* ptr)
{
if (nullptr == ptr) { return; }
std::size_t n = fDataHandlers.size();
for (std::size_t i = 0; i < n; ++i) {
if (fDataHandlers[i] == ptr) {
fDataHandlers[i] = nullptr;
return;
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4EmDataHandler* G4EmDataRegistry::EmDataHandler(const G4String& nam)
@@ -50,6 +50,7 @@
#include "G4EmExtraParameters.hh"
#include "G4EmLowEParameters.hh"
#include "G4EmParametersMessenger.hh"
#include "G4EmUtility.hh"
#include "G4NistManager.hh"
#include "G4RegionStore.hh"
#include "G4Region.hh"
@@ -719,7 +720,7 @@ G4double G4EmParameters::MaxEnergyFor5DMuPair() const
void G4EmParameters::SetLinearLossLimit(G4double val)
{
if(IsLocked()) { return; }
if(val > 0.0 && val < 0.5) {
if(val > 0.0 && val < 1.0) {
linLossLimit = val;
} else {
G4ExceptionDescription ed;
@@ -1365,6 +1366,22 @@ const G4String& G4EmParameters::GetDirLEDATA() const
return fDirLEDATA;
}
void G4EmParameters::SetFluctuationsForRegion(const G4String& nam, G4bool flag)
{
if (IsLocked()) { return; }
G4String ss = fBParameters->CheckRegion(nam);
if (!fluctRegions.empty()) {
for (auto const& p : fluctRegions) { if (p.first == ss) { return; } }
}
fluctRegions.push_back(std::make_pair(ss, flag));
}
void G4EmParameters::DefineFluctuationFlags(std::vector<G4bool>* theFlags)
{
if (fluctRegions.empty()) { return; }
G4EmUtility::FillFluctFlags(fluctRegions, theFlags);
}
void G4EmParameters::StreamInfo(std::ostream& os) const
{
G4long prec = os.precision(5);
@@ -1417,7 +1434,7 @@ void G4EmParameters::StreamInfo(std::ostream& os) const
os << "5D gamma conversion limit for muon pair "
<< max5DEnergyForMuPair/CLHEP::GeV << " GeV\n";
}
os << "Use Ricardo-Gerardo pair production model "
os << "Use RiGe 5D e+e- pair production model by muons "
<< fUseRiGePairProductionModel << "\n";
os << "Livermore data directory "
<< fCParameters->LivermoreDataDir() << "\n";
@@ -1442,11 +1459,29 @@ void G4EmParameters::StreamInfo(std::ostream& os) const
os << "Lowest muon/hadron kinetic energy "
<<G4BestUnit(lowestMuHadEnergy,"Energy") << "\n";
os << "Use ICRU90 data " << fICRU90 << "\n";
os << "Fluctuations of dE/dx are enabled " <<lossFluctuation << "\n";
os << "Fluctuations of dE/dx are enabled " << lossFluctuation << "\n";
G4String namef = "Universal";
if(fFluct == fUrbanFluctuation) { namef = "Urban"; }
else if(fFluct == fDummyFluctuation) { namef = "Dummy"; }
os << "Type of fluctuation model for leptons and hadrons " << namef << "\n";
if (!fluctRegions.empty()) {
if (lossFluctuation) {
os << "Fluctuations of dE/dx are disabled in G4Regions: ";
} else {
os << "Fluctuations of dE/dx are enabled in G4Regions: ";
}
G4int n = 0;
for (auto const& p : fluctRegions) {
if (p.second != lossFluctuation) {
os << p.first << " ";
if (n > 0 && (n/2)*2 == n) {
os << "\n" << " ";
}
++n;
}
}
os << "\n";
}
os << "Use built-in Birks satuaration " << birks << "\n";
os << "Build CSDA range enabled " <<buildCSDARange << "\n";
os << "Use cut as a final range enabled " <<cutAsFinalRange << "\n";
@@ -217,6 +217,13 @@ G4EmParametersMessenger::G4EmParametersMessenger(G4EmParameters* ptr)
f3gCmd->AvailableForStates(G4State_PreInit);
f3gCmd->SetToBeBroadcasted(false);
fRiGeCmd = new G4UIcmdWithABool("/process/em/PairProd5D",this);
fRiGeCmd->SetGuidance("Enable/disable 5D model for e+e- pair production by muons");
fRiGeCmd->SetParameterName("ee5D",true);
fRiGeCmd->SetDefaultValue(false);
fRiGeCmd->AvailableForStates(G4State_PreInit);
fRiGeCmd->SetToBeBroadcasted(false);
minEnCmd = new G4UIcmdWithADoubleAndUnit("/process/eLoss/minKinEnergy",this);
minEnCmd->SetGuidance("Set the min kinetic energy for EM tables");
minEnCmd->SetParameterName("emin",true);
@@ -452,6 +459,18 @@ G4EmParametersMessenger::G4EmParametersMessenger(G4EmParameters* ptr)
fluc1Cmd->AvailableForStates(G4State_PreInit);
fluc1Cmd->SetToBeBroadcasted(false);
fluc2Cmd = new G4UIcmdWithAString("/process/eLoss/enableFluctForRegion",this);
fluc2Cmd->SetGuidance("Enable dEdx fluctuations for G4Region");
fluc2Cmd->SetParameterName("Fluc2",true);
fluc2Cmd->AvailableForStates(G4State_PreInit);
fluc2Cmd->SetToBeBroadcasted(false);
fluc3Cmd = new G4UIcmdWithAString("/process/eLoss/disableFluctForRegion",this);
fluc3Cmd->SetGuidance("Disable dEdx fluctuations for G4Region");
fluc3Cmd->SetParameterName("Fluc3",true);
fluc3Cmd->AvailableForStates(G4State_PreInit);
fluc3Cmd->SetToBeBroadcasted(false);
posiCmd = new G4UIcmdWithAString("/process/em/setPositronAtRestModel",this);
posiCmd->SetGuidance("Define model of positron annihilation at rest");
posiCmd->SetParameterName("Posi",true);
@@ -510,6 +529,7 @@ G4EmParametersMessenger::~G4EmParametersMessenger()
delete mudatCmd;
delete peKCmd;
delete f3gCmd;
delete fRiGeCmd;
delete mscPCmd;
delete pepicsCmd;
@@ -549,6 +569,8 @@ G4EmParametersMessenger::~G4EmParametersMessenger()
delete nffCmd;
delete ssCmd;
delete fluc1Cmd;
delete fluc2Cmd;
delete fluc3Cmd;
delete posiCmd;
delete dumpCmd;
@@ -605,6 +627,8 @@ void G4EmParametersMessenger::SetNewValue(G4UIcommand* command,
theParameters->SetPhotoeffectBelowKShell(peKCmd->GetNewBoolValue(newValue));
} else if (command == f3gCmd) {
theParameters->Set3GammaAnnihilationOnFly(f3gCmd->GetNewBoolValue(newValue));
} else if (command == fRiGeCmd) {
theParameters->SetUseRiGePairProductionModel(fRiGeCmd->GetNewBoolValue(newValue));
} else if (command == mscPCmd) {
theParameters->SetMscPositronCorrection(mscPCmd->GetNewBoolValue(newValue));
} else if (command == pepicsCmd) {
@@ -743,6 +767,10 @@ void G4EmParametersMessenger::SetNewValue(G4UIcommand* command,
if(newValue == "Dummy") { x = fDummyFluctuation; }
else if(newValue == "Urban") { x = fUrbanFluctuation; }
theParameters->SetFluctuationType(x);
} else if (command == fluc2Cmd) {
theParameters->SetFluctuationsForRegion(newValue, true);
} else if (command == fluc3Cmd) {
theParameters->SetFluctuationsForRegion(newValue, false);
} else if (command == posiCmd) {
G4PositronAtRestModelType x = fSimplePositronium;
if (newValue == "Allison") { x = fAllisonPositronium; }
@@ -288,6 +288,7 @@ G4EmUtility::FillPeaksStructure(G4PhysicsTable* p, G4LossTableBuilder* bld)
}
// case of no 1st peak in all vectors
if(!isDeep) {
for (G4int k=0; k<n; ++k) { delete (*ptr)[k]; }
delete ptr;
ptr = nullptr;
return ptr;
@@ -384,3 +385,29 @@ void G4EmUtility::InitialiseElementSelectors(G4VEmModel* mod,
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
void G4EmUtility::FillFluctFlags(std::vector<std::pair<G4String, G4bool> >& reg,
std::vector<G4bool>* flags)
{
G4RegionStore* regStore = G4RegionStore::GetInstance();
G4ProductionCutsTable* theCoupleTable=
G4ProductionCutsTable::GetProductionCutsTable();
std::size_t numOfCouples = theCoupleTable->GetTableSize();
for (std::size_t i = 0; i < numOfCouples; ++i) {
auto couple = theCoupleTable->GetMaterialCutsCouple((G4int)i);
auto mat = const_cast<G4Material*>(couple->GetMaterial());
for (auto const& r : reg) {
const G4String& rname = r.first;
G4Region* region = regStore->GetRegion(rname, false);
if (nullptr != region) {
auto couple1 = region->FindCouple(mat);
if (couple1 == couple) {
(*flags)[couple->GetIndex()] = r.second;
break;
}
}
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
@@ -68,8 +68,9 @@
G4bool G4LossTableBuilder::baseMatFlag = false;
std::vector<G4double>* G4LossTableBuilder::theDensityFactor = nullptr;
std::vector<G4int>* G4LossTableBuilder::theDensityIdx = nullptr;
std::vector<G4bool>* G4LossTableBuilder::theFlag = nullptr;
std::vector<G4int>* G4LossTableBuilder::theDensityIdx = nullptr;
std::vector<G4bool>* G4LossTableBuilder::theFlag = nullptr;
std::vector<G4bool>* G4LossTableBuilder::theFluct = nullptr;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -81,6 +82,7 @@ G4LossTableBuilder::G4LossTableBuilder(G4bool master)
theDensityFactor = new std::vector<G4double>;
theDensityIdx = new std::vector<G4int>;
theFlag = new std::vector<G4bool>;
theFluct = new std::vector<G4bool>;
}
}
@@ -92,9 +94,11 @@ G4LossTableBuilder::~G4LossTableBuilder()
delete theDensityFactor;
delete theDensityIdx;
delete theFlag;
delete theFluct;
theDensityFactor = nullptr;
theDensityIdx = nullptr;
theFlag = nullptr;
theFluct = nullptr;
}
}
@@ -114,6 +118,13 @@ const std::vector<G4double>* G4LossTableBuilder::GetDensityFactors()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
const std::vector<G4bool>* G4LossTableBuilder::GetFluctuationFlags()
{
return theFluct;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
G4bool G4LossTableBuilder::GetFlag(std::size_t idx)
{
return (idx < theFlag->size()) ? (*theFlag)[idx] : false;
@@ -304,8 +315,11 @@ void G4LossTableBuilder::InitialiseBaseMaterials(const G4PhysicsTable* table)
if(nFlags != nCouples) { isInitialized = false; }
if(isInitialized) { return; }
// reserve memory
// reserve and fill memory
theFlag->resize(nCouples, true);
theFluct->resize(nCouples, theParameters->LossFluctuation());
theParameters->DefineFluctuationFlags(theFluct);
theDensityFactor->resize(nCouples,1.0);
theDensityIdx->resize(nCouples, 0);
@@ -49,6 +49,7 @@
#include "G4VMultipleScattering.hh"
#include "G4VEmProcess.hh"
#include "G4VXRayModel.hh"
#include "G4EmParameters.hh"
#include "G4EmSaturation.hh"
@@ -59,6 +60,7 @@
#include "G4LossTableBuilder.hh"
#include "G4VAtomDeexcitation.hh"
#include "G4VSubCutProducer.hh"
#include "G4VXRayModel.hh"
#include "G4PhysicsTable.hh"
#include "G4ParticleDefinition.hh"
@@ -102,6 +104,7 @@ G4LossTableManager::~G4LossTableManager()
for (auto const & p : msc_vector) { delete p; }
for (auto const & p : emp_vector) { delete p; }
for (auto const & p : p_vector) { delete p; }
for (auto const & p : xray_vector) { delete p; }
std::size_t mod = mod_vector.size();
std::size_t fmod = fmod_vector.size();
@@ -342,6 +345,9 @@ void G4LossTableManager::DeRegister(G4VProcess* p)
void G4LossTableManager::Register(G4VEmModel* p)
{
if (nullptr == p) { return; }
std::size_t n = mod_vector.size();
for (std::size_t i=0; i<n; ++i) { if (mod_vector[i] == p) { return; } }
mod_vector.push_back(p);
if(verbose > 1) {
G4cout << "G4LossTableManager::Register G4VEmModel : "
@@ -353,7 +359,6 @@ void G4LossTableManager::Register(G4VEmModel* p)
void G4LossTableManager::DeRegister(G4VEmModel* p)
{
//G4cout << "G4LossTableManager::DeRegister G4VEmModel : " << p << G4endl;
std::size_t n = mod_vector.size();
for (std::size_t i=0; i<n; ++i) {
if(mod_vector[i] == p) {
@@ -367,6 +372,9 @@ void G4LossTableManager::DeRegister(G4VEmModel* p)
void G4LossTableManager::Register(G4VEmFluctuationModel* p)
{
if (nullptr == p) { return; }
std::size_t n = fmod_vector.size();
for (std::size_t i=0; i<n; ++i) { if (fmod_vector[i] == p) { return; } }
fmod_vector.push_back(p);
if(verbose > 1) {
G4cout << "G4LossTableManager::Register G4VEmFluctuationModel : "
@@ -380,7 +388,37 @@ void G4LossTableManager::DeRegister(G4VEmFluctuationModel* p)
{
std::size_t n = fmod_vector.size();
for (std::size_t i=0; i<n; ++i) {
if(fmod_vector[i] == p) { fmod_vector[i] = nullptr; }
if(fmod_vector[i] == p) {
fmod_vector[i] = nullptr;
break;
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
void G4LossTableManager::Register(G4VXRayModel* p)
{
if (nullptr == p) { return; }
std::size_t n = xray_vector.size();
for (std::size_t i=0; i<n; ++i) { if (xray_vector[i] == p) { return; } }
xray_vector.push_back(p);
if (verbose > 1) {
G4cout << "G4LossTableManager::Register G4VXRayModel : "
<< p->GetName() << " " << xray_vector.size() << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
void G4LossTableManager::DeRegister(G4VXRayModel* p)
{
std::size_t n = xray_vector.size();
for (std::size_t i=0; i<n; ++i) {
if (xray_vector[i] == p) {
xray_vector[i] = nullptr;
break;
}
}
}
@@ -447,8 +485,10 @@ G4LossTableManager::PreparePhysicsTable(const G4ParticleDefinition* particle,
}
// start initialisation for the first run
if( -1 == run ) {
if (nullptr != emConfigurator) { emConfigurator->PrepareModels(particle, p); }
if ( -1 == run ) {
if (nullptr != emConfigurator) {
emConfigurator->PrepareModels(particle, p);
}
// initialise particles for given process
for (G4int j=0; j<n_loss; ++j) {
@@ -501,7 +541,9 @@ G4LossTableManager::PreparePhysicsTable(const G4ParticleDefinition* particle,
// start initialisation for the first run
if ( -1 == run ) {
if (nullptr != emConfigurator) { emConfigurator->PrepareModels(particle, p); }
if (nullptr != emConfigurator) {
emConfigurator->PrepareModels(particle, p);
}
}
ResetParameters();
@@ -470,6 +470,22 @@ G4int G4OpticalParameters::GetMieVerboseLevel() const
return mieVerboseLevel;
}
const std::vector<std::pair<G4XRayModelType, const G4String> >&
G4OpticalParameters::ActiveVolumes() const
{
return xrayVolumes;
}
void G4OpticalParameters::SetActiveVolume(const G4String& lvname,
G4XRayModelType type)
{
if(IsLocked()) {
return;
}
xrayVolumes.push_back(std::make_pair(type, lvname));
}
void G4OpticalParameters::PrintWarning(G4ExceptionDescription& ed) const
{
G4Exception("G4EmParameters", "Optical0020", JustWarning, ed);
@@ -111,6 +111,18 @@ G4OpticalParametersMessenger::G4OpticalParametersMessenger(
fDumpCmd = new G4UIcommand("/process/optical/printParameters", this);
fDumpCmd->SetGuidance("Print all optical parameters.");
fDumpCmd->SetToBeBroadcasted(false);
fXRayCmd = new G4UIcommand("/process/optical/XRayModel", this);
fXRayCmd->SetGuidance("Add XRay model per G4LogicalVolume.");
fXRayCmd->SetGuidance(" lvName : G4LogicalVolume name");
fXRayCmd->SetGuidance(" xrayType : X-Ray model type");
fXRayCmd->AvailableForStates(G4State_PreInit);
fXRayCmd->SetToBeBroadcasted(false);
auto lvName = new G4UIparameter("lvName",'s',false);
fXRayCmd->SetParameter(lvName);
auto xrayT = new G4UIparameter("xrayT",'s',false);
fXRayCmd->SetParameter(xrayT);
// Cerenkov ////////////////////
fCerenkovMaxPhotonsCmd =
@@ -291,6 +303,7 @@ G4OpticalParametersMessenger::~G4OpticalParametersMessenger()
delete fActivateProcessCmd;
delete fVerboseCmd;
delete fDumpCmd;
delete fXRayCmd;
delete fCerenkovMaxPhotonsCmd;
delete fCerenkovMaxBetaChangeCmd;
delete fCerenkovStackPhotonsCmd;
@@ -329,6 +342,31 @@ void G4OpticalParametersMessenger::SetNewValue(G4UIcommand* command,
G4bool value = G4UIcommand::ConvertToBool(flag);
params->SetProcessActivation(pn, value);
}
else if(command == fXRayCmd)
{
std::istringstream is(newValue.data());
G4String lv;
G4String sss;
is >> lv >> sss;
G4XRayModelType type;
if (sss == "CerenkovDefault")
{
type = kCerenkovDefault;
}
else if (sss == "ScintillationDefault")
{
type = kScintillationDefault;
}
else
{
G4cout << "G4OpticalParametersMessenger::SetNewValue: "
<< " fail for /process/optical/XRayModel \n"
<< " type " << sss << " is unknown, no model assigned."
<< G4endl;
return;
}
params->SetActiveVolume(lv, type);
}
else if(command == fVerboseCmd)
{
params->SetVerboseLevel(fVerboseCmd->GetNewIntValue(newValue));
@@ -111,8 +111,7 @@ G4VEmProcess::G4VEmProcess(const G4String& name, G4ProcessType type):
G4VEmProcess::~G4VEmProcess()
{
if(isTheMaster) {
delete theData;
if (isTheMaster) {
delete theEnergyOfCrossSectionMax;
}
delete modelManager;
@@ -353,6 +352,10 @@ void G4VEmProcess::StartTracking(G4Track* track)
biasManager->ResetForcedInteraction();
}
}
for (G4int i=0; i<numberOfModels; ++i) {
auto ptr = GetModelByIndex(i);
ptr->StartTracking(track);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -369,6 +372,9 @@ G4double G4VEmProcess::PostStepGetPhysicalInteractionLength(
preStepKinEnergy = track.GetKineticEnergy();
const G4double scaledEnergy = preStepKinEnergy*massRatio;
SelectModel(scaledEnergy, currentCoupleIndex);
// In models applied to ions the dynamic charge is needed
if (isIon) { currentModel->ChargeSquareRatio(track); }
/*
G4cout << "PostStepGetPhysicalInteractionLength: idx= " << currentCoupleIndex
<< " couple: " << currentCouple << G4endl;
@@ -128,6 +128,7 @@ G4VEnergyLossProcess::G4VEnergyLossProcess(const G4String& name,
G4LossTableBuilder* bld = lManager->GetTableBuilder();
theDensityFactor = bld->GetDensityFactors();
theDensityIdx = bld->GetCoupleIndexes();
theFluctuationFlags = bld->GetFluctuationFlags();
scTracks.reserve(10);
secParticles.reserve(12);
@@ -139,7 +140,6 @@ G4VEnergyLossProcess::G4VEnergyLossProcess(const G4String& name,
G4VEnergyLossProcess::~G4VEnergyLossProcess()
{
if (isMaster) {
if(nullptr == baseParticle) { delete theData; }
delete theEnergyOfCrossSectionMax;
if(nullptr != fXSpeaks) {
for(auto const & v : *fXSpeaks) { delete v; }
@@ -227,7 +227,7 @@ G4VEnergyLossProcess::PreparePhysicsTable(const G4ParticleDefinition& part)
InitialiseEnergyLossProcess(particle, baseParticle);
// parameters of the process
if(!actLossFluc) { lossFluctuationFlag = theParameters->LossFluctuation(); }
lossFluctuationFlag = theParameters->LossFluctuation();
useCutAsFinalRange = theParameters->UseCutAsFinalRange();
if(!actMinKinEnergy) { minKinEnergy = theParameters->MinKinEnergy(); }
if(!actMaxKinEnergy) { maxKinEnergy = theParameters->MaxKinEnergy(); }
@@ -310,13 +310,6 @@ G4VEnergyLossProcess::PreparePhysicsTable(const G4ParticleDefinition& part)
if(isIonisation) {
subcutProducer = lManager->SubCutProducer();
}
if(1 == nSCoffRegions) {
if((*scoffRegions)[0]->GetName() == "DefaultRegionForTheWorld") {
delete scoffRegions;
scoffRegions = nullptr;
nSCoffRegions = 0;
}
}
if(1 < verboseLevel) {
G4cout << "G4VEnergyLossProcess::PrepearPhysicsTable() is done "
@@ -809,7 +802,7 @@ G4VParticleChange* G4VEnergyLossProcess::AlongStepDoIt(const G4Track& track,
if (useDeexcitation) {
atomDeexcitation->AlongStepDeexcitation(scTracks, step,
eloss, (G4int)currentCoupleIndex);
if(scTracks.size() > 0) { FillSecondariesAlongStep(weight); }
if (!scTracks.empty()) { FillSecondariesAlongStep(weight); }
eloss = std::max(eloss, 0.0);
}
fParticleChange.SetProposedKineticEnergy(0.0);
@@ -871,7 +864,7 @@ G4VParticleChange* G4VEnergyLossProcess::AlongStepDoIt(const G4Track& track,
if(eloss >= preStepKinEnergy) {
eloss = preStepKinEnergy;
} else if (lossFluctuationFlag) {
} else if ((*theFluctuationFlags)[currentCoupleIndex]) {
const G4double tmax = currentModel->MaxSecondaryKinEnergy(dynParticle);
const G4double tcut = std::min(cut, tmax);
G4VEmFluctuationModel* fluc = currentModel->GetModelOfFluctuations();
@@ -1423,7 +1416,15 @@ void G4VEnergyLossProcess::SetIonisation(G4bool val)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void G4VEnergyLossProcess::SetLinearLossLimit(G4double val)
void G4VEnergyLossProcess::SetLossFluctuations(G4bool)
{
G4cout << "### G4VEnergyLossProcess::SetLossFluctuations has no effect and "
<< "will be removed for the next major release" << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void G4VEnergyLossProcess::SetLinearLossLimit(G4double val)
{
if(0.0 < val && val < 1.0) {
linLossLimit = val;
@@ -1435,11 +1436,11 @@ void G4VEnergyLossProcess::SetIonisation(G4bool val)
void G4VEnergyLossProcess::SetStepFunction(G4double v1, G4double v2)
{
if(0.0 < v1 && 0.0 < v2) {
if(0.0 < v1 && 1.0 >= v1 && 0.0 < v2) {
dRoverRange = std::min(1.0, v1);
finalRange = std::min(v2, 1.e+50);
} else {
PrintWarning("SetStepFunctionV1", v1);
PrintWarning("SetStepFunctionV1", v1);
PrintWarning("SetStepFunctionV2", v2);
}
}
@@ -0,0 +1,124 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// -------------------------------------------------------------------
//
// GEANT4 Class file
//
// File name: G4VXRayModel
//
// Author: Vladimir Ivanchenko
//
// Creation date: 28.04.2025
//
// -------------------------------------------------------------------
//
#include "G4VXRayModel.hh"
#include "G4LogicalVolume.hh"
#include "G4LossTableManager.hh"
#include "G4ParticleDefinition.hh"
#include "G4DynamicParticle.hh"
#include "G4OpticalParameters.hh"
#include "G4Track.hh"
#include <iostream>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VXRayModel::G4VXRayModel(const G4String& nam)
: pName(nam)
{
Register();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VXRayModel::G4VXRayModel(const G4VXRayModel& right)
: pLogicalVolumes(nullptr),
pCurrentLV(nullptr),
pCurrentTrack(nullptr),
pBetaMin(1.0),
pPreStepBeta(0.0),
pMaxBetaChange(0.1),
pMaxPhotons(100),
pTypeInt(0),
pVerbose(1),
isMaster(false),
pName(right.pName)
{
Register();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VXRayModel::~G4VXRayModel()
{
pEmManager->DeRegister(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4VXRayModel::Register()
{
pEmManager = G4LossTableManager::Instance();
pEmManager->Register(this);
isMaster = pEmManager->IsMaster();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double G4VXRayModel::Initialise(std::vector<const G4LogicalVolume*>* ptr)
{
pLogicalVolumes = ptr;
auto params = G4OpticalParameters::Instance();
pMaxBetaChange = params->GetCerenkovMaxBetaChange();
pMaxPhotons = params->GetCerenkovMaxPhotonsPerStep();
pVerbose = params->GetCerenkovVerboseLevel();
pBetaMin = InitialiseModel();
return pBetaMin;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool G4VXRayModel::StepLimit(const G4LogicalVolume* lv, const G4Track& track,
G4double preStepBeta, G4double& limit)
{
if (preStepBeta <= pBetaMin) { return false; }
pCurrentLV = lv;
pCurrentTrack = &track;
pPreStepBeta = preStepBeta;
return StepLimitForVolume(limit);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4VXRayModel::ModelDescription(std::ostream& outFile) const
{
outFile << "The description for this model has not been written yet.\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......