11 Matrix<double,10,10>
temp = mat.topLeftCorner<10,10>();
12 outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
17 Matrix<double,9,9>
temp = mat.topLeftCorner<9,9>();
18 outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
23 Matrix<double,8,8>
temp = mat.topLeftCorner<8,8>();
24 outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
29 Matrix<double,7,7>
temp = mat.topLeftCorner<7,7>();
30 outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
35 Matrix<double,6,6>
temp = mat.topLeftCorner<6,6>();
36 outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
41 Matrix<double,5,5>
temp = mat.topLeftCorner<5,5>();
42 outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
47 Matrix<double,4,4>
temp = mat.topLeftCorner<4,4>();
48 outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
53 Matrix<double,3,3>
temp = mat.topLeftCorner<3,3>();
54 outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
59 Matrix<double,2,2>
temp = mat.topLeftCorner<2,2>();
60 outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
65 Matrix<double,1,1>
temp = mat.topLeftCorner<1,1>();
66 outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
71 <<
"Weird number of pulses encountered in multifit, module is configured incorrectly!";
79 _maxiterwarnings(
true)
90 int npulse = bxs.rows();
97 int ngains = gains.maxCoeff()+1;
99 for (
int gainidx=0; gainidx<
ngains; ++gainidx) {
102 if (pedestal.maxCoeff()>0.) {
105 _bxs[npulse+nPedestals-1] = 100 + gainidx;
106 _pulsemat.resize(Eigen::NoChange, npulse+nPedestals);
112 for (
int isample=0; isample<SampleVector::RowsAtCompileTime; ++isample) {
113 if (badSamples.coeff(isample)>0) {
120 _bxs[npulse+nPedestals-1] = -100 - isample;
121 _pulsemat.resize(Eigen::NoChange, npulse+nPedestals);
140 for (
int ipulse=0; ipulse<npulse; ++ipulse) {
141 int bx =
_bxs.coeff(ipulse);
143 _pulsemat.col(ipulse) = fullpulse.segment<SampleVector::RowsAtCompileTime>(
offset);
148 for (
int i=0;
i<
_bxs.rows(); ++
i) {
149 int bx =
_bxs.coeff(
i);
161 if (!status)
return status;
166 bool foundintime =
false;
167 unsigned int ipulseintime = 0;
168 for (
unsigned int ipulse=0; ipulse<
_npulsetot; ++ipulse) {
169 if (
_bxs.coeff(ipulse)==0) {
170 ipulseintime = ipulse;
175 if (!foundintime)
return status;
177 const unsigned int ipulseintimemin = ipulseintime;
184 if (ipulseintime<
_nP) {
188 ipulseintime =
_nP - 1;
197 double xplus100 = x0 + approxerr;
198 _ampvec.coeffRef(ipulseintime) = xplus100;
200 status &=
Minimize(samplecov,fullpulsecov);
201 if (!status)
return status;
204 double sigmaplus =
std::abs(xplus100-x0)/
sqrt(chisqplus100-chisq0);
207 if ( (x0/sigmaplus) > 0.5 ) {
208 for (
unsigned int ipulse=0; ipulse<
_npulsetot; ++ipulse) {
209 if (
_bxs.coeff(ipulse)==0) {
210 ipulseintime = ipulse;
214 double xminus100 =
std::max(0.,x0-approxerr);
215 _ampvec.coeffRef(ipulseintime) = xminus100;
217 status &=
Minimize(samplecov,fullpulsecov);
218 if (!status)
return status;
221 double sigmaminus =
std::abs(xminus100-x0)/
sqrt(chisqminus100-chisq0);
222 _errvec[ipulseintimemin] = 0.5*(sigmaplus + sigmaminus);
226 _errvec[ipulseintimemin] = sigmaplus;
237 const unsigned int npulse =
_bxs.rows();
245 LogDebug(
"PulseChiSqSNNLS::Minimize") <<
"Max Iterations reached at iter " << iter;
250 status =
updateCov(samplecov,fullpulsecov);
262 double deltachisq = chisqnow-
_chisq;
277 const unsigned int nsample = SampleVector::RowsAtCompileTime;
278 const unsigned int npulse =
_bxs.rows();
282 for (
unsigned int ipulse=0; ipulse<npulse; ++ipulse) {
283 if (
_ampvec.coeff(ipulse)==0.)
continue;
284 int bx =
_bxs.coeff(ipulse);
287 int firstsamplet =
std::max(0,bx + 3);
290 const double ampveccoef =
_ampvec.coeff(ipulse);
291 const double ampsq = ampveccoef*ampveccoef;
293 const unsigned int nsamplepulse = nsample-firstsamplet;
294 _invcov.block(firstsamplet,firstsamplet,nsamplepulse,nsamplepulse) +=
295 ampsq*fullpulsecov.block(firstsamplet+offset,firstsamplet+offset,nsamplepulse,nsamplepulse);
327 const unsigned int npulse =
_bxs.rows();
328 constexpr unsigned int nsamples = SampleVector::RowsAtCompileTime;
340 if (iter>0 ||
_nP==0) {
343 const unsigned int nActive = npulse -
_nP;
346 Index idxwmaxprev = idxwmax;
347 double wmaxprev = wmax;
348 wmax =
updatework.tail(nActive).maxCoeff(&idxwmax);
351 if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev))
break;
355 LogDebug(
"PulseChiSqSNNLS::NNLS()") <<
"Max Iterations reached at iter " << iter;
360 Index idxp = _nP + idxwmax;
378 bool positive =
true;
379 for (
unsigned int i = 0;
i <
_nP; ++
i)
391 for (
unsigned int ipulse=0; ipulse<
_nP; ++ipulse) {
393 const double c_ampvec =
_ampvec.coeff(ipulse);
395 if (ratio<minratio) {
397 minratioidx = ipulse;
405 _ampvec.coeffRef(minratioidx) = 0.;
414 if (iter % 16 == 0) {
458 _ampvec.coeffRef(0) =
std::max(0.,aTbvecval.coeff(0)/aTamatval.coeff(0));
void NNLSUnconstrainParameter(Index idxp)
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())
SamplePulseMatrix _pulsemat
Eigen::Matrix< char, SampleVectorSize, 1 > SampleGainVector
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
double ComputeApproxUncertainty(unsigned int ipulse)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Eigen::Matrix< double, 1, 1 > SingleVector
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)
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
void resize(int bx, unsigned size)
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
void eigen_solve_submatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned NP)
Eigen::Matrix< double, 1, 1 > SingleMatrix
void NNLSConstrainParameter(Index minratioidx)
SamplePulseMatrix invcovp
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix