CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
List of all members | Public Member Functions | Private Member Functions
BlockSolver Class Reference

solves at best the matrix invertion for calibration More...

#include <BlockSolver.h>

Public Member Functions

int operator() (const CLHEP::HepMatrix &matrix, const CLHEP::HepVector &vector, CLHEP::HepVector &result)
 

Private Member Functions

void pour (CLHEP::HepVector &result, const CLHEP::HepVector &output, const std::vector< int > &where)
 pour results in bigger vector More...
 
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 More...
 

Detailed Description

solves at best the matrix invertion for calibration

Definition at line 21 of file BlockSolver.h.

Member Function Documentation

◆ operator()()

int BlockSolver::operator() ( const CLHEP::HepMatrix &  matrix,
const CLHEP::HepVector &  vector,
CLHEP::HepVector &  result 
)

Definition at line 6 of file BlockSolver.cc.

References cuy::col, mps_fire::i, input, makeMuonMisalignmentScenario::matrix, pour(), mps_fire::result, shrink(), DiMuonV_cfg::threshold, and trackerHitRTTI::vector.

6  {
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 }
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
static std::string const input
Definition: EdmProvDump.cc:50
col
Definition: cuy.py:1009
Definition: output.py:1
void pour(CLHEP::HepVector &result, const CLHEP::HepVector &output, const std::vector< int > &where)
pour results in bigger vector
Definition: BlockSolver.cc:69

◆ pour()

void BlockSolver::pour ( CLHEP::HepVector &  result,
const CLHEP::HepVector &  output,
const std::vector< int > &  where 
)
private

pour results in bigger vector

Definition at line 69 of file BlockSolver.cc.

References mps_fire::result.

Referenced by operator()().

69  {
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 }
Definition: output.py:1

◆ shrink()

void BlockSolver::shrink ( const CLHEP::HepMatrix &  matrix,
CLHEP::HepMatrix &  solution,
const CLHEP::HepVector &  result,
CLHEP::HepVector &  input,
const std::vector< int > &  where 
)
private

eliminate empty columns and rows

Definition at line 36 of file BlockSolver.cc.

References cuy::col, input, makeMuonMisalignmentScenario::matrix, and mps_fire::result.

Referenced by operator()().

40  {
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 }
static std::string const input
Definition: EdmProvDump.cc:50
col
Definition: cuy.py:1009