Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix for EMPairProduction when haveElectrons=False and small Optimizations #491

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/module/EMDoublePairProduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void EMDoublePairProduction::performInteraction(Candidate *candidate) const {

double f = Ee / E;

if (haveElectrons) {
if (random.rand() < pow(1 - f, thinning)) {
double w = 1. / pow(1 - f, thinning);
candidate->addSecondary( 11, Ee / (1 + z), pos, w, interactionTag);
Expand All @@ -87,7 +86,6 @@ void EMDoublePairProduction::performInteraction(Candidate *candidate) const {
double w = 1. / pow(f, thinning);
candidate->addSecondary(-11, Ee / (1 + z), pos, w, interactionTag);
}
}
}

void EMDoublePairProduction::process(Candidate *candidate) const {
Expand Down
4 changes: 2 additions & 2 deletions src/module/EMInverseComptonScattering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ void EMInverseComptonScattering::performInteraction(Candidate *candidate) const
double Enew = distribution.sample(E, s);

// add up-scattered photon
double Esecondary = E - Enew;
double f = Enew / E;
if (havePhotons) {
double Esecondary = E - Enew;
double f = Enew / E;
if (random.rand() < pow(1 - f, thinning)) {
double w = 1. / pow(1 - f, thinning);
Vector3d pos = random.randomInterpolatedPosition(candidate->previous.getPosition(), candidate->current.getPosition());
Expand Down
13 changes: 7 additions & 6 deletions src/module/EMPairProduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ class PPSecondariesEnergyDistribution {
};

void EMPairProduction::performInteraction(Candidate *candidate) const {
// scale particle energy instead of background photon energy
double z = candidate->getRedshift();
double E = candidate->current.getEnergy() * (1 + z);

// photon is lost after interacting
candidate->setActive(false);

// check if secondary electron pair needs to be produced
if (not haveElectrons)
return;

// scale particle energy instead of background photon energy
double z = candidate->getRedshift();
double E = candidate->current.getEnergy() * (1 + z);

// check if in tabulated energy range
if (E < tabE.front() or (E > tabE.back()))
Expand All @@ -203,9 +207,6 @@ void EMPairProduction::performInteraction(Candidate *candidate) const {
if (not std::isfinite(Ee) || not std::isfinite(Ep))
return;

// photon is lost after interacting
candidate->setActive(false);

// sample random position along current step
Vector3d pos = random.randomInterpolatedPosition(candidate->previous.getPosition(), candidate->current.getPosition());
// apply sampling
Expand Down
Loading