11 Matrix<double,10,10>
temp = mat;
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!";
80 Eigen::initParallel();
108 for (
unsigned int ipulse=0; ipulse<
_npulsetot; ++ipulse) {
109 int bx =
_bxs.coeff(ipulse);
116 _pulsemat.col(ipulse) = fullpulse.segment<SampleVector::RowsAtCompileTime>(
offset);
124 if (!status)
return status;
129 bool foundintime =
false;
130 unsigned int ipulseintime = 0;
131 for (
unsigned int ipulse=0; ipulse<
_npulsetot; ++ipulse) {
132 if (
_bxs.coeff(ipulse)==0) {
133 ipulseintime = ipulse;
138 if (!foundintime)
return status;
140 const unsigned int ipulseintimemin = ipulseintime;
147 if (ipulseintime<
_nP) {
151 ipulseintime =
_nP - 1;
160 double xplus100 = x0 + approxerr;
161 _ampvec.coeffRef(ipulseintime) = xplus100;
163 status &=
Minimize(samplecor,pederr,fullpulsecov);
164 if (!status)
return status;
167 double sigmaplus =
std::abs(xplus100-x0)/
sqrt(chisqplus100-chisq0);
170 if ( (x0/sigmaplus) > 0.5 ) {
171 for (
unsigned int ipulse=0; ipulse<
_npulsetot; ++ipulse) {
172 if (
_bxs.coeff(ipulse)==0) {
173 ipulseintime = ipulse;
177 double xminus100 =
std::max(0.,x0-approxerr);
178 _ampvec.coeffRef(ipulseintime) = xminus100;
180 status &=
Minimize(samplecor,pederr,fullpulsecov);
181 if (!status)
return status;
184 double sigmaminus =
std::abs(xminus100-x0)/
sqrt(chisqminus100-chisq0);
185 _errvec[ipulseintimemin] = 0.5*(sigmaplus + sigmaminus);
189 _errvec[ipulseintimemin] = sigmaplus;
207 edm::LogWarning(
"PulseChiSqSNNLS::Minimize") <<
"Max Iterations reached at iter " << iter << std::endl;
211 status =
updateCov(samplecor,pederr,fullpulsecov);
217 double deltachisq = chisqnow-
_chisq;
232 const unsigned int nsample = SampleVector::RowsAtCompileTime;
233 const unsigned int npulse =
_bxs.rows();
235 const double pederr2 = pederr*pederr;
238 for (
unsigned int ipulse=0; ipulse<npulse; ++ipulse) {
239 if (
_ampvec.coeff(ipulse)==0.)
continue;
240 int bx =
_bxs.coeff(ipulse);
241 int firstsamplet =
std::max(0,bx + 3);
244 const double ampveccoef =
_ampvec.coeff(ipulse);
245 const double ampsq = ampveccoef*ampveccoef;
247 const unsigned int nsamplepulse = nsample-firstsamplet;
248 _invcov.block(firstsamplet,firstsamplet,nsamplepulse,nsamplepulse) +=
249 ampsq*fullpulsecov.block(firstsamplet+offset,firstsamplet+offset,nsamplepulse,nsamplepulse);
281 const unsigned int npulse =
_bxs.rows();
294 if (iter>0 ||
_nP==0) {
295 if (
_nP==npulse )
break;
297 const unsigned int nActive = npulse -
_nP;
300 wmax =
updatework.tail(nActive).maxCoeff(&idxwmax);
303 if (wmax<1
e-11)
break;
306 Index idxp = _nP + idxwmax;
312 std::swap(_ampvec.coeffRef(_nP),_ampvec.coeffRef(idxp));
335 if ( ampvecpermhead.minCoeff()>0. ) {
345 for (
unsigned int ipulse=0; ipulse<
_nP; ++ipulse) {
347 const double c_ampvec =
_ampvec.coeff(ipulse);
348 const double ratio = c_ampvec/(c_ampvec-
ampvecpermtest.coeff(ipulse));
349 if (ratio<minratio) {
351 minratioidx = ipulse;
356 _ampvec.head(_nP) += minratio*(ampvecpermhead -
_ampvec.head(_nP));
359 _ampvec.coeffRef(minratioidx) = 0.;
Eigen::Matrix< double, 10, 1 > SampleVector
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 10, 1 > PulseVector
PulseVector ampvecpermtest
Eigen::Matrix< double, 19, 19 > FullSampleMatrix
SamplePulseMatrix _pulsemat
const T & max(const T &a, const T &b)
bool updateCov(const SampleMatrix &samplecor, double pederr, const FullSampleMatrix &fullpulsecov)
double ComputeApproxUncertainty(unsigned int ipulse)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
SampleDecompLLT _covdecomp
Abs< T >::type abs(const T &t)
static const MaxIter maxiter
unsigned int offset(bool)
Eigen::Matrix< double, 19, 1 > FullSampleVector
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, 10, 10 > PulseMatrix
bool Minimize(const SampleMatrix &samplecor, double pederr, const FullSampleMatrix &fullpulsecov)
void eigen_solve_submatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned NP)
Eigen::Matrix< double, 10, 10 > SampleMatrix
SamplePulseMatrix invcovp
bool DoFit(const SampleVector &samples, const SampleMatrix &samplecor, double pederr, const BXVector &bxs, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov)