10 Matrix<double, 10, 10>
temp = mat.topLeftCorner<10, 10>();
11 outvec.head<10>() =
temp.ldlt().solve(invec.head<10>());
14 Matrix<double, 9, 9>
temp = mat.topLeftCorner<9, 9>();
15 outvec.head<9>() =
temp.ldlt().solve(invec.head<9>());
18 Matrix<double, 8, 8>
temp = mat.topLeftCorner<8, 8>();
19 outvec.head<8>() =
temp.ldlt().solve(invec.head<8>());
22 Matrix<double, 7, 7>
temp = mat.topLeftCorner<7, 7>();
23 outvec.head<7>() =
temp.ldlt().solve(invec.head<7>());
26 Matrix<double, 6, 6>
temp = mat.topLeftCorner<6, 6>();
27 outvec.head<6>() =
temp.ldlt().solve(invec.head<6>());
30 Matrix<double, 5, 5>
temp = mat.topLeftCorner<5, 5>();
31 outvec.head<5>() =
temp.ldlt().solve(invec.head<5>());
34 Matrix<double, 4, 4>
temp = mat.topLeftCorner<4, 4>();
35 outvec.head<4>() =
temp.ldlt().solve(invec.head<4>());
38 Matrix<double, 3, 3>
temp = mat.topLeftCorner<3, 3>();
39 outvec.head<3>() =
temp.ldlt().solve(invec.head<3>());
42 Matrix<double, 2, 2>
temp = mat.topLeftCorner<2, 2>();
43 outvec.head<2>() =
temp.ldlt().solve(invec.head<2>());
46 Matrix<double, 1, 1>
temp = mat.topLeftCorner<1, 1>();
47 outvec.head<1>() =
temp.ldlt().solve(invec.head<1>());
51 <<
"Weird number of pulses encountered in multifit, module is configured incorrectly!";
66 int npulse = bxs.rows();
70 _pulsemat.resize(Eigen::NoChange, npulse);
73 int ngains =
gains.maxCoeff() + 1;
75 for (
int gainidx = 0; gainidx < ngains; ++gainidx) {
81 _bxs[npulse + nPedestals - 1] = 100 + gainidx;
82 _pulsemat.resize(Eigen::NoChange, npulse + nPedestals);
88 for (
int isample = 0; isample < SampleVector::RowsAtCompileTime; ++isample) {
89 if (badSamples.coeff(isample) > 0) {
96 _bxs[npulse + nPedestals - 1] =
98 _pulsemat.resize(Eigen::NoChange, npulse + nPedestals);
117 for (
int ipulse = 0; ipulse < npulse; ++ipulse) {
118 int bx =
_bxs.coeff(ipulse);
120 _pulsemat.col(ipulse) = fullpulse.segment<SampleVector::RowsAtCompileTime>(
offset);
124 if (nPedestals > 0) {
125 for (
int i = 0;
i <
_bxs.rows(); ++
i) {
145 bool foundintime =
false;
146 unsigned int ipulseintime = 0;
147 for (
unsigned int ipulse = 0; ipulse <
_npulsetot; ++ipulse) {
148 if (
_bxs.coeff(ipulse) == 0) {
149 ipulseintime = ipulse;
157 const unsigned int ipulseintimemin = ipulseintime;
164 if (ipulseintime <
_nP) {
168 ipulseintime =
_nP - 1;
176 double xplus100 = x0 + approxerr;
177 _ampvec.coeffRef(ipulseintime) = xplus100;
184 double sigmaplus =
std::abs(xplus100 - x0) /
sqrt(chisqplus100 - chisq0);
187 if ((x0 / sigmaplus) > 0.5) {
188 for (
unsigned int ipulse = 0; ipulse <
_npulsetot; ++ipulse) {
189 if (
_bxs.coeff(ipulse) == 0) {
190 ipulseintime = ipulse;
194 double xminus100 =
std::max(0., x0 - approxerr);
195 _ampvec.coeffRef(ipulseintime) = xminus100;
202 double sigmaminus =
std::abs(xminus100 - x0) /
sqrt(chisqminus100 - chisq0);
203 _errvec[ipulseintimemin] = 0.5 * (sigmaplus + sigmaminus);
206 _errvec[ipulseintimemin] = sigmaplus;
215 const unsigned int npulse =
_bxs.rows();
222 LogDebug(
"PulseChiSqSNNLS::Minimize") <<
"Max Iterations reached at iter " << iter;
240 double deltachisq = chisqnow -
_chisq;
253 const unsigned int nsample = SampleVector::RowsAtCompileTime;
254 const unsigned int npulse =
_bxs.rows();
258 for (
unsigned int ipulse = 0; ipulse < npulse; ++ipulse) {
259 if (
_ampvec.coeff(ipulse) == 0.)
261 int bx =
_bxs.coeff(ipulse);
268 const double ampveccoef =
_ampvec.coeff(ipulse);
269 const double ampsq = ampveccoef * ampveccoef;
271 const unsigned int nsamplepulse = nsample - firstsamplet;
272 _invcov.block(firstsamplet, firstsamplet, nsamplepulse, nsamplepulse) +=
273 ampsq * fullpulsecov.block(firstsamplet +
offset, firstsamplet +
offset, nsamplepulse, nsamplepulse);
300 const unsigned int npulse =
_bxs.rows();
301 constexpr unsigned int nsamples = SampleVector::RowsAtCompileTime;
313 if (iter > 0 ||
_nP == 0) {
317 const unsigned int nActive = npulse -
_nP;
320 Index idxwmaxprev = idxwmax;
321 double wmaxprev =
wmax;
330 LogDebug(
"PulseChiSqSNNLS::NNLS()") <<
"Max Iterations reached at iter " << iter;
353 bool positive =
true;
354 for (
unsigned int i = 0;
i <
_nP; ++
i)
362 Index minratioidx = 0;
366 for (
unsigned int ipulse = 0; ipulse <
_nP; ++ipulse) {
368 const double c_ampvec =
_ampvec.coeff(ipulse);
370 if (
ratio < minratio) {
372 minratioidx = ipulse;
380 _ampvec.coeffRef(minratioidx) = 0.;
389 if (iter % 16 == 0) {
428 _ampvec.coeffRef(0) =
std::max(0., aTbvecval.coeff(0) / aTamatval.coeff(0));
void NNLSUnconstrainParameter(Index idxp)
Eigen::Matrix< double, 1, 1 > SingleVector
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
PulseVector ampvecpermtest
bool DoFit(const SampleVector &samples, const SampleMatrix &samplecov, const BXVector &bxs, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const SampleGainVector &gains=-1 *SampleGainVector::Ones(), const SampleGainVector &badSamples=SampleGainVector::Zero())
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
void swap(Association< C > &lhs, Association< C > &rhs)
SamplePulseMatrix _pulsemat
double ComputeApproxUncertainty(unsigned int ipulse)
SampleDecompLLT _covdecomp
Abs< T >::type abs(const T &t)
bool updateCov(const SampleMatrix &samplecov, const FullSampleMatrix &fullpulsecov)
bool Minimize(const SampleMatrix &samplecov, const FullSampleMatrix &fullpulsecov)
constexpr float gains[NGAINS]
void resize(int bx, unsigned size)
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
Eigen::Matrix< char, SampleVectorSize, 1 > SampleGainVector
void eigen_solve_submatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned NP)
Eigen::Matrix< double, 1, 1 > SingleMatrix
void NNLSConstrainParameter(Index minratioidx)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
SamplePulseMatrix invcovp
__host__ __device__ V V wmax