19#include "G4Version.hh"
21#if G4VERSION_NUMBER > 1009
23#include "BDSBOptrChangeCrossSection.hh"
25#include "BDSException.hh"
26#include "BDSPhysicsUtilities.hh"
29#include "G4BiasingProcessInterface.hh"
30#include "G4BiasingProcessSharedData.hh"
31#include "G4BOptnChangeCrossSection.hh"
32#include "G4InteractionLawPhysical.hh"
33#include "G4IonTable.hh"
34#include "G4ParticleDefinition.hh"
35#include "G4ParticleTable.hh"
37#include "G4VProcess.hh"
42BDSBOptrChangeCrossSection::BDSBOptrChangeCrossSection(
const G4String& particleNameIn,
43 const G4String& name):
44 G4VBiasingOperator(name),
46 particleName(particleNameIn),
49 fParticleToBias = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
52 {
throw BDSException(__METHOD_NAME__,
"Particle \"" + particleName +
"\" not found");}
57BDSBOptrChangeCrossSection::~BDSBOptrChangeCrossSection()
59 for (
auto change : fChangeCrossSectionOperations)
60 {
delete change.second;}
63void BDSBOptrChangeCrossSection::StartRun()
70 const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
71 const G4BiasingProcessSharedData* sharedData = G4BiasingProcessInterface::GetSharedData(processManager);
77 for (
const auto& wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
79 G4String operationName =
"XSchange-"+wrapperProcess->GetWrappedProcess()->GetProcessName();
80 fChangeCrossSectionOperations[wrapperProcess] =
new G4BOptnChangeCrossSection(operationName);
81 fXSScale[wrapperProcess] = 1.0;
82 fPrimaryScale[wrapperProcess] = 0;
89void BDSBOptrChangeCrossSection::SetBias(
const G4String& processName,
93 const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
94 const G4BiasingProcessSharedData* sharedData = G4BiasingProcessInterface::GetSharedData(processManager);
96 G4bool allProcesses =
false;
97 if (processName ==
"all")
98 {allProcesses =
true;}
100 G4bool processFound =
false;
101 for (
const auto& wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
103 G4String currentProcess = wrapperProcess->GetWrappedProcess()->GetProcessName();
106 std::regex braces(
"[\\w\\-\\+_$]*\\((\\w+)\\)");
109 if (std::regex_search(currentProcess, match, braces))
110 {currentProcess = match[1];}
112 if (allProcesses || processName == currentProcess)
114 fXSScale[wrapperProcess] = bias;
115 fPrimaryScale[wrapperProcess] = iPrimary;
121 G4cout <<
"\nCouldn't find process by name. Available processes are:" << G4endl;
122 for (
const auto wrapperProcess : sharedData->GetPhysicsBiasingProcessInterfaces())
124 G4String currentProcessName = wrapperProcess->GetWrappedProcess()->GetProcessName();
125 G4cout <<
"\"" << currentProcessName <<
"\"" << G4endl;
127 throw BDSException(__METHOD_NAME__,
"Process \"" + processName +
128 "\" not found registered to particle \"" + particleName +
"\"");
132G4VBiasingOperation* BDSBOptrChangeCrossSection::ProposeOccurenceBiasingOperation(
const G4Track* track,
133 const G4BiasingProcessInterface* callingProcess)
136 const G4ParticleDefinition* definition = track->GetDefinition();
139 if (!G4IonTable::IsIon(definition) || definition == G4Proton::Definition())
143 else if (definition != fParticleToBias)
151 G4double analogInteractionLength = callingProcess->GetWrappedProcess()->GetCurrentInteractionLength();
152 if (analogInteractionLength > std::numeric_limits<double>::max()/10.)
157 if (analogInteractionLength < 0)
161 G4double analogXS = 1./analogInteractionLength;
166 G4double XStransformation = 1.0;
169 G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
172 G4VBiasingOperation* previousOperation = callingProcess->GetPreviousOccurenceBiasingOperation();
175 if ( fPrimaryScale[callingProcess] == 2 && track->GetParentID() != 0 )
177 if ( fPrimaryScale[callingProcess] == 3 && track->GetParentID() == 0 )
179 XStransformation = fXSScale[callingProcess];
197 if (!previousOperation)
199 operation->SetBiasedCrossSection( XStransformation * analogXS );
204 if (previousOperation != operation)
209 if (operation->GetInteractionOccured())
211 operation->SetBiasedCrossSection( XStransformation * analogXS );
218 operation->UpdateForStep(callingProcess->GetPreviousStepSize());
220 operation->SetBiasedCrossSection(XStransformation * analogXS);
223 operation->UpdateForStep(0.0);
229void BDSBOptrChangeCrossSection::OperationApplied(
const G4BiasingProcessInterface* callingProcess,
230 G4BiasingAppliedCase,
231 G4VBiasingOperation* occurenceOperationApplied,
233 G4VBiasingOperation*,
234 const G4VParticleChange*)
236 G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
237 if (operation == occurenceOperationApplied)
238 {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.