void CalcSchurComplement (const FlatMatrix<double> a, FlatMatrix<double> s, const BitArray & used, LocalHeap & lh) { if (s.Height() == 0) return; if (s.Height() == a.Height()) { s = a; return; } HeapReset hr(lh); int n = a.Height(); Array<int> used_dofs(n, lh); Array<int> unused_dofs(n, lh); used_dofs.SetSize(0); unused_dofs.SetSize(0); for (int i = 0; i < n; i++) if (used[i]) used_dofs.Append(i); else unused_dofs.Append(i); s = a.Rows(used_dofs).Cols(used_dofs); FlatMatrix<> b1 = a.Rows(unused_dofs).Cols(used_dofs) | lh; FlatMatrix<> b2 = a.Rows(used_dofs).Cols(unused_dofs) | lh; FlatMatrix<> c = a.Rows(unused_dofs).Cols(unused_dofs) | lh; FlatMatrix<> hb1 (b1.Height(), b1.Width(), lh); if (n > 10) { LapackInverse (c); hb1 = c * b1 | Lapack; s -= b2 * hb1 | Lapack; } else { CalcInverse (c); hb1 = c * b1; s -= b2 * hb1; } }
int main() { float fixedphase_ns = 6.0; float max_fracerror = 0.02; std::auto_ptr<HcalPulseContainmentManager> manager; manager = std::auto_ptr<HcalPulseContainmentManager>( new HcalPulseContainmentManager(max_fracerror)); HcalDetId hb1(HcalBarrel, 1, 1, 1); HcalDetId he1(HcalEndcap, 17, 1, 1); double fc = 10.; // test re-finding the correction double corr1 = manager->correction(hb1, 4, fixedphase_ns, fc); double corr2 = manager->correction(hb1, 4, fixedphase_ns, fc); assert(corr1 == corr2); // fewer toAdd means bigger correction double corr3 = manager->correction(hb1, 2, fixedphase_ns, fc); assert(corr3 > corr1); // HB and HE have the same shape here double corr4 = manager->correction(he1, 4, fixedphase_ns, fc); assert(corr4 == corr1); std::cout << corr1 << " " <<corr2 << " " <<corr3 << " " <<corr4 << " " << std::endl; return 0; }