11 using namespace tauImpactParameter;
14 : isConfigured_(
false),
40 <<
"Reached Maximum number of iterations..." <<
niter_ << std::endl;
57 TVectorT<double> alpha_A =
par_;
58 TVectorT<double> alpha_0 =
par_0_;
59 TVectorT<double> delta_alpha_A = alpha_A - alpha_0;
62 TVectorT<double>
C =
D_ * delta_alpha_A -
d;
63 TMatrixTSym<double> V_alpha0 =
cov_0_;
64 TMatrixTSym<double> V_D_inv = V_alpha0;
65 V_D_inv.Similarity(
D_);
66 double det = V_D_inv.Determinant();
67 TDecompBK Inverter(V_D_inv);
68 if (fabs(det) > 1e40) {
70 <<
"Fit failed: unable to invert SYM gain matrix LARGE Determinant" << det <<
" \n"
74 if (!Inverter.Decompose()) {
75 edm::LogWarning(
"LagrangeMultipliersFitter::Fit") <<
"Fit failed: unable to invert SYM gain matrix " << det <<
" \n"
79 V_D_ = Inverter.Invert();
82 TVectorT<double> lambda = -1.0 *
V_D_ *
C;
83 TMatrixT<double>
DT =
D_;
85 TVectorT<double>
alpha = alpha_0 - V_alpha0 * DT * lambda;
88 double s(1), stepscale(0.01);
91 TVectorT<double> alpha_s =
alpha;
98 int NIter = (int)(1.0 / stepscale);
99 for (
int iter = 0; iter < NIter; iter++) {
102 for (
int l = 0;
l < alpha_s.GetNrows();
l++) {
103 if (diff < alpha_s(
l) - alpha_A(
l))
104 diff = alpha_s(
l) - alpha_A(
l);
108 if (delta_alpha_s < currentdelta || iter == NIter || diff < 100 *
epsilon_) {
110 currentdelta = delta_alpha_s;
116 if ((delta_alpha_s < currentdelta && chi2_s < currentchi2) || iter == NIter ||
118 currentchi2 = chi2_s;
119 currentdelta = delta_alpha_s;
125 alpha_s = alpha_A +
s * (alpha - alpha_A);
137 TVectorD par_plus(
par_.GetNrows());
140 for (
int j = 0;
j <
par_.GetNrows();
j++) {
141 for (
int i = 0;
i <
par_.GetNrows();
i++) {
147 value_par_plus =
value(par_plus);
163 const TVectorT<double>& lambda,
164 const TMatrixT<double>&
D,
165 const TVectorT<double>&
d) {
166 double c2 = lambda * (D * delta_alpha +
d);
171 const TVectorT<double>& lambda) {
173 TMatrixTSym<double> V_alpha0 =
cov_0_;
175 TDecompBK Inverter(V_alpha0);
176 if (!Inverter.Decompose()) {
177 edm::LogWarning(
"LagrangeMultipliersFitter::chiSquareUsingInitalPoint")
178 <<
"Error non-invertable Matrix... Calculating under assumption that correlations can be neglected!!!"
180 for (
int j = 0;
j <
par_.GetNrows();
j++) {
181 for (
int i = 0;
i <
par_.GetNrows();
i++) {
193 TVectorT<double> alpha_0 =
par_0_;
194 TVectorT<double> dalpha = alpha - alpha_0;
196 const TVectorT<double>& alpha_v =
alpha;
197 double c2_constraints = lambda *
value(alpha_v);
198 double c2 = c2_var + c2_constraints;
203 TVectorD d_par =
value(par);
205 for (
int i = 0;
i < d_par.GetNrows();
i++) {
206 delta_d += fabs(d_par(
i));
212 TMatrixTSym<double> V_alpha0 =
cov_0_;
213 TMatrixTSym<double> DTV_DD =
V_D_.SimilarityT(
D_);
214 TMatrixT<double> DTV_DDV = DTV_DD * V_alpha0;
215 TMatrixT<double> VDTV_DDV = V_alpha0 * DTV_DDV;
216 TMatrixT<double> CovCor = VDTV_DDV;
219 V_corr_prev_.ResizeTo(V_alpha0.GetNrows(), V_alpha0.GetNrows());
227 TMatrixT<double> V_alpha = V_alpha0 - CovCor;
228 for (
int i = 0;
i <
cov_.GetNrows();
i++) {
229 for (
int j = 0;
j <=
i;
j++) {
TMatrixTSym< double > cov_0_
virtual TVectorD value(const TVectorD &v)=0
bool applyLagrangianConstraints()
TMatrixT< double > V_corr_prev_
virtual bool isConverged()
virtual double chiSquare()
TMatrixTSym< double > V_alpha0_inv_
TMatrixTSym< double > cov_
virtual double nConstraints()=0
DecomposeProduct< arg, typename Div::arg > D
LagrangeMultipliersFitter()
double chiSquareUsingInitalPoint(const TVectorT< double > &alpha, const TVectorT< double > &lambda)
TMatrixTSym< double > V_D_
double constraintDelta(const TVectorT< double > &par)
AlgebraicMatrix Derivatives
TMatrixT< double > computeVariance()
Log< level::Warning, false > LogWarning
TMatrixT< double > derivative()