Consolidate nudk decay-osc calculator (supersedes #42, #47) - #48
Consolidate nudk decay-osc calculator (supersedes #42, #47)#48gavinsdavies wants to merge 25 commits into
Conversation
Copy Cullen changes
…after all comments Merge branch 'main' into feature/acbarros_nudk_osc
Merge branch 'feature/acbarros_nudk_osc' of https://github.com/abarroscs/OscLib into feature/acbarros_nudk_osc
Merge branch 'feature/acbarros_nudk_osc' of https://github.com/abarroscs/OscLib into feature/acbarros_nudk_osc
Consolidates the fixes from PR #47 onto this branch so the existing review thread stays attached to the current code. Fixes a typo introduced in #47 (Neutirno -> Neutrino). Pushed to a branch on cafana/OscLib rather than force-pushing onto Andrea's personal fork (abarroscs/OscLib) to avoid rewriting their fork history.
Strips the commented-out three-argument SolveHam overload (.cxx/.h) and its matching //int anti; member, per cullenmsullivan's review on #42. Also drops the now-stale @param anti doxygen line that documented the removed overload.
|
Went through @cullenmsullivan's review comments from #42 against the current code:
All of @cullenmsullivan's outstanding points on the old thread are addressed. Remaining open items are the cosmetic ones from my own #42 review (naming, stray includes, an incorrect class description) — will follow up on those separately. |
The class brief was updated to say 'decay oscillation calculators' but the explanatory paragraph below it still described a 'sterile oscillation calculator', copy-pasted from IOscCalcSterile.h.
|
Went through my own #42 review comments as well:
All review comments from #42 (mine and @cullenmsullivan's) are now addressed on this branch. Should be ready for a fresh look. |
They duplicate storage and getters already provided by IOscCalcAdjustable.
There was a problem hiding this comment.
I had Claude take a look at this PR also before signing off. It found a few more issues, below.
There are 3 things below (fully removing fGotES, fully removing the unused fEval/eigen-solve state, and the dead 2-flavor branch) span several non-adjacent sites, so the suggestion covers the primary edit and the comment describes the rest.
Items 1 and 2 are the most important ones before merging, since they concern uninitialized behavior, but since it's almost all just confirming that Claude's suggestions are ok and clicking "apply suggestion", hopefully it's all straightforward.
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
Co-authored-by: Jeremy Wolcott <chenel@users.noreply.github.com>
complexsolver() filled fEval with the Hamiltonian's eigenvalues, but fEval was never read anywhere (propagation uses fHam.exp() in PropagatePath instead), so every uncached energy point paid for a ComplexEigenSolver call whose result was discarded. The paired fGotES cache flag was never checked either. Removes both members, all their writers (constructors, SetIsNuBar, BuildHms), the complexsolver method itself, and the now-dead call site in SolveHam. Per @chenel's review on #48.
cullenmsullivan
left a comment
There was a problem hiding this comment.
Looks mostly good to me - my primary suggestion is to avoid using == to check for equivalence of floating point variables. I've suggested a different method that's safer.
| } | ||
|
|
||
| //--------------------------------------------------------------------------- | ||
| const IOscCalcDecay* DowncastToDecay(const IOscCalc* calc, bool quiet) |
There was a problem hiding this comment.
| const IOscCalcDecay* DowncastToDecay(const IOscCalc* calc, bool quiet) | |
| const IOscCalcDecay* OscCalcDecayTrivial::DowncastToDecay(const IOscCalc* calc, bool quiet) |
(However, it's unclear to me what the use case is, and it might be worth asking if this is even needed or whether it should belong in OscCalcDecay instead of OscCalcDecayTrivial is.)
| return nullptr; // If the cast failed, calc_decay should be nullptr anyway | ||
| } | ||
|
|
||
| IOscCalcDecay* DowncastToDecay(IOscCalc* calc, bool quiet) |
There was a problem hiding this comment.
| IOscCalcDecay* DowncastToDecay(IOscCalc* calc, bool quiet) | |
| IOscCalcDecay* OscCalcTrivial::DowncastToDecay(IOscCalc* calc, bool quiet) |
| this->SetL(810); | ||
| this->SetRho(2.74); | ||
| } | ||
| else if(fNumNus==2){ |
There was a problem hiding this comment.
This condition will never be met because, as far as I can tell, fNumNus is always initialized to 3, and there's no setter. Suggest either removing the condition or adding a setter method.
| if (i < 1 || i > fNumNus - 1 || j < 2 || j > fNumNus) { | ||
| std::cout << "Fatal Error Occurred" << std::endl; | ||
| std::cout << "Theta" << i << j << " not valid for " << fNumNus; | ||
| std::cout << " neutrinos. Abortig." << std::endl; |
There was a problem hiding this comment.
| std::cout << " neutrinos. Abortig." << std::endl; | |
| std::cout << " neutrinos. Aborting." << std::endl; |
Pedantic: fixing a typo
| abort(); | ||
| } | ||
| // Check if value is actually changing | ||
| fBuiltHms = fBuiltHms && (fTheta(i - 1,j - 1) == th); |
There was a problem hiding this comment.
| fBuiltHms = fBuiltHms && (fTheta(i - 1,j - 1) == th); | |
| fBuiltHms = fBuiltHms && (std::abs(fTheta(i - 1,j - 1) - th) <= std::numeric_limits<double>::epsilon()); |
Does this work? I thiiiiink this is unsafe - you're checking for equivalence between two floating point values using raw ==. See: https://stackoverflow.com/questions/4548004/how-to-correctly-and-standardly-compare-floats
| abort(); | ||
| } | ||
| // Check if value is actually changing | ||
| fBuiltHms = fBuiltHms && (fDelta(i - 1,j - 1) == delta); |
There was a problem hiding this comment.
| fBuiltHms = fBuiltHms && (fDelta(i - 1,j - 1) == delta); | |
| fBuiltHms = fBuiltHms && (std::abs(fDelta(i - 1,j - 1) - delta) <= std::numeric_limits<double>::epsilon()); |
Another floating point equivalence check written safer.
| return; | ||
| } | ||
| // Check if value is actually changing | ||
| fBuiltHms = fBuiltHms && (fDm(i - 1) == dm); |
There was a problem hiding this comment.
| fBuiltHms = fBuiltHms && (fDm(i - 1) == dm); | |
| fBuiltHms = fBuiltHms && (std::abs(fDm(i - 1) - dm) <= std::numeric_limits<double>::epsilon()); |
| void OscCalcDecayEigen::RotateH(int i, int j, Eigen::Matrix3cd& Ham) | ||
| { | ||
| // Do nothing if angle is zero | ||
| if (fTheta(i,j) == 0) return; |
There was a problem hiding this comment.
| if (fTheta(i,j) == 0) return; | |
| if (std::abs(fTheta(i,j)) <= std::numeric_limits<double>::epsilon()) return; |
|
|
||
| void OscCalcDecayEigen::SolveHam(double E, double Ne) | ||
| { | ||
| if(Ne!=fCachedNe || E!=fCachedE || !fBuiltHms ){ |
There was a problem hiding this comment.
| if(Ne!=fCachedNe || E!=fCachedE || !fBuiltHms ){ | |
| if(std::abs(Ne-fCachedNe) <= std::numeric_limits<double>::epsilon() || std::abs(E-fCachedE) <= std::numeric_limits<double>::epsilon() || !fBuiltHms ){ |
| #include <iostream> | ||
| #include <cassert> | ||
| #include <stdlib.h> | ||
| #include <complex> |
There was a problem hiding this comment.
| #include <complex> | |
| #include <complex> | |
| #include <cmath> | |
| #include <limits> |
There was a problem hiding this comment.
These headers are used for the safer floating point equivalence checks.
Andrea (acbarros) opened two PRs for the same nudk decay-oscillation calculator work — #42 (with the full review history from @gavinsdavies and @cullenmsullivan) and #47 (a later rebuild off main that addressed the
using namespace std;/ style feedback and fixedfIsNuBarhandling, but lost the review thread and had zero reviews of its own).This branch takes #42 as the base (preserving the review history) and applies #47's fixes on top as a single new commit, so reviewers aren't starting over. One typo introduced in #47 ("Neutirno" -> "Neutrino") was fixed along the way.
Pushed to a branch on cafana/OscLib rather than force-pushing onto Andrea's personal fork, to avoid rewriting their fork history.
Next: will work through @cullenmsullivan's remaining style comments from #42 here to help Andrea get this over the line. Closes #42 and #47 in favor of this.