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