CMS 3D CMS Logo

BlockSolver.cc
Go to the documentation of this file.
1 
6 int BlockSolver::operator()(const CLHEP::HepMatrix& matrix, const CLHEP::HepVector& vector, CLHEP::HepVector& result) {
7  double threshold = matrix.trace() / static_cast<double>(matrix.num_row());
8  std::vector<int> holes;
9  // loop over the matrix rows
10  for (int row = 0; row < matrix.num_row(); ++row) {
11  double sumAbs = 0.;
12  for (int col = 0; col < matrix.num_col(); ++col)
13  sumAbs += fabs(matrix[row][col]);
14  if (sumAbs < threshold)
15  holes.push_back(row);
16  } // loop over the matrix rows
17 
18  int dim = matrix.num_col() - holes.size();
19 
20  if (holes.empty()) //PG exceptional case!
21  {
22  for (int i = 0; i < result.num_row(); ++i)
23  result[i] = 1.;
24  } else if (dim > 0) {
25  CLHEP::HepMatrix solution(dim, dim, 0);
26  CLHEP::HepVector input(dim, 0);
27  shrink(matrix, solution, vector, input, holes);
28  CLHEP::HepVector output = solve(solution, input);
29  pour(result, output, holes);
30  }
31  return holes.size();
32 }
33 
34 // ------------------------------------------------------------
35 
36 void BlockSolver::shrink(const CLHEP::HepMatrix& matrix,
37  CLHEP::HepMatrix& solution,
38  const CLHEP::HepVector& result,
39  CLHEP::HepVector& input,
40  const std::vector<int>& where) {
41  int offsetRow = 0;
42  std::vector<int>::const_iterator whereRows = where.begin();
43  // loop over rows
44  for (int row = 0; row < matrix.num_row(); ++row) {
45  if (row == *whereRows) {
46  // std::cerr << " DEBUG shr hole found " << std::endl ;
47  ++offsetRow;
48  ++whereRows;
49  continue;
50  }
51  input[row - offsetRow] = result[row];
52  int offsetCol = 0;
53  std::vector<int>::const_iterator whereCols = where.begin();
54  // loop over columns
55  for (int col = 0; col < matrix.num_col(); ++col) {
56  if (col == *whereCols) {
57  ++offsetCol;
58  ++whereCols;
59  continue;
60  }
61  solution[row - offsetRow][col - offsetCol] = matrix[row][col];
62  }
63  } // loop over rows
64  return;
65 }
66 
67 // ------------------------------------------------------------
68 
69 void BlockSolver::pour(CLHEP::HepVector& result, const CLHEP::HepVector& output, const std::vector<int>& where) {
70  std::vector<int>::const_iterator whereCols = where.begin();
71  int readingIndex = 0;
72  //PG loop over the output crystals
73  for (int xtal = 0; xtal < result.num_row(); ++xtal) {
74  if (xtal == *whereCols) {
75  result[xtal] = 1.;
76  ++whereCols;
77  } else {
78  result[xtal] = output[readingIndex];
79  ++readingIndex;
80  }
81  } //PG loop over the output crystals
82 
83  return;
84 }
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
BlockSolver::shrink
void shrink(const CLHEP::HepMatrix &matrix, CLHEP::HepMatrix &solution, const CLHEP::HepVector &result, CLHEP::HepVector &input, const std::vector< int > &where)
eliminate empty columns and rows
Definition: BlockSolver.cc:36
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
BlockSolver.h
cuy.col
col
Definition: cuy.py:1009
BlockSolver::pour
void pour(CLHEP::HepVector &result, const CLHEP::HepVector &output, const std::vector< int > &where)
pour results in bigger vector
Definition: BlockSolver.cc:69
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
BlockSolver::operator()
int operator()(const CLHEP::HepMatrix &matrix, const CLHEP::HepVector &vector, CLHEP::HepVector &result)
Definition: BlockSolver.cc:6
mps_fire.result
result
Definition: mps_fire.py:311
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430