Skip to content

Commit

Permalink
TEMPORARY debug lc2
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Feb 7, 2025
1 parent c081d25 commit 5f691ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ncrystal_core/src/extd_utils/NCLCRefModels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ void NC::LCBraggRndmRot::updateCache(Cache& cache, NeutronEnergy ekin, const Vec
auto nd = cache.rotations.back().rotateVectorAroundAxis( indir, m_lcaxislab, lccross,
lcdot ).as<NeutronDirection>();
sumxs.add(m_sc->crossSection(cache.sc_cacheptr,ekin,nd).get());
if ( do_debug )
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::updateCache sumxs is now "<<NC::fmt(sumxs.sum()));

cache.xscommul.push_back(sumxs.sum());
}
}
Expand Down Expand Up @@ -163,13 +166,30 @@ NC::ScatterOutcome NC::LCBraggRndmRot::sampleScatter(CachePtr&cp, RNG& rng, Neut
return {ekin,indir_nd};
}

static bool do_debug = getenv("NCRYSTALDEBUGLC") != nullptr;

//Select one phi rotation at random:
const PhiRot& phirot = cache.rotations.at(pickRandIdxByWeight(rng,cache.xscommul));
auto idx = pickRandIdxByWeight(rng,cache.xscommul);
if ( do_debug ) {
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter selected phirot idx = "<<idx);
}
const PhiRot& phirot = cache.rotations.at(idx);

//Scatter!
auto ndir = phirot.rotateVectorAroundAxis( indir, m_lcaxislab).as<NeutronDirection>();
if ( do_debug ) {
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter scatter! indir = "<<indir);
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter scatter! ndir = "<<ndir);
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter scatter! m_lcaxislab = "<<m_lcaxislab);
}
auto scatoutcome = m_sc->sampleScatter(cache.sc_cacheptr,rng,ekin,ndir);
if ( do_debug ) {
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter scatter! scatoutcome = "<<scatoutcome);
}
auto outdir = phirot.rotateVectorAroundAxis( scatoutcome.direction.as<Vector>(), m_lcaxislab,
true/*reverse*/).as<NeutronDirection>();
if ( do_debug ) {
NCRYSTAL_MSG("DEBUGLC::LCBraggRndmRot::sampleScatter scatter! outdir = "<<outdir);
}
return { ekin, outdir };
}
7 changes: 7 additions & 0 deletions tests/src/app_lc2/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ NCrystal: DEBUGLC::LCBragg::sampleScatter next rng is:0.0537314
NCrystal: DEBUGLC::LCBragg::sampleScatter use fallback reference model
NCrystal: DEBUGLC::LCBraggRndmRot::updateCache
NCrystal: DEBUGLC::LCBraggRndmRot::updateCache selected cosphi=0.14386359402338836 sinphi=-0.98959752743965257
NCrystal: DEBUGLC::LCBraggRndmRot::updateCache sumxs is now 70.567763211908257
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter selected phirot idx = 0
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter scatter! indir = { 0, 0.707107, -0.707107 }
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter scatter! ndir = { 0.699751, 0.101727, -0.707107 }
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter scatter! m_lcaxislab = { 0, 0, 1 }
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter scatter! scatoutcome = ScatterOutcomeIsotropic(E=0.00363272eV, dir={ 0.6935, 0.140873, 0.70655 })
NCrystal: DEBUGLC::LCBraggRndmRot::sampleScatter scatter! outdir = { -0.0396386, 0.706552, 0.70655 }
scatter: (-0.0396386,0.706552,0.70655)=89.9999deg de=0

0 comments on commit 5f691ee

Please sign in to comment.