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 edm::LogWarning(
"PulseChiSqSNNLS::Minimize") <<
"Max Iterations reached at iter " << iter << std::endl;
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;
341 if (iter>0 ||
_nP==0) {
344 const unsigned int nActive = npulse -
_nP;
347 Index idxwmaxprev = idxwmax;
348 double wmaxprev = wmax;
349 wmax =
updatework.tail(nActive).maxCoeff(&idxwmax);
352 if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev))
break;
356 edm::LogWarning(
"PulseChiSqSNNLS::NNLS()") <<
"Max Iterations reached at iter " << iter << std::endl;
361 Index idxp = _nP + idxwmax;
380 if ( ampvecpermhead.minCoeff()>0. ) {
390 for (
unsigned int ipulse=0; ipulse<
_nP; ++ipulse) {
392 const double c_ampvec =
_ampvec.coeff(ipulse);
394 if (ratio<minratio) {
396 minratioidx = ipulse;
401 _ampvec.head(_nP) += minratio*(ampvecpermhead -
_ampvec.head(_nP));
404 _ampvec.coeffRef(minratioidx) = 0.;
457 _ampvec.coeffRef(0) =
std::max(0.,aTbvecval.coeff(0)/aTamatval.coeff(0));
void NNLSUnconstrainParameter(Index idxp)
Eigen::Matrix< char, SampleVectorSize, 1 > SampleGainVector
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
Eigen::Matrix< double, SampleVectorSize, 1 > SampleVector
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
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
SamplePulseMatrix _pulsemat
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)
void resize(int bx, unsigned size)
void eigen_solve_submatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned NP)
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
Eigen::Matrix< double, 1, 1 > SingleMatrix
void NNLSConstrainParameter(Index minratioidx)
SamplePulseMatrix invcovp