22 #include "Geant4/G4DynamicParticle.hh" 23 #include "Geant4/G4KaonZeroLong.hh" 24 #include "Geant4/G4KaonZeroShort.hh" 25 #include "Geant4/G4LorentzVector.hh" 26 #include "Geant4/G4ParticleChange.hh" 27 #include "Geant4/G4ParticleDefinition.hh" 28 #include "Geant4/G4Step.hh" 29 #include "Geant4/G4String.hh" 30 #include "Geant4/G4ThreeVector.hh" 31 #include "Geant4/G4Track.hh" 32 #include "Geant4/G4VParticleChange.hh" 33 #include "Geant4/G4ios.hh" 34 #include "Geant4/Randomize.hh" 36 #include "cetlib_except/exception.h" 46 G4VParticleChange* pChange = pRegProcess->PostStepDoIt(track, step);
47 pChange->SetVerboseLevel(0);
48 pChange->SetSecondaryWeightByProcess(
true);
50 G4double secWeight = 1.0;
52 std::vector<G4Track*> secondaries;
57 G4double s = step.GetStepLength();
58 G4double
x = pRegProcess->GetCurrentInteractionLength();
59 nw = pChange->GetParentWeight();
64 if (
wc < 1.0
e-10)
wc = 1.0;
65 nw *= 1 /
wc * (1. - exp(-s / x)) / (1 - exp(-
eFactor * s / x));
66 G4cout <<
" MNSPXSB.PostStepDoit(): original wt = " << pChange->GetParentWeight()
67 <<
" eF = " <<
eFactor << G4endl;
68 G4cout <<
" MNSPXSB.PostStepDoit(): New weight = " << nw <<
" wc = " <<
wc <<
" s= " << s
69 <<
" x = " << x << G4endl;
70 ((G4ParticleChange*)pChange)->ProposeParentWeight(nw);
74 ((G4ParticleChange*)pChange)->ProposeParentWeight(nw);
81 pChange->SetNumberOfSecondaries(pChange->GetNumberOfSecondaries() + 1);
82 G4ThreeVector mDirection = track.GetDynamicParticle()->GetMomentumDirection();
83 G4DynamicParticle* aD =
84 new G4DynamicParticle((track.GetDynamicParticle())->GetDefinition(),
85 G4LorentzVector(mDirection,
86 (track.GetDynamicParticle())->GetKineticEnergy() +
87 step.GetTotalEnergyDeposit()));
88 G4Track* secTrk =
new G4Track(aD, step.GetDeltaTime(), step.GetDeltaPosition());
89 pChange->AddSecondary(secTrk);
90 pChange->GetSecondary(pChange->GetNumberOfSecondaries() - 1)
94 nw = track.GetWeight();
95 pChange->ProposeParentWeight(nw);
99 secWeight = secWeight * nw;
105 G4VParticleChange* particleChange =
new G4VParticleChange();
107 for (
unsigned int ii = 0; ii < (
unsigned int)
fNSplit; ii++) {
108 particleChange = pRegProcess->PostStepDoIt(track, step);
110 throw std::runtime_error(
111 "MuNuclearSplittingProcessXSecBias::PostStepDoIt(): no particle change");
113 G4int numSec(particleChange->GetNumberOfSecondaries());
115 for (j = 0; j < numSec; j++) {
116 G4Track* newSec =
new G4Track(*(particleChange->GetSecondary(j)));
117 G4String pdgstr = newSec->GetParticleDefinition()->GetParticleName();
119 G4int pdg = newSec->GetParticleDefinition()->GetPDGEncoding();
120 if (
abs(pdg) == 310 ||
abs(pdg) == 311 ||
abs(pdg) == 3122 ||
abs(pdg) == 2112) {
123 if (pdg == G4KaonZeroShort::KaonZeroShort()->GetPDGEncoding() && G4UniformRand() < 0.50) {
124 pdg = G4KaonZeroLong::KaonZeroLong()->GetPDGEncoding();
125 pdgstr = G4KaonZeroLong::KaonZeroLong()->GetParticleName();
126 G4LorentzVector pK0L(
127 newSec->GetMomentum(),
128 TMath::Sqrt(TMath::Power(G4KaonZeroLong::KaonZeroLong()->GetPDGMass(), 2) +
129 TMath::Power(newSec->GetMomentum().mag(), 2)));
130 G4DynamicParticle* newK0L =
new G4DynamicParticle(G4KaonZeroLong::KaonZeroLong(), pK0L);
132 G4Track* newSecK0L =
new G4Track(newK0L, track.GetGlobalTime(), track.GetPosition());
133 secondaries.push_back(newSecK0L);
136 secondaries.push_back(newSec);
142 pChange->SetNumberOfSecondaries(secondaries.size());
143 pChange->SetSecondaryWeightByProcess(
true);
148 while (iter != secondaries.end()) {
149 G4Track* myTrack = *iter;
150 G4String pdgstr = myTrack->GetParticleDefinition()->GetParticleName();
151 G4double ke = myTrack->GetKineticEnergy() / CLHEP::GeV;
152 G4int pdg = myTrack->GetParticleDefinition()->GetPDGEncoding();
153 if (
abs(pdg) == 130 ||
abs(pdg) == 310 ||
abs(pdg) == 311 ||
abs(pdg) == 3122 ||
156 std::cout <<
"MuNuclSplXSB(): Adding " << pdgstr <<
" of Kinetic Energy and weight " << ke
157 <<
" GeV and " << secWeight <<
"." << std::endl;
159 myTrack->SetWeight(secWeight);
160 pChange->AddSecondary(myTrack);
179 G4VParticleChange* pC =
new G4VParticleChange();
180 pC->Initialize(track);
184 pC->ProposeParentWeight(nw);
185 for (G4int i = 0; i < pC->GetNumberOfSecondaries(); i++)
186 pC->GetSecondary(i)->SetWeight(nw);
189 pC->SetNumberOfSecondaries(pC->GetNumberOfSecondaries() + 1);
190 G4ThreeVector mDirection = track.GetDynamicParticle()->GetMomentumDirection();
191 G4DynamicParticle* aD =
192 new G4DynamicParticle((track.GetDynamicParticle())->GetDefinition(),
193 G4LorentzVector(mDirection,
194 (track.GetDynamicParticle())->GetKineticEnergy() +
195 step.GetTotalEnergyDeposit()));
198 track.GetGlobalTime(),
199 track.GetPosition());
200 secTrk->SetGoodForTrackingFlag(
true);
201 pC->AddSecondary(secTrk);
202 pC->GetSecondary(pC->GetNumberOfSecondaries() - 1)
211 G4double s = step.GetStepLength();
212 G4double
x = pRegProcess->GetCurrentInteractionLength();
227 <<
"Set XBiasMode to 0 or 1. " <<
xBiasMode <<
" not allowed!\n";
237 G4double biasedProbability = 1. - std::exp(-nLTraversed);
238 G4double realProbability = 1 - std::exp(-nLTraversed /
eFactor);
239 result = (biasedProbability - realProbability) / biasedProbability;
257 const G4Track&
track,
258 G4double previousStepSize,
259 G4ForceCondition* condition)
265 G4double psgPIL = (1. /
eFactor) * pRegProcess->PostStepGetPhysicalInteractionLength(
266 track, previousStepSize, condition);
270 return pRegProcess->PostStepGetPhysicalInteractionLength(track, previousStepSize, condition);
274 const G4Track&
track,
275 G4double previousStepSize,
276 G4double currentMinimumStep,
277 G4double& proposedSafety,
278 G4GPILSelection* selection)
286 (1. /
eFactor) * pRegProcess->AlongStepGetPhysicalInteractionLength(
287 track, previousStepSize, currentMinimumStep, proposedSafety, selection);
289 return currentMinimumStep;
G4VParticleChange fParticleChange
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
constexpr auto abs(T v)
Returns the absolute value of the argument.
Check of Geant4 to run the LArSoft detector simulation.
G4double GetTotalNumberOfInteractionLengthTraversed()
G4double XBiasSurvivalProbability()
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)
G4double XBiasSecondaryWeight()
G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &step)
G4double theInitialNumberOfInteractionLength
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step)
cet::coded_exception< error, detail::translate > exception