16#include "fairlogger/Logger.h"
26constexpr Double_t ROW_RANK_TOL{1.0E-9};
28constexpr Double_t CONTRADICTION_TOL{1.0E-9};
74 const TVectorD& acc{accA ? *accA : zero};
85 const Double_t w{1.0 / (s * s)}, own{p.IsComposite() ? acc(p.full) : acc(p.full) - vJP[p.full]};
86 mC(p.full, p.full) += w;
87 vB[p.full] += w * (
ref[p.full] - own);
108 std::vector<TVectorD> basis;
110 Int_t contradictions{0};
116 for (std::size_t
m = 0;
m < basis.size();
m++) {
118 Add(res, -d, basis[
m]);
119 resRhs -= d * basisRhs[
m];
122 if (resNorm > ROW_RANK_TOL * rowNorm) {
123 basis.push_back((1.0 / resNorm) * res);
124 basisRhs.push_back(resRhs / resNorm);
128 const Double_t scale{rowNorm > 0.0 ? rowNorm : 1.0};
129 if (std::fabs(resRhs) <= CONTRADICTION_TOL * scale)
131 LOG(error) <<
Form(
" <!> BmnAlignPriors::Check: constraint row #%d asks for a value %.2e off what the"
132 " constraints before it give (or has an all-zero LHS with a non-zero RHS)",
133 j + 1, resRhs / scale);
136 if (contradictions) {
137 LOG(error) <<
" <!> BmnAlignPriors::Check: " << contradictions <<
" contradicting constraint(s)";
144 <<
" dropped as empty or repeated";
180 probe(p.full, p.comp) = 1.0;
190 if (!probe.NonZeros()) {
191 LOG(error) <<
" <!> none of the " << nComp
192 <<
" composite parameter(s) is"
193 " determined: neither a presigma nor a composite-addressed"
194 " constraint was given, so the split between the levels rests"
195 " on nothing at all";
200 LOG(error) <<
" <!> BmnAlignPriors::Check: SVD failed, solvability not verified";
204 constexpr static const Double_t RANK_TOL{1.0E-9};
206 while (rank < sig.
GetNrows() && sig[rank] > sig[0] * RANK_TOL)
210 LOG(info) <<
" hierarchy check: all " << nComp
211 <<
" composite parameter(s) determined by priors and constraints";
221 LOG(error) <<
" <!> " << nComp - rank <<
" of " << nComp
222 <<
" composite parameter direction(s) left undetermined -"
223 " the fit would be singular along them:";
224 for (
Int_t d = rank; d < nComp; d++) {
225 std::vector<std::pair<Double_t, Int_t>> weight;
226 weight.reserve(nComp);
227 for (
Int_t a = 0; a < nComp; a++)
228 weight.emplace_back(std::fabs(V(a, d)), a);
229 std::sort(weight.rbegin(), weight.rend());
231 for (
Int_t t = 0; t < nComp && weight[t].first > 0.1; t++)
232 descr +=
Form(
"%s%+.2f x [%s]", descr.
IsNull() ?
"" :
" ", V(weight[t].second, d),
234 LOG(error) <<
" " << descr;
236 LOG(error) <<
" give the composites involved a presigma (NodeName entry) or a"
237 " NodeName constraint - leaf-addressed constraints cannot fix a"
238 " composite split, and a leaf presigma only reaches the combinations"
239 " that move its own element";
std::vector< Double_t > VecDouble_t
Double_t Dot(const TGLVector3 &v1, const TGLVector3 &v2)
TMatrixTRow< Double_t > TMatrixDRow
TMatrixTRow_const< Double_t > TMatrixDRow_const
TMatrixT< Double_t > TMatrixD
TMatrixTSparse< Element > & Add(TMatrixTSparse< Element > &target, Element scalar, const TMatrixTSparse< Element > &source)
char * Form(const char *fmt,...)
TVectorT< Double_t > TVectorD
const TMatrixD & J() const noexcept
Int_t LeafParams() const noexcept
Int_t AllParams() const noexcept
const BmnParamLayout & Layout() const noexcept
Int_t CompositeParams() const noexcept
Int_t CompositeParamBase() const noexcept
TMatrixD PromoteConstraints(const TMatrixD &constraints) const
Double_t SigmaAt(Int_t full) const noexcept
void Apply(TVectorD &vB, TMatrixD &mC, const BmnAlignHierarchy &hierarchy, const TVectorD *accA) const
Bool_t Check(const BmnAlignHierarchy &hierarchy)
Bool_t UsePresigmas() const noexcept
Int_t KeptCount() const noexcept
Int_t ConstCount() const noexcept
const Range_t & All() const noexcept
const Range_t & Composites() const noexcept
const TVectorD & GetSig()
Bool_t Decompose() override
TMatrixTBase< Element > & SetSub(Int_t row_lwb, Int_t col_lwb, const TMatrixTBase< Element > &source) override
TVectorT< Element > GetSub(Int_t row_lwb, Int_t row_upb, Option_t *option="S") const