From 4177607b400c1534aeec95bbb27dd8ade2947f12 Mon Sep 17 00:00:00 2001 From: Leander Schlegel Date: Fri, 17 May 2024 13:01:51 +0200 Subject: [PATCH 1/3] changed order in performInteraction so that energy loss without secondary injection can be applied and no other calculations are done in that case, that should be not necessary --- src/module/EMPairProduction.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/module/EMPairProduction.cpp b/src/module/EMPairProduction.cpp index d57ecc1ae..2b5eed623 100644 --- a/src/module/EMPairProduction.cpp +++ b/src/module/EMPairProduction.cpp @@ -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())) @@ -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 From 4b27792b9159036988417cc7bc28a3c9d2518b16 Mon Sep 17 00:00:00 2001 From: Leander Schlegel Date: Fri, 17 May 2024 13:05:45 +0200 Subject: [PATCH 2/3] taking out unnecessary if-statement --- src/module/EMDoublePairProduction.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/module/EMDoublePairProduction.cpp b/src/module/EMDoublePairProduction.cpp index 451081743..7477cf81a 100644 --- a/src/module/EMDoublePairProduction.cpp +++ b/src/module/EMDoublePairProduction.cpp @@ -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); @@ -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 { From 14c783564f9b5521e4e54797b9ff62e7af9ee421 Mon Sep 17 00:00:00 2001 From: Leander Schlegel Date: Tue, 21 May 2024 14:41:11 +0200 Subject: [PATCH 3/3] small optimization for case of haveSecondaries=False, as pointed out by Julien --- src/module/EMInverseComptonScattering.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module/EMInverseComptonScattering.cpp b/src/module/EMInverseComptonScattering.cpp index 55c7637b5..c15d689d6 100644 --- a/src/module/EMInverseComptonScattering.cpp +++ b/src/module/EMInverseComptonScattering.cpp @@ -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());