File indexing completed on 2026-03-31 07:49:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "GB05BOptrSplitAndKillByCrossSection.hh"
0030
0031 #include "GB05BOptnSplitAndKillByCrossSection.hh"
0032
0033 #include "G4BiasingProcessInterface.hh"
0034 #include "G4ParticleDefinition.hh"
0035 #include "G4ParticleTable.hh"
0036 #include "G4VProcess.hh"
0037
0038
0039
0040 GB05BOptrSplitAndKillByCrossSection::GB05BOptrSplitAndKillByCrossSection(G4String particleName,
0041 G4String name)
0042 : G4VBiasingOperator(name), fSetup(true)
0043 {
0044 fParticleToBias = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
0045
0046 if (fParticleToBias == nullptr) {
0047 G4ExceptionDescription ed;
0048 ed << "Particle `" << particleName << "' not found !" << G4endl;
0049 G4Exception("GB05BOptrSplitAndKillByCrossSection(...)", "exGB05.01", JustWarning, ed);
0050 }
0051
0052 fSplitAndKillByCrossSection =
0053 new GB05BOptnSplitAndKillByCrossSection("splitterFor_" + particleName);
0054 }
0055
0056
0057
0058 GB05BOptrSplitAndKillByCrossSection::~GB05BOptrSplitAndKillByCrossSection()
0059 {
0060 delete fSplitAndKillByCrossSection;
0061 }
0062
0063
0064
0065 void GB05BOptrSplitAndKillByCrossSection::StartRun()
0066 {
0067
0068
0069
0070
0071
0072
0073
0074 if (fSetup) {
0075 const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
0076 const G4BiasingProcessSharedData* sharedData =
0077 G4BiasingProcessInterface::GetSharedData(processManager);
0078 if (sharedData) {
0079 for (size_t i = 0; i < fProcessesToEquipoise.size(); i++) {
0080 G4bool processFound(false);
0081 for (size_t j = 0; j < (sharedData->GetPhysicsBiasingProcessInterfaces()).size(); j++) {
0082 const G4BiasingProcessInterface* wrapperProcess =
0083 (sharedData->GetPhysicsBiasingProcessInterfaces())[j];
0084 if (fProcessesToEquipoise[i] == wrapperProcess->GetWrappedProcess()->GetProcessName()) {
0085 fProcesses.push_back(wrapperProcess->GetWrappedProcess());
0086 processFound = true;
0087 break;
0088 }
0089 }
0090 if (!processFound) {
0091 G4String particleName = "(unknown)";
0092 if (fParticleToBias != nullptr) {
0093 particleName = fParticleToBias->GetParticleName();
0094 }
0095 G4ExceptionDescription ed;
0096 ed << "Process `" << fProcessesToEquipoise[i] << "' not found for particle `"
0097 << particleName << "'" << G4endl;
0098 G4Exception("GB05BOptrSplitAndKillByCrossSection::StartRun(...)", "exGB05.02",
0099 JustWarning, ed);
0100 }
0101 }
0102 }
0103 fSetup = false;
0104 }
0105
0106 if (fProcessesToEquipoise.size() == 0 || fProcesses.size() == 0) {
0107 G4ExceptionDescription ed;
0108 ed << "No processes to counterbalance for defined or found ! "
0109 << "Biasing will do nothing." << G4endl;
0110 G4Exception("GB05BOptrSplitAndKillByCrossSection::StartRun(...)", "exGB05.03", JustWarning, ed);
0111 }
0112 }
0113
0114
0115
0116 G4VBiasingOperation* GB05BOptrSplitAndKillByCrossSection::ProposeNonPhysicsBiasingOperation(
0117 const G4Track* track, const G4BiasingProcessInterface* )
0118 {
0119
0120
0121
0122 if (track->GetDefinition() != fParticleToBias) return nullptr;
0123
0124
0125
0126
0127
0128
0129
0130
0131 G4double totalCrossSection(0.0);
0132 for (size_t i = 0; i < fProcesses.size(); i++) {
0133 G4double interactionLength = fProcesses[i]->GetCurrentInteractionLength();
0134 if (interactionLength < DBL_MAX / 10.) totalCrossSection += 1. / interactionLength;
0135 }
0136 if (totalCrossSection < DBL_MIN) return nullptr;
0137
0138 G4double totalInteractionLength = 1. / totalCrossSection;
0139
0140
0141
0142
0143
0144 fSplitAndKillByCrossSection->SetInteractionLength(totalInteractionLength);
0145
0146 return fSplitAndKillByCrossSection;
0147 }
0148
0149 void GB05BOptrSplitAndKillByCrossSection::AddProcessToEquipoise(G4String processName)
0150 {
0151 fProcessesToEquipoise.push_back(processName);
0152 }