20#include "BDSException.hh"
21#include "BDSPhysicsMuonSplitting.hh"
22#include "BDSWrapperMuonSplitting.hh"
24#include "G4ParticleDefinition.hh"
25#include "G4ParticleTable.hh"
26#include "G4PhysicsListHelper.hh"
27#include "G4ProcessManager.hh"
28#include "G4ProcessVector.hh"
30#include "G4TrackFastVector.hh"
32#include "G4Version.hh"
34#include "CLHEP/Units/SystemOfUnits.h"
39BDSPhysicsMuonSplitting::BDSPhysicsMuonSplitting(G4int splittingFactorIn,
40 G4double splittingThresholdEKIn,
41 G4int splittingFactor2In,
42 G4double splittingThresholdEK2In,
43 G4bool excludeWeight1ParticlesIn,
44 G4double muonSplittingExclusionWeightIn):
45 G4VPhysicsConstructor(
"BDSPhysicsMuonSplitting"),
46 splittingFactor(splittingFactorIn),
47 splittingThresholdEK(splittingThresholdEKIn),
48 splittingFactor2(splittingFactor2In),
49 splittingThresholdEK2(splittingThresholdEK2In),
50 excludeWeight1Particles(excludeWeight1ParticlesIn),
51 muonSplittingExclusionWeight(muonSplittingExclusionWeightIn)
53 if (splittingFactorIn < 1)
54 {
throw BDSException(__METHOD_NAME__,
"the splitting factor must be an integer 1 or greater.");}
55 if (splittingFactor2In < 1)
56 {
throw BDSException(__METHOD_NAME__,
"the splitting factor #2 must be an integer 1 or greater.");}
57 G4int maxSize = G4TrackFastVectorSize/2;
58 if (splittingFactorIn > maxSize)
60 G4String msg =
"the maximum safe splitting factor is " + std::to_string(maxSize);
61 msg +=
" based on the G4TrackFastVectorSize in Geant4";
64 if (splittingFactor2In > maxSize)
66 G4String msg =
"(for factor #2) the maximum safe splitting factor is " + std::to_string(maxSize);
67 msg +=
" based on the G4TrackFastVectorSize in Geant4";
72BDSPhysicsMuonSplitting::~BDSPhysicsMuonSplitting()
83 if (excludeWeight1Particles)
84 {G4cout <<
"Bias> muon splitting> excluding weight=1 parents from splitting." << G4endl;}
99 std::map<G4String, std::set<G4String> > particleProcesses = {{
"e+", {
"AnnihiToMuPair"}},
102 {
"kaon+", {
"Decay"}},
103 {
"kaon-", {
"Decay"}},
104 {
"kaon0L", {
"Decay"}} };
106#if G4VERSION_NUMBER > 1029
107 auto aParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator();
109 aParticleIterator->reset();
111 G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
113 while( (*aParticleIterator)() )
115 G4ParticleDefinition* particle = aParticleIterator->value();
116 G4String particleName = particle->GetParticleName();
117 const auto& search = particleProcesses.find(particleName);
118 if (search == particleProcesses.end())
122 G4ProcessManager* pManager = particle->GetProcessManager();
123 G4ProcessVector* processVector = pManager->GetProcessList();
124 const std::set<G4String>& processNamesToLookFor = search->second;
125 for (G4int i=0; i < (G4int)processVector->entries(); ++i)
127 G4VProcess* process = (*processVector)[i];
128 G4String processName = process->GetProcessName();
129 if (processNamesToLookFor.count(processName) == 0)
133 splittingFactor2, splittingThresholdEK2, excludeWeight1Particles,
134 muonSplittingExclusionWeight);
135 pManager->RemoveProcess(process);
136 ph->RegisterProcess(wrappedProcess, particle);
137 G4cout <<
"Bias> muon splitting> wrapping \"" << process->GetProcessName()
138 <<
"\" for particle \"" << particle->GetParticleName() <<
"\": x" << splittingFactor
139 <<
" for parent Ek > " << splittingThresholdEK / CLHEP::GeV <<
" GeV" << G4endl;
140 if (splittingFactor2 > 1)
142 G4cout <<
"Bias> muon splitting> wrapping \"" << process->GetProcessName()
143 <<
"\" for particle \"" << particle->GetParticleName() <<
"\": (2nd band) x" << splittingFactor2
144 <<
" for parent Ek > " << splittingThresholdEK2 / CLHEP::GeV <<
" GeV" << G4endl;
General exception with possible name of object and message.
virtual void ConstructParticle()
Construct all leptons, photons (inc optical), and pion +- just in case.
virtual void ConstructProcess()
Construct and attach the processes to the relevant particles.
G4bool Activated() const
Get whether this instance has been activated.
void SetActivated()
Flag this instance as activated for later querying.
Wrapper process to produce more muons by resampling the process.