CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BlockSolver.cc
Go to the documentation of this file.
1 
10 int
11 BlockSolver::operator () (const CLHEP::HepMatrix & matrix,
12  const CLHEP::HepVector & vector,
13  CLHEP::HepVector & result)
14 {
15  double threshold = matrix.trace () /
16  static_cast<double> (matrix.num_row ()) ;
17  std::vector<int> holes ;
18  // loop over the matrix rows
19  for (int row = 0 ; row < matrix.num_row () ; ++row)
20  {
21  double sumAbs = 0. ;
22  for (int col = 0 ; col < matrix.num_col () ; ++col)
23  sumAbs += fabs (matrix[row][col]) ;
24  if (sumAbs < threshold) holes.push_back (row) ;
25  } // loop over the matrix rows
26 
27  int dim = matrix.num_col () - holes.size () ;
28 
29  if (holes.size () == 0) //PG exceptional case!
30  {
31  for (int i = 0 ; i < result.num_row () ; ++i)
32  result[i] = 1. ;
33  }
34  else if (dim > 0)
35  {
36  CLHEP::HepMatrix solution (dim, dim, 0) ;
37  CLHEP::HepVector input (dim, 0) ;
38  shrink (matrix, solution, vector, input, holes) ;
39  CLHEP::HepVector output = solve (solution,input) ;
40  pour (result, output, holes) ;
41  }
42  return holes.size () ;
43 }
44 
45 
46 // ------------------------------------------------------------
47 
48 
49 void
50 BlockSolver::shrink (const CLHEP::HepMatrix & matrix,
51  CLHEP::HepMatrix & solution,
52  const CLHEP::HepVector & result,
53  CLHEP::HepVector & input,
54  const std::vector<int> & where)
55 {
56 
57  int offsetRow = 0 ;
58  std::vector<int>::const_iterator whereRows = where.begin () ;
59  // loop over rows
60  for (int row = 0 ; row < matrix.num_row () ; ++row)
61  {
62  if (row == *whereRows)
63  {
64 // std::cerr << " DEBUG shr hole found " << std::endl ;
65  ++offsetRow ;
66  ++whereRows ;
67  continue ;
68  }
69  input[row-offsetRow] = result[row] ;
70  int offsetCol = 0 ;
71  std::vector<int>::const_iterator whereCols = where.begin () ;
72  // loop over columns
73  for (int col = 0 ; col < matrix.num_col () ; ++col)
74  {
75  if (col == *whereCols)
76  {
77  ++offsetCol ;
78  ++whereCols ;
79  continue ;
80  }
81  solution[row-offsetRow][col-offsetCol] = matrix[row][col] ;
82  }
83  } // loop over rows
84  return ;
85 }
86 
87 
88 // ------------------------------------------------------------
89 
90 
91 void
92 BlockSolver::pour (CLHEP::HepVector & result,
93  const CLHEP::HepVector & output,
94  const std::vector<int> & where)
95 {
96  std::vector<int>::const_iterator whereCols = where.begin () ;
97  int readingIndex = 0 ;
98  //PG loop over the output crystals
99  for (int xtal = 0 ; xtal < result.num_row () ; ++xtal)
100  {
101  if (xtal == *whereCols)
102  {
103  result[xtal] = 1. ;
104  ++whereCols ;
105  }
106  else
107  {
108  result[xtal] = output[readingIndex] ;
109  ++readingIndex ;
110  }
111  } //PG loop over the output crystals
112 
113  return ;
114 }
115 
int i
Definition: DBlmapReader.cc:9
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:50
int operator()(const CLHEP::HepMatrix &matrix, const CLHEP::HepVector &vector, CLHEP::HepVector &result)
Definition: BlockSolver.cc:11
tuple result
Definition: query.py:137
void pour(CLHEP::HepVector &result, const CLHEP::HepVector &output, const std::vector< int > &where)
pour results in bigger vector
Definition: BlockSolver.cc:92