19#include "BDSException.hh"
20#include "BDSPhysicsMuonSplitting.hh"
21#include "BDSWrapperMuonSplitting.hh"
23#include "G4ParticleDefinition.hh"
24#include "G4ParticleTable.hh"
25#include "G4PhysicsListHelper.hh"
26#include "G4ProcessManager.hh"
27#include "G4ProcessVector.hh"
29#include "G4TrackFastVector.hh"
31#include "G4Version.hh"
33#include "CLHEP/Units/SystemOfUnits.h"
38BDSPhysicsMuonSplitting::BDSPhysicsMuonSplitting(G4int splittingFactorIn,
39 G4double splittingThresholdEKIn,
40 G4int splittingFactor2In,
41 G4double splittingThresholdEK2In,
42 G4bool excludeWeight1ParticlesIn,
43 G4double muonSplittingExclusionWeightIn):
44 G4VPhysicsConstructor(
"BDSPhysicsMuonSplitting"),
45 splittingFactor(splittingFactorIn),
46 splittingThresholdEK(splittingThresholdEKIn),
47 splittingFactor2(splittingFactor2In),
48 splittingThresholdEK2(splittingThresholdEK2In),
49 excludeWeight1Particles(excludeWeight1ParticlesIn),
50 muonSplittingExclusionWeight(muonSplittingExclusionWeightIn)
52 if (splittingFactorIn < 1)
53 {
throw BDSException(__METHOD_NAME__,
"the splitting factor must be an integer 1 or greater.");}
54 if (splittingFactor2In < 1)
55 {
throw BDSException(__METHOD_NAME__,
"the splitting factor #2 must be an integer 1 or greater.");}
56 G4int maxSize = G4TrackFastVectorSize/2;
57 if (splittingFactorIn > maxSize)
59 G4String msg =
"the maximum safe splitting factor is " + std::to_string(maxSize);
60 msg +=
" based on the G4TrackFastVectorSize in Geant4";
63 if (splittingFactor2In > maxSize)
65 G4String msg =
"(for factor #2) the maximum safe splitting factor is " + std::to_string(maxSize);
66 msg +=
" based on the G4TrackFastVectorSize in Geant4";
71BDSPhysicsMuonSplitting::~BDSPhysicsMuonSplitting()
82 if (excludeWeight1Particles)
83 {G4cout <<
"Bias> muon splitting> excluding weight=1 parents from splitting." << G4endl;}
98 std::map<G4String, std::set<G4String> > particleProcesses = {{
"e+", {
"AnnihiToMuPair"}},
101 {
"kaon+", {
"Decay"}},
102 {
"kaon-", {
"Decay"}},
103 {
"kaon0L", {
"Decay"}} };
105#if G4VERSION_NUMBER > 1029
106 auto aParticleIterator = G4ParticleTable::GetParticleTable()->GetIterator();
108 aParticleIterator->reset();
110 G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
112 while( (*aParticleIterator)() )
114 G4ParticleDefinition* particle = aParticleIterator->value();
115 G4String particleName = particle->GetParticleName();
116 const auto& search = particleProcesses.find(particleName);
117 if (search == particleProcesses.end())
121 G4ProcessManager* pManager = particle->GetProcessManager();
122 G4ProcessVector* processVector = pManager->GetProcessList();
123 const std::set<G4String>& processNamesToLookFor = search->second;
124 for (G4int i=0; i < (G4int)processVector->entries(); ++i)
126 G4VProcess* process = (*processVector)[i];
127 G4String processName = process->GetProcessName();
128 if (processNamesToLookFor.count(processName) == 0)
133 splittingThresholdEK,
135 splittingThresholdEK2,
136 excludeWeight1Particles,
137 muonSplittingExclusionWeight);
138 pManager->RemoveProcess(process);
139 ph->RegisterProcess(wrappedProcess, particle);
140 G4cout <<
"Bias> muon splitting> wrapping \"" << process->GetProcessName()
141 <<
"\" for particle \"" << particle->GetParticleName() <<
"\": x" << splittingFactor
142 <<
" for parent Ek > " << splittingThresholdEK / CLHEP::GeV <<
" GeV" << G4endl;
143 if (splittingFactor2 > 1)
145 G4cout <<
"Bias> muon splitting> wrapping \"" << process->GetProcessName()
146 <<
"\" for particle \"" << particle->GetParticleName() <<
"\": (2nd band) x" << splittingFactor2
147 <<
" 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.