20#include "G4Version.hh"
22#if G4VERSION_NUMBER > 1009
24#include "BDSBOptrChangeCrossSection.hh"
26#include "BDSException.hh"
27#include "BDSPhysicsUtilities.hh"
30#include "G4BiasingProcessInterface.hh"
31#include "G4BiasingProcessSharedData.hh"
32#include "G4BOptnChangeCrossSection.hh"
33#include "G4InteractionLawPhysical.hh"
34#include "G4IonTable.hh"
35#include "G4ParticleDefinition.hh"
36#include "G4ParticleTable.hh"
38#include "G4VProcess.hh"
43BDSBOptrChangeCrossSection::BDSBOptrChangeCrossSection(
const G4String& particleNameIn,
44 const G4String& name):
45 G4VBiasingOperator(name),
47 particleName(particleNameIn),
50 fParticleToBias = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
53 {
throw BDSException(__METHOD_NAME__,
"Particle \"" + particleName +
"\" not found");}
58BDSBOptrChangeCrossSection::~BDSBOptrChangeCrossSection()
60 for (
auto change : fChangeCrossSectionOperations)
61 {
delete change.second;}
64void BDSBOptrChangeCrossSection::StartRun()
71 const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
72 const G4BiasingProcessSharedData* sharedData = G4BiasingProcessInterface::GetSharedData(processManager);
78 for (
const auto& wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
80 G4String operationName =
"XSchange-"+wrapperProcess->GetWrappedProcess()->GetProcessName();
81 fChangeCrossSectionOperations[wrapperProcess] =
new G4BOptnChangeCrossSection(operationName);
82 fXSScale[wrapperProcess] = 1.0;
83 fPrimaryScale[wrapperProcess] = 0;
90void BDSBOptrChangeCrossSection::SetBias(
const G4String& processName,
94 const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
95 const G4BiasingProcessSharedData* sharedData = G4BiasingProcessInterface::GetSharedData(processManager);
97 G4bool allProcesses =
false;
98 if (processName ==
"all")
99 {allProcesses =
true;}
101 G4bool processFound =
false;
102 for (
const auto& wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
104 G4String currentProcess = wrapperProcess->GetWrappedProcess()->GetProcessName();
107 std::regex braces(
"[\\w\\-\\+_$]*\\((\\w+)\\)");
110 if (std::regex_search(currentProcess, match, braces))
111 {currentProcess = match[1];}
113 if (allProcesses || processName == currentProcess)
115 fXSScale[wrapperProcess] = bias;
116 fPrimaryScale[wrapperProcess] = iPrimary;
122 G4cout <<
"\nCouldn't find process by name. Available processes are:" << G4endl;
123 for (
const auto wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
125 G4String currentProcessName = wrapperProcess->GetWrappedProcess()->GetProcessName();
126 G4cout <<
"\"" << currentProcessName <<
"\"" << G4endl;
128 throw BDSException(__METHOD_NAME__,
"Process \"" + processName +
129 "\" not found registered to particle \"" + particleName +
"\"");
133G4VBiasingOperation* BDSBOptrChangeCrossSection::ProposeOccurenceBiasingOperation(
const G4Track* track,
134 const G4BiasingProcessInterface* callingProcess)
137 const G4ParticleDefinition* definition = track->GetDefinition();
140 if (!G4IonTable::IsIon(definition) || definition == G4Proton::Definition())
144 else if (definition != fParticleToBias)
152 G4double analogInteractionLength = callingProcess->GetWrappedProcess()->GetCurrentInteractionLength();
153 if (analogInteractionLength > std::numeric_limits<double>::max()/10.)
158 if (analogInteractionLength < 0)
162 G4double analogXS = 1./analogInteractionLength;
167 G4double XStransformation = 1.0;
170 G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
173 G4VBiasingOperation* previousOperation = callingProcess->GetPreviousOccurenceBiasingOperation();
176 if ( fPrimaryScale[callingProcess] == 2 && track->GetParentID() != 0 )
178 if ( fPrimaryScale[callingProcess] == 3 && track->GetParentID() == 0 )
180 XStransformation = fXSScale[callingProcess];
198 if (!previousOperation)
200 operation->SetBiasedCrossSection( XStransformation * analogXS );
205 if (previousOperation != operation)
210 if (operation->GetInteractionOccured())
212 operation->SetBiasedCrossSection( XStransformation * analogXS );
219 operation->UpdateForStep(callingProcess->GetPreviousStepSize());
221 operation->SetBiasedCrossSection(XStransformation * analogXS);
224 operation->UpdateForStep(0.0);
230void BDSBOptrChangeCrossSection::OperationApplied(
const G4BiasingProcessInterface* callingProcess,
231 G4BiasingAppliedCase,
232 G4VBiasingOperation* occurenceOperationApplied,
234 G4VBiasingOperation*,
235 const G4VParticleChange*)
237 G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
238 if (operation == occurenceOperationApplied)
239 {operation->SetInteractionOccured();}
General exception with possible name of object and message.
G4bool IsIon(const G4ParticleDefinition *particle)
Whether a particle is an ion. A proton is counted NOT as an ion.