79static const char* G4Hadronic_Random_File = std::getenv(
"G4HADRONIC_RANDOM_FILE");
105 delete theCrossSectionDataStore;
108void G4HadronicProcess::InitialiseLocal() {
111 theInteraction =
nullptr;
115 theInitialNumberOfInteractionLength = 0.0;
118 nMatWarn = nKaonWarn = 0;
119 useIntegralXS =
true;
120 theLastCrossSection = 0.0;
123 G4HadronicProcess_debug_flag =
false;
124 levelsSetByProcess =
false;
127 epCheckLevels.second =
DBL_MAX;
128 GetEnergyMomentumCheckEnvvars();
131void G4HadronicProcess::GetEnergyMomentumCheckEnvvars() {
132 if ( std::getenv(
"G4Hadronic_epReportLevel") ) {
133 epReportLevel = std::strtol(std::getenv(
"G4Hadronic_epReportLevel"),0,10);
135 if ( std::getenv(
"G4Hadronic_epCheckRelativeLevel") ) {
136 epCheckLevels.first = std::strtod(std::getenv(
"G4Hadronic_epCheckRelativeLevel"),0);
138 if ( std::getenv(
"G4Hadronic_epCheckAbsoluteLevel") ) {
139 epCheckLevels.second = std::strtod(std::getenv(
"G4Hadronic_epCheckAbsoluteLevel"),0);
157 static const G4int nmax = 5;
158 if(nMatWarn < nmax) {
162 <<
" because no material defined \n"
163 <<
" Please, specify material pointer or define simple material"
165 G4Exception(
"G4HadronicProcess::GetElementCrossSection",
"had066",
170 std::max(theCrossSectionDataStore->
GetCrossSection(part, elm, mat),0.0);
175 if(std::getenv(
"G4HadronicProcess_debug")) {
176 G4HadronicProcess_debug_flag =
true;
193 theLastCrossSection = aScaleFactor*theCrossSectionDataStore
195 G4double res = (theLastCrossSection>0.0) ? 1.0/theLastCrossSection :
DBL_MAX;
228 theCrossSectionDataStore->
SampleZandA(aParticle,aMaterial,targetNucleus);
238 ed <<
"G4HadronicProcess: track in unusable state - "
240 ed <<
"G4HadronicProcess: returning unchanged track " <<
G4endl;
252 aMaterial, anElement);
253 if(!theInteraction) {
255 ed <<
"Target element "<<anElement->
GetName()<<
" Z= "
258 DumpState(aTrack,
"ChooseHadronicInteraction",ed);
259 ed <<
" No HadronicInteraction found out" <<
G4endl;
265 G4int reentryCount = 0;
279 if (G4Hadronic_Random_File) {
291 ed <<
"Target element "<<anElement->
GetName()<<
" Z= "
295 ed <<
" ApplyYourself failed" <<
G4endl;
303 if(reentryCount>100) {
306 ed <<
"Target element "<<anElement->
GetName()<<
" Z= "
310 ed <<
" ApplyYourself does not completed after 100 attempts" <<
G4endl;
324 for (
G4int i = 0; i < nSec; ++i ) {
361 outFile <<
"The description for this process has not been written yet.\n";
365G4double G4HadronicProcess::XBiasSurvivalProbability()
369 G4double realProbability = 1-
G4Exp(-nLTraversed/aScaleFactor);
370 G4double result = (biasedProbability-realProbability)/biasedProbability;
374G4double G4HadronicProcess::XBiasSecondaryWeight()
378 1./aScaleFactor*
G4Exp(-nLTraversed/aScaleFactor*(1-1./aScaleFactor));
396 }
else if(0.0 == efinal) {
419 idxIC = -1 == idx ? -2 : idx;
425 for (
G4int i = 0; i < nSec; ++i) {
437 const G4double delta_mass_lim = 1.0*CLHEP::keV;
438 const G4double delta_ekin = 0.001*CLHEP::eV;
439 if(std::abs(dmass - mass) > delta_mass_lim) {
441 if(G4HadronicProcess_debug_flag) {
445 <<
" Target Z= " << targetNucleus.
GetZ_asInt() <<
" A= "
449 <<
" EkinNew(MeV)= " << e
450 <<
" DeltaMass(MeV)= " << dmass - mass <<
G4endl;
469 if (G4HadronicProcess_debug_flag) {
473 DumpState(aT,
"Secondary has zero energy",ed);
476 G4Exception(
"G4HadronicProcess::FillResults",
"had011",
494 ed <<
" Wrong biasing factor " << aScale <<
" for " <<
GetProcessName();
495 G4Exception(
"G4HadronicProcess::BiasCrossSectionByFactor",
"had010",
498 aScaleFactor = aScale;
531 for (
G4int i = 0; i < nSec; i++) {
536 if ( std::abs(mass_pdg - mass_dyn) > 0.1*mass_pdg + 1.*MeV ) {
545 desc <<
"Warning: Secondary with off-shell dynamic mass detected: "
548 <<
", PDG mass: " << mass_pdg <<
", dynamic mass: "
551 :
"re-sample the interaction") <<
G4endl
557 <<
", target nucleus (" << aNucleus.
GetZ_asInt() <<
", "
559 G4Exception(
"G4HadronicProcess:CheckResult()",
"had012",
567 std::pair<G4double, G4double> checkLevels =
569 if (std::abs(deltaE) > checkLevels.second &&
575 desc <<
"Warning: Bad energy non-conservation detected, will "
577 :
"re-sample the interaction") <<
G4endl
583 <<
", target nucleus (" << aNucleus.
GetZ_asInt() <<
", "
585 <<
" E(initial - final) = " << deltaE <<
" MeV." <<
G4endl;
586 G4Exception(
"G4HadronicProcess:CheckResult()",
"had012",
601 + nICelectrons*CLHEP::electron_mass_c2);
607 G4int initial_A = target_A + track_A;
608 G4int initial_Z = target_Z + track_Z - nICelectrons;
614 G4int final_A(0), final_Z(0);
623 final4mom = initial4mom;
632 G4double ptot = std::sqrt(ekin*(ekin + 2*mass));
633 final4mom.
set(ptot*v.
x(), ptot*v.
y(), ptot*v.
z(), mass + ekin);
643 for (
G4int i = 0; i < nSec; i++) {
656 std::pair<G4double, G4double> checkLevels = epCheckLevels;
657 if (!levelsSetByProcess) {
659 checkLevels.first= std::min(checkLevels.first, epCheckLevels.first);
660 checkLevels.second=std::min(checkLevels.second, epCheckLevels.second);
676 if ( std::abs(relative) > checkLevels.first
677 || std::abs(relative_mom) > checkLevels.first) {
679 relResult = checkRelative ?
"fail" :
"N/A";
684 if ( std::abs(absolute) > checkLevels.second
685 || std::abs(absolute_mom) > checkLevels.second ) {
692 if ( (initial_A-final_A)!=0
693 || (initial_Z-final_Z)!=0 ) {
694 chargePass = checkLevels.second <
DBL_MAX ? false :
true;
695 chargeResult =
"fail";
698 G4bool conservationPass = (relPass || absPass) && chargePass;
700 std::stringstream Myout;
701 G4bool Myout_notempty(
false);
712 Myout <<
" Process: " << processName <<
" , Model: " << modelName <<
G4endl;
716 <<
", target nucleus (" << aNucleus.
GetZ_asInt() <<
","
722 || ! conservationPass ){
724 Myout <<
" "<< relResult <<
" relative, limit " << checkLevels.
first <<
", values E/T(0) = "
725 << relative <<
" p/p(0)= " << relative_mom <<
G4endl;
726 Myout <<
" "<< absResult <<
" absolute, limit (MeV) " << checkLevels.second/MeV <<
", values E / p (MeV) = "
727 << absolute/MeV <<
" / " << absolute_mom/MeV <<
" 3mom: " << (diff.
vect())*1./MeV <<
G4endl;
728 Myout <<
" "<< chargeResult <<
" charge/baryon number balance " << (initial_Z-final_Z) <<
" / " << (initial_A-final_A) <<
" "<<
G4endl;
733 if ( Myout_notempty ) {
743 ed <<
"Unrecoverable error in the method " << method <<
" of "
745 ed <<
"TrackID= "<< aTrack.
GetTrackID() <<
" ParentID= "
751 ed <<
"Position(mm)= " << aTrack.
GetPosition()/CLHEP::mm <<
";";
771 theCrossSectionDataStore->
AddDataSet(aDataSet);
774std::vector<G4HadronicInteraction*>&
783 std::vector<G4HadronicInteraction*>& list
785 for (
size_t li=0; li<list.size(); li++) {
786 if (list[li]->GetModelName() == modelName)
return list[li];
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
@ fKillTrackAndSecondaries
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
Hep3Vector & rotateUz(const Hep3Vector &)
void set(double x, double y, double z, double t)
static void saveEngineStatus(const char filename[]="Config.conf")
static G4AntiKaonZero * Definition()
void BuildPhysicsTable(const G4ParticleDefinition &)
void AddDataSet(G4VCrossSectionDataSet *)
void DumpPhysicsTable(const G4ParticleDefinition &)
G4double ComputeCrossSection(const G4DynamicParticle *, const G4Material *)
G4double GetCrossSection(const G4DynamicParticle *, const G4Material *)
const G4Element * SampleZandA(const G4DynamicParticle *, const G4Material *, G4Nucleus &target)
void SetMomentumDirection(const G4ThreeVector &aDirection)
const G4ThreeVector & GetMomentumDirection() const
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
void SetMass(G4double mass)
const G4ParticleDefinition * GetParticleDefinition() const
G4ParticleDefinition * GetDefinition() const
G4LorentzVector Get4Momentum() const
G4double GetKineticEnergy() const
G4double GetTotalEnergy() const
void SetKineticEnergy(G4double aEnergy)
const G4String & GetName() const
void RegisterMe(G4HadronicInteraction *a)
void BuildPhysicsTable(const G4ParticleDefinition &)
std::vector< G4HadronicInteraction * > & GetHadronicInteractionList()
G4double GetEnergyChange() const
G4HadFinalStateStatus GetStatusChange() const
void SetTrafoToLab(const G4LorentzRotation &aT)
G4double GetLocalEnergyDeposit() const
const G4ThreeVector & GetMomentumChange() const
std::size_t GetNumberOfSecondaries() const
G4HadSecondary * GetSecondary(size_t i)
void Initialise(const G4Track &aT)
const G4ParticleDefinition * GetDefinition() const
G4LorentzRotation & GetTrafoToLab()
G4double GetKineticEnergy() const
const G4LorentzVector & Get4Momentum() const
G4double GetTotalEnergy() const
G4DynamicParticle * GetParticle()
G4double GetWeight() const
G4int GetCreatorModelType() const
void Report(std::ostream &aS) const
virtual G4HadFinalState * ApplyYourself(const G4HadProjectile &aTrack, G4Nucleus &targetNucleus)
virtual const std::pair< G4double, G4double > GetFatalEnergyCheckLevels() const
virtual std::pair< G4double, G4double > GetEnergyMomentumCheckLevels() const
const G4String & GetModelName() const
void DeRegister(G4HadronicProcess *)
void RegisterParticle(G4HadronicProcess *, const G4ParticleDefinition *)
static G4HadronicProcessStore * Instance()
void RegisterInteraction(G4HadronicProcess *, G4HadronicInteraction *)
void Register(G4HadronicProcess *)
void PrintInfo(const G4ParticleDefinition *)
void FillResult(G4HadFinalState *aR, const G4Track &aT)
G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep) override
void ProcessDescription(std::ostream &outFile) const override
void BiasCrossSectionByFactor(G4double aScale)
G4HadFinalState * CheckResult(const G4HadProjectile &thePro, const G4Nucleus &targetNucleus, G4HadFinalState *result)
G4double GetMeanFreePath(const G4Track &aTrack, G4double, G4ForceCondition *) override
G4HadronicInteraction * GetHadronicInteraction() const
G4ParticleChange * theTotalResult
void AddDataSet(G4VCrossSectionDataSet *aDataSet)
G4double GetElementCrossSection(const G4DynamicParticle *part, const G4Element *elm, const G4Material *mat=nullptr)
std::vector< G4HadronicInteraction * > & GetHadronicInteractionList()
void PreparePhysicsTable(const G4ParticleDefinition &) override
G4HadronicProcess(const G4String &processName="Hadronic", G4ProcessType procType=fHadronic)
G4HadronicInteraction * ChooseHadronicInteraction(const G4HadProjectile &aHadProjectile, G4Nucleus &aTargetNucleus, const G4Material *aMaterial, const G4Element *anElement)
~G4HadronicProcess() override
void BuildPhysicsTable(const G4ParticleDefinition &) override
void CheckEnergyMomentumConservation(const G4Track &, const G4Nucleus &)
G4HadronicInteraction * GetHadronicModel(const G4String &)
void DumpState(const G4Track &, const G4String &, G4ExceptionDescription &)
void DumpPhysicsTable(const G4ParticleDefinition &p)
void MultiplyCrossSectionBy(G4double factor)
void RegisterMe(G4HadronicInteraction *a)
static G4KaonZeroLong * Definition()
static G4KaonZeroShort * Definition()
static G4KaonZero * Definition()
const G4String & GetName() const
static G4double GetNuclearMass(const G4double A, const G4double Z)
void AddSecondary(G4Track *aSecondary)
G4double GetEnergy() const
const G4ThreeVector * GetMomentumDirection() const
void ProposeEnergy(G4double finalEnergy)
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
virtual void Initialize(const G4Track &)
G4ProcessManager * GetProcessManager() const
G4bool IsShortLived() const
G4double GetPDGMass() const
G4int GetPDGEncoding() const
G4double GetPDGWidth() const
G4double GetPDGCharge() const
G4int GetBaryonNumber() const
const G4String & GetParticleName() const
static G4int GetIndex(const G4String &)
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
std::size_t first(char) const
G4TrackStatus GetTrackStatus() const
const G4ParticleDefinition * GetParticleDefinition() const
G4VPhysicalVolume * GetVolume() const
G4double GetWeight() const
void SetWeight(G4double aValue)
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4double GetGlobalTime() const
G4ThreeVector GetMomentum() const
G4Material * GetMaterial() const
G4ParticleDefinition * GetDefinition() const
const G4DynamicParticle * GetDynamicParticle() const
const G4TouchableHandle & GetTouchableHandle() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
G4int GetParentID() const
void SetCreatorModelIndex(G4int idx)
void ProposeTrackStatus(G4TrackStatus status)
void SetSecondaryWeightByProcess(G4bool)
void ProposeWeight(G4double finalWeight)
G4int GetNumberOfSecondaries() const
void ProposeLocalEnergyDeposit(G4double anEnergyPart)
void SetNumberOfSecondaries(G4int totSecondaries)
G4Track * GetSecondary(G4int anIndex) const
G4TrackStatus GetTrackStatus() const
const G4String & GetName() const
void ClearNumberOfInteractionLengthLeft()
void SetProcessSubType(G4int)
G4double GetTotalNumberOfInteractionLengthTraversed() const
const G4String & GetProcessName() const