Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcSpaceChargeMatrixContainerv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcSpaceChargeMatrixContainerv1.cc
1 
10 
11 //___________________________________________________________
13 {
14  // reset all matrix arrays
16 }
17 
18 //___________________________________________________________
20 {
21  out << "TpcSpaceChargeMatrixContainerv1" << std::endl;
22  out << " phibins: " << m_phibins << std::endl;
23  out << " rbins: " << m_rbins << std::endl;
24  out << " zbins: " << m_zbins << std::endl;
25 }
26 
27 //___________________________________________________________
28 void TpcSpaceChargeMatrixContainerv1::get_grid_dimensions( int& phibins, int& rbins, int& zbins ) const
29 {
30  phibins = m_phibins;
31  rbins = m_rbins;
32  zbins = m_zbins;
33 }
34 
35 //___________________________________________________________
37 { return m_phibins*m_rbins*m_zbins; }
38 
39 //___________________________________________________________
40 int TpcSpaceChargeMatrixContainerv1::get_cell_index( int iphi, int ir, int iz ) const
41 {
42  if( iphi < 0 || iphi >= m_phibins ) return -1;
43  if( ir < 0 || ir >= m_rbins ) return -1;
44  if( iz < 0 || iz >= m_zbins ) return -1;
45  return iz + m_zbins*( ir + m_rbins*iphi );
46 }
47 
48 //___________________________________________________________
50 {
51  // bound check
52  if( !bound_check( cell_index ) ) return 0;
53  return m_entries[cell_index];
54 }
55 
56 //___________________________________________________________
57 float TpcSpaceChargeMatrixContainerv1::get_lhs( int cell_index, int i, int j ) const
58 {
59  // bound check
60  if( !bound_check( cell_index, i, j ) ) return 0;
61  return m_lhs[cell_index][get_flat_index(i, j)];
62 }
63 
64 //___________________________________________________________
65 float TpcSpaceChargeMatrixContainerv1::get_rhs( int cell_index, int i ) const
66 {
67  // bound check
68  if( !bound_check( cell_index, i ) ) return 0;
69  return m_rhs[cell_index][i];
70 }
71 
72 //___________________________________________________________
74 {
75  // reset total number of bins
76  const int totalbins = m_phibins*m_rbins*m_zbins;
77 
78  // reset arrays
79  m_entries = std::vector<int>( totalbins, 0 );
80  m_lhs = std::vector<matrix_t>( totalbins, {{}} );
81  m_rhs = std::vector<column_t>( totalbins, {{}} );
82 }
83 
84 //___________________________________________________________
86 {
88  m_rbins = rbins;
89  m_zbins = zbins;
90  Reset();
91 }
92 
93 //___________________________________________________________
95 {
96  if( bound_check( cell_index ) )
97  { m_entries[cell_index] += value; }
98 }
99 
100 //___________________________________________________________
101 void TpcSpaceChargeMatrixContainerv1::add_to_lhs( int cell_index, int i, int j, float value )
102 {
103  if( bound_check( cell_index, i, j ) )
104  { m_lhs[cell_index][get_flat_index(i, j)] += value; }
105 }
106 
107 //___________________________________________________________
108 void TpcSpaceChargeMatrixContainerv1::add_to_rhs( int cell_index, int i, float value )
109 {
110  if( bound_check( cell_index, i ) )
111  { m_rhs[cell_index][i] += value; }
112 }
113 
114 //___________________________________________________________
116 {
117  // check dimensions
118  int phibins = 0;
119  int rbins = 0;
120  int zbins = 0;
121  other.get_grid_dimensions( phibins, rbins, zbins );
122  if( (m_phibins != phibins) || (m_rbins != rbins) || (m_zbins != zbins) )
123  {
124  std::cout << "TpcSpaceChargeMatrixContainerv1::add - inconsistent grid sizes" << std::endl;
125  return false;
126  }
127 
128  // increment cell entries
129  for( size_t cell_index = 0; cell_index < m_lhs.size(); ++cell_index )
130  { add_to_entries( cell_index, other.get_entries( cell_index ) ); }
131 
132  // increment left hand side matrices
133  for( size_t cell_index = 0; cell_index < m_lhs.size(); ++cell_index )
134  for( int i = 0; i < m_ncoord; ++i )
135  for( int j = 0; j < m_ncoord; ++j )
136  { add_to_lhs( cell_index, i, j, other.get_lhs( cell_index, i, j ) ); }
137 
138  // increment right hand side matrices
139  for( size_t cell_index = 0; cell_index < m_lhs.size(); ++cell_index )
140  for( int i = 0; i < m_ncoord; ++i )
141  { add_to_rhs( cell_index, i, other.get_rhs( cell_index, i ) ); }
142 
143  return true;
144 }
145 
146 //___________________________________________________________
148 {
149  if( cell_index < 0 || cell_index >= (int) m_rhs.size() ) return false;
150  return true;
151 }
152 
153 //___________________________________________________________
154 bool TpcSpaceChargeMatrixContainerv1::bound_check( int cell_index, int i ) const
155 {
156  if( cell_index < 0 || cell_index >= (int) m_rhs.size() ) return false;
157  if( i < 0 || i >= m_ncoord ) return false;
158  return true;
159 }
160 
161 //___________________________________________________________
162 bool TpcSpaceChargeMatrixContainerv1::bound_check( int cell_index, int i, int j ) const
163 {
164  if( cell_index < 0 || cell_index >= (int) m_lhs.size() ) return false;
165  if( i < 0 || i >= m_ncoord ) return false;
166  if( j < 0 || j >= m_ncoord ) return false;
167  return true;
168 }
169 
170 //___________________________________________________________
172 { return j + i*m_ncoord; }