ATLAS Offline Software
AlSymMat.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "GaudiKernel/StatusCode.h"
6 
10 #include "TrkAlgebraUtils/AlMat.h"
11 
12 #include <algorithm>
13 #include <cfloat> //for DBL_EPSILON
14 #include <cmath>
15 #include <cstdint>
16 #include <fstream>
17 #include <iomanip>
18 #include <iostream>
19 #include <stdexcept>
20 
21 #include <TMatrixDSparse.h>
22 
23 
24 extern "C" {
25  void dsptrf_(char*, const int*, double*, int*, int* );
26 }
27 
28 extern "C" {
29  void dsptri_(char*, const int*, double*, int*, double*, int* );
30 }
31 
32 extern "C" {
33  void dspev_(char*, char*, const int*, double*,
34  double*, double*, const int*, double*, int* );
35 }
36 
37 namespace{
38  char *
39  charAddress(auto & v){
40  return reinterpret_cast<char *>(&v);
41  }
42 }
43 namespace Trk {
44 
45 //______________________________________________________________________________
47  : m_ptr_data(nullptr)
48  , m_pathbin("./")
49  , m_pathtxt("./")
50 {
51  m_matrix_type = 1;
52 }
53 
54 
55 //______________________________________________________________________________
57  : AlSymMatBase(N)
58  , m_ptr_data(new double[m_nele])
59  , m_pathbin("./")
60  , m_pathtxt("./")
61 {
62  m_matrix_type = 1;
63 
64  double* p = m_ptr_data + m_nele;
65  while (p > m_ptr_data) *(--p) = 0.;
66 
67 }
68 
69 //______________________________________________________________________________
71  : AlSymMatBase(m)
72  , m_ptr_data(new double[m_nele])
73  , m_pathbin(m.m_pathbin)
74  , m_pathtxt(m.m_pathtxt)
75 {
76  m_matrix_type = 1;
77  m_size = m.size();
78  m_nele = m.m_nele;
79 
80  copy(m);
81 }
82 
83 //______________________________________________________________________________
85  : AlSymMatBase (m.size()),
86  m_ptr_data (new double[m_nele]),
87  m_pathbin (m.pathBin()),
88  m_pathtxt (m.pathTxt())
89 {
91 }
92 
93 //______________________________________________________________________________
95 {
96  m_matrix_type = 1;
97  m_size = m.size();
98  m_nele = m_size*(m_size+1)/2;
99  m_pathbin = m.pathBin();
100  m_pathtxt = m.pathTxt();
101 
102  m_ptr_data = new double[m_nele];
103  copy(m);
104  return *this;
105 }
106 
107 //______________________________________________________________________________
109 {
110  if( m_ptr_data != nullptr ) delete [] m_ptr_data;
111  //ptr_map.clear();
112 }
113 
114 //______________________________________________________________________________
116 {
117  // this one implements the fast copy alg.
118  if( size() != m.size()) {
119  throw std::range_error( "AlSymMat::copy: size do not match!" );
120  }
121 
122  double * p = m_ptr_data + m_nele;
123  double* r = m.m_ptr_data + m_nele;
124  while (p > m_ptr_data) *(--p) = *(--r);
125 }
126 
127 //______________________________________________________________________________
129 {
130  //
131  if( size() != m.size()) {
132  throw std::range_error( "AlSymMat::copy: size do not match!" );
133  }
134 
135  (*this) = 0.;
136  //Convert Storage System
137  long int i, j;
138  for (const datamap::value_type& p : *m.ptrMap()) {
139  m.elem(p.first, i, j);
140  AlSymMat::elemr(i,j) = p.second;
141  }
142 
143  }
144 
145 //______________________________________________________________________________
146 void AlSymMat::copy(const AlMat& m)
147 {
148  // copy the lower triangle only!
149  int si = size();
150  if( si != m.nrow() || si != m.ncol() ) {
151  throw std::range_error("AlSymMat::copy: sizes do not match!" );
152  }
153 
154  for( int i=0; i<si; i++ )
155  for( int j=0; j<=i; j++ )
156  elemr(i, j) = m.elemc(i, j);
157 }
158 
159 //______________________________________________________________________________
161 {
162  if (this==&m)
163  return *this;
164 
165  if ( m_ptr_data != m.m_ptr_data ) {
166  reSize(m.size());
167  copy(m);
168  }
169  return *this;
170 }
171 
172 //______________________________________________________________________________
174 {
175  if( m.nrow() != m.ncol() ) {
176  throw std::range_error( "AlSymMat::operator=: a squared matrix is required!" );
177  }
178 
179  reSize(m.nrow());
180  copy(m);
181 
182  return *this;
183 }
184 
185 //______________________________________________________________________________
187 {
188  double * p = m_ptr_data + m_nele;
189  while (p > m_ptr_data) *(--p) = d;
190 
191  return *this;
192 }
193 
194 //______________________________________________________________________________
196 {
197  if( size() != m.size()) {
198  throw std::range_error( "AlSymMat::operator+: size do not match!" );
199  }
200 
201  AlSymMat b(size());
202  double * p = m_ptr_data + m_nele;
203  double * q = m.m_ptr_data + m_nele;
204  double * r = b.m_ptr_data + m_nele;
205  while (p > m_ptr_data) *(--r) = (*(--p))+(*(--q));
206 
207  return b;
208 }
209 
210 //______________________________________________________________________________
212 {
213  if( size() != m.size()){
214  throw std::range_error( "AlSymMat::operator+=: size do not match!" );
215  }
216 
217  double * p = m_ptr_data + m_nele;
218  double * q = m.m_ptr_data + m_nele;
219  while (p > m_ptr_data) *(--p) += *(--q);
220 
221  return *this;
222 }
223 
224 //______________________________________________________________________________
226 {
227  if( size() != m.size()) {
228  throw std::range_error( "AlSymMat::operator-: size do not match!" );
229  }
230 
231  AlSymMat b(size());
232  double * p = m_ptr_data + m_nele;
233  double * q = m.m_ptr_data + m_nele;
234  double * r = b.m_ptr_data + m_nele;
235  while (p > m_ptr_data) *(--r) = (*(--p))-(*(--q));
236 
237  return b;
238 }
239 
240 //______________________________________________________________________________
242 {
243  if( size() != m.size()) {
244  throw std::range_error( "AlSymMat::operator-=: size do not match!" );
245  }
246 
247  double * p = m_ptr_data + m_nele;
248  double * q = m.m_ptr_data + m_nele;
249  while (p > m_ptr_data) *(--p) -= *(--q);
250 
251  return *this;
252 }
253 
254 //______________________________________________________________________________
256 {
257  if( size() != m.size() ) {
258  throw std::range_error( "AlSymMat::operator*: size do not match!" );
259  }
260 
261  AlMat b( size(), size());
262  double x;
263  long int k, l, n, ii, jj;
264  long int siz(size());
265 
266  // optimised version of symmetric matrix product:
267  for( long int i=0; i<siz; i++ )
268  for( long int j=0; j<siz; j++ ) {
269  x = 0.;
270  l = i < j ? i : j;
271  n = i < j ? j : i;
272  ii = (i+1)*i/2;
273  jj = (j+1)*j/2;
274  for( k=0; k<l; k++)
275  x += (*(m_ptr_data+ii+k))*(*(m.m_ptr_data+jj+k));
276  if( i<j ) {
277  for( k=l; k<n; k++)
278  x += (*(m_ptr_data+(k+1)*k/2+i))*(*(m.m_ptr_data+jj+k));
279  }
280  else {
281  for( k=l; k<n; k++)
282  x += (*(m_ptr_data+ii+k))*(*(m.m_ptr_data+(k+1)*k/2+j));
283  }
284  for( k=n; k<siz; k++)
285  x += (*(m_ptr_data+(k+1)*k/2+i))*(*(m.m_ptr_data+(k+1)*k/2+j));
286  b.elemr(i,j) = x;
287  }
288 
289  return b;
290 }
291 
292 //______________________________________________________________________________
294 {
295  if( size() != m.nrow() ) {
296  throw std::range_error("AlSymMat::operator*: size do not match!" );
297  }
298 
299  AlMat b( size(), m.ncol());
300 
301  double x;
302  long int k, ii;
303  long int siz(size()), nco(m.ncol());
304 
305  // optimised version of matrix product:
306  for( long int i=0; i<siz; i++ )
307  for( long int j=0; j<nco; j++ ) {
308  x = 0.;
309  ii = (i+1)*i/2;
310  for( k=0; k<i; k++)
311  x += (*(m_ptr_data+ii+k))*m.elemc(k,j);
312  for( k=i; k<siz; k++)
313  x += (*(m_ptr_data+(k+1)*k/2+i))*m.elemc(k,j);
314  b.elemr(i,j) = x;
315  }
316 
317  return b;
318 }
319 
320 //______________________________________________________________________________
322 {
323  if( size() != v.size() ) {
324  throw std::range_error( "AlSymMat::operator*: size do not match! " );
325  }
326 
327  AlVec b(size());
328 
329  long int ii;
330 
331  for( long int i=0; i<size(); i++ ) {
332  ii = (i+1)*i/2;
333  for( long int j=0; j<i; j++ )
334  b[i] += (*(m_ptr_data+ii+j))*v[j];
335  for( long int j=i; j<size(); j++ )
336  b[i] += (*(m_ptr_data+(j+1)*j/2+i))*v[j];
337  }
338 
339  return b;
340 }
341 
342 //______________________________________________________________________________
344 {
345  double * p = m_ptr_data + m_nele;
346  while (p > m_ptr_data) *(--p) *= d;
347 
348  return *this;
349 }
350 
351 //______________________________________________________________________________
352 AlSymMat AlSymMat::operator*(const double& d) const
353 {
354  AlSymMat a(size());
355  double * p = m_ptr_data + m_nele;
356  double * q = a.m_ptr_data + m_nele;
357  while (p > m_ptr_data) *(--q) = (*(--p))*d;
358 
359  return a;
360 }
361 
362 //______________________________________________________________________________
364 {
365  // add a protection to detect singular matrices:
366  // double det = (*this).determinant();
367  // double detcut = 1.E-20;
368 
369  // if (fabs(det)>detcut) {
370 
371  int ierr = 0;
372  char uplo = 'U';
373  int N = size();
374  int * ipiv = new int[N];
375  double * work = new double[N];
376  double * mx = m_ptr_data;
377 
378  dsptrf_(&uplo, &N, mx, ipiv, &ierr);
379 
380  dsptri_(&uplo, &N, mx, ipiv, work, &ierr);
381 
382  delete [] ipiv;
383  delete [] work;
384 
385  // } else {
386  // ierr=999;
387  // }
388  return ierr;
389 }
390 
391 //______________________________________________________________________________
393 {
394  double deter = 1.;
395 
396  // get determinant using LU decomposition + Crout algorithm
397  AlMat A(size(),size());
398  A = (*this);
399 
400  double AMAX,DUM,SUM;
401  //int CODE;
402  double TINY = 1.E-20;
403  double D;
404  int N=size();
405 
406  D=1.; //CODE=0;
407 
408  for(int I=0;I<N;I++) {
409  AMAX=0.;
410  for(int J=0;J<N;J++)
411  if (fabs(A[I][J])>AMAX)
412  AMAX=fabs(A[I][J]);
413  if(AMAX<TINY) {
414 // CODE = 1; // matrix is singular
415  return 0;
416  }
417  }
418 
419  for(int J=0;J<N;J++) {
420  for(int I=0;I<N;I++) {
421  SUM = A[I][J];
422  int KMAX = (I<J)?I:J;
423  for(int K=0;K<KMAX;K++)
424  SUM = SUM - A[I][K]*A[K][J];
425  A[I][J]=SUM;
426  }
427 
428  // find pivot and exchange if necessary
429  int IMAX=J;
430  for (int I=J+1;I<N;I++) {
431  if(fabs(A[I][J])>fabs(A[IMAX][J])) IMAX=I;
432  }
433 
434  if(IMAX!=J) {
435  for(int K=0;K<N;K++) {
436  DUM=A[IMAX][K];
437  A[IMAX][K]=A[J][K];
438  A[J][K]=DUM;
439  }
440  D=-D;
441  }
442 
443  if(J<N && (fabs(A[J][J])>TINY)) {
444  DUM = 1./ A[J][J];
445  for(int I=J+1;I<N;I++) A[I][J] = A[I][J]*DUM;
446  }
447  }
448 
449  deter=deter*D;
450  for(int I=0;I<N;I++)
451  deter = deter*A[I][I];
452 
453  return deter;
454 }
455 
456 //______________________________________________________________________________
457 int AlSymMat::diagonalize(char jobz, AlVec &w, AlMat &z)
458 {
459  int info = 0;
460  char uplo = 'U';
461  int N = size();
462  double * work = new double[3*N];
463 
464  double * ap = m_ptr_data;
465 
466  dspev_(&jobz, &uplo, &N, ap, w.ptrData(), z.ptrData(), &N, work, &info);
467 
468  delete [] work;
469 
470  return info;
471 }
472 
473 //______________________________________________________________________________
474 // index here is module number within matrix (size=6*max_index)
476 {
477  const int shift=6;
478 
479  if((shift*index)<size() && index>=0) {
480  for(int row=(shift*index); row<(size()-shift); row+=shift) {
481  for(int k=0; k<shift; k++) {
482  for(int col=0; col<row+k+1; col++) {
483  // cout << "(" << row+k << "," << col << ") -> " << *(m_ptr_data+elem(row+k,col)) << endl;
484 
485  if(col<shift*index)
486  *(m_ptr_data+elem(row+k,col))=*(m_ptr_data+elem(row+k+shift,col));
487  else
488  *(m_ptr_data+elem(row+k,col))=*(m_ptr_data+elem(row+k+shift,col+shift));
489  }
490  }
491  }
492  }
493 }
494 
495 
496 //______________________________________________________________________________
497 int AlSymMat::RemoveCollsRows(std::vector<int> indices)
498 {
499  int n = indices.size();
500  if (n==0) {
501  return m_size;
502  }
503  if (n>m_size) {
504  throw std::range_error("Vector of indices larger than matrix size.");
505  }
506 
507  // first sort the list of indices descending
508  // maybe not the fastest way to do that but it works
509  for (int i=0;i<n-1;i++)
510  for (int j=i+1; j<n; j++)
511  if (indices[j] > indices[i]) {
512  int itmp = indices[i];
513  indices[i] = indices[j];
514  indices[j] = itmp;
515  }
516 
517  // remove rows and columns starting from largest indices
518  for (int i=0;i<n;i++) {
519  int index = indices[i];
520  if (index > m_size-1) {
521  throw std::out_of_range("AlSymMat::RemoveCollsRows: Index goes beyond matrix.");
522  }
523 
524  for (int j=index; j<m_size-1; j++)
525  for (int col=0; col<=j; col++)
526  if(col<index)
527  *(m_ptr_data+elem(j,col)) = *(m_ptr_data+elem(j+1,col));
528  else
529  *(m_ptr_data+elem(j,col)) = *(m_ptr_data+elem(j+1,col+1));
530 
531  m_size--;
532  }
533 
534  return m_size;
535 }
536 
537 //______________________________________________________________________________
538 // index here is alignment parameter to remove
539 void AlSymMat::RemoveAlignPar(int index, int control)
540 {
541  // Dynamic shiftRow
542  int shiftRow = 1;
543  int counterRow = 0;
544 
545  // Dynamic shiftCol
546  int shiftCol;
547  int counterCol = 0;
548 
549  index = index-control;
550 
551  for(int row=index; row<(size()-shiftRow); row++) {
552 
553  shiftCol = 0;
554  counterCol = 0;
555 
556  for(int col=0; col<row+1; col++) {
557 
558  if (col==index) {
559  shiftCol = 1;
560  counterCol=0;
561  }
562 
563  *(m_ptr_data+elem(row,col))=*(m_ptr_data+elem(row+shiftRow,col+shiftCol));
564 
565  counterCol++;
566  if (counterCol==5-control) {
567  counterCol=0;
568  shiftCol++;
569  }
570  }
571 
572  counterRow++;
573  if (counterRow==5-control) {
574  counterRow=0;
575  shiftRow++;
576  }
577  }
578 }
579 
580 //______________________________________________________________________________
581 void AlSymMat::SetPathBin(const std::string &path)
582 {
583  m_pathbin.assign(path);
584 }
585 
586 //______________________________________________________________________________
587 void AlSymMat::SetPathTxt(const std::string &path)
588 {
589  m_pathtxt.assign(path);
590 }
591 
592 //______________________________________________________________________________
593 StatusCode AlSymMat::Write(const std::string &filename, bool binary,
594  bool square, double, float version)
595 {
596  std::ofstream outmat;
597 
598  int32_t msizz = square ? size() : (-1)*size();
599 
600  if(binary) {
601  outmat.open((m_pathbin+filename).c_str(), std::ios::binary);
602  if(outmat.fail())
603  return StatusCode::FAILURE;
604  // if triangular, change size sign to distinguish
605  // from square format
606  outmat.write(charAddress(msizz), sizeof (msizz));
607  outmat.write(charAddress(version), sizeof (version));
608  }
609  else {
610  outmat.open((m_pathtxt+filename).c_str());
611  if(outmat.fail())
612  return StatusCode::FAILURE;
613  outmat.setf(std::ios::fixed);
614  outmat.setf(std::ios::showpoint);
615  outmat.precision(3);
616  outmat << "msizz: " << std::setw(6) << msizz << std::endl;
617  outmat << "AlSymMat version: " << std::setw(6) << version << std::endl;
618  }
619 
620  double melem=0;
621 
622  if (!square) {
623  for( int i=0; i<size(); i++) {
624  for( int j=0; j<=i; j++) {
625  melem = *(m_ptr_data+(i+1)*i/2+j);
626  if(binary)
627  outmat.write(charAddress((melem)), sizeof (melem));
628  else
629  outmat << std::setw(14) << melem;
630  }
631  if(!binary)
632  outmat << std::endl;
633  }
634  }
635  else {
636  for( int i=0; i<size(); i++) {
637  for( int j=0; j<size(); j++) {
638  if(i>=j) melem = *(m_ptr_data+(i+1)*i/2+j);
639  else melem = *(m_ptr_data+(j+1)*j/2+i);
640  if(binary)
641  outmat.write(charAddress((melem)), sizeof (melem));
642  else
643  outmat << std::setw(14) << melem;
644  }
645  if(!binary)
646  outmat << std::endl;
647  }
648  }
649  outmat.close();
650  return StatusCode::SUCCESS;
651 }
652 
653 //______________________________________________________________________________
654 StatusCode AlSymMat::CheckMatVersion(const std::string& filename, bool &StdUnits)
655 {
656  std::ifstream inmat((filename).c_str(), std::ios::binary);
657  if(inmat.fail())
658  return StatusCode::FAILURE;
659 
660  int32_t msiz=0;
661  inmat.read(charAddress(msiz), sizeof (msiz));
662 
663  float version=0.0;
664  inmat.read(charAddress(version), sizeof (version));
665 
666  StdUnits = version>=2.0;
667 
668  inmat.close();
669 
670  // std::cout << "AlSymMat::StdUnits: " << StdUnits << std::endl;
671 
672  return StatusCode::SUCCESS;
673 }
674 
675 //______________________________________________________________________________
676 StatusCode AlSymMat::Read(const std::string &filename, int &dofs,
677  bool &triang, float &version)
678 {
679  bool stdUnits = true;
680  if (StatusCode::SUCCESS != CheckMatVersion(m_pathbin+filename, stdUnits))
681  return StatusCode::FAILURE;
682 
683  // std::cout << "AlSymMat::StdUnits: " << stdUnits << std::endl;
684 
685  std::ifstream inmat((m_pathbin+filename).c_str(), std::ios::binary);
686  if(inmat.fail())
687  return StatusCode::FAILURE;
688 
689  int32_t msiz=0;
690  inmat.read(charAddress(msiz), sizeof (msiz));
691  dofs = abs(msiz);
692  m_size = abs(msiz);
693 
694  if (stdUnits)
695  inmat.read(charAddress(version), sizeof (version));
696 
697  double melem=0;
698 
699  if(msiz>0) { // square format
700  triang=false;
701  for(int i=0; i<msiz; i++) {
702  for(int j=0; j<msiz; j++) {
703  inmat.read(charAddress(melem), sizeof (melem));
704  if( i>=j )
705  *(m_ptr_data+(i+1)*i/2+j) = melem;
706  }
707  }
708  }
709  else { // triangular format
710  triang=true;
711  msiz = (-1)*msiz;
712  // std::cout << "msiz=" << msiz << std::endl;
713  for( int i=0; i<msiz; i++) {
714  for( int j=0; j<=i; j++) {
715  inmat.read(charAddress(melem), sizeof (melem));
716  *(m_ptr_data+(i+1)*i/2+j) = melem;
717  }
718  }
719  }
720 
721  inmat.close();
722  return StatusCode::SUCCESS;
723 }
724 
725 //______________________________________________________________________________
726 StatusCode AlSymMat::ReadProjected(const std::string &filename, int &dofs,
727  bool &triang, float &version)
728 {
729  std::ifstream inmat((m_pathbin+filename).c_str(), std::ios::binary);
730  if(inmat.fail())
731  return StatusCode::FAILURE;
732 
733  int32_t msiz=0;
734  inmat.read(charAddress(msiz), sizeof (msiz));
735  dofs = abs(msiz);
736  m_size = abs(msiz);
737 
738  inmat.read(charAddress(version), sizeof (version));
739 
740  double melem=0;
741 
742  if(msiz>0) { // square format
743  triang=false;
744  for(int i=0; i<msiz; i++) {
745  for(int j=0; j<msiz; j++) {
746  inmat.read(charAddress(melem), sizeof (melem));
747  if( i>=j )
748  *(m_ptr_data+(i+1)*i/2+j) = melem;
749  }
750  }
751  }
752  else { // triangular format
753  triang=true;
754  msiz = (-1)*msiz;
755  // std::cout << "msiz=" << msiz << std::endl;
756  for( int i=0; i<msiz; i++) {
757  for( int j=0; j<=i; j++) {
758  inmat.read(charAddress(melem), sizeof (melem));
759  *(m_ptr_data+(i+1)*i/2+j) = melem;
760  }
761  }
762  }
763 
764  inmat.close();
765  return StatusCode::SUCCESS;
766 }
767 
768 //______________________________________________________________________________
769 void AlSymMat::reSize(long int Nnew)
770 {
771  if ( Nnew != size() ) {
772  double * p = m_ptr_data;
773  long int ii;
774 
775  m_nele = Nnew*(Nnew+1)/2;
776  m_ptr_data = new double[m_nele];
777  long int Size_old = size();
778  m_size = Nnew;
779  long int k = size() <= Size_old ? size() : Size_old;
780  for( long int i=0; i<k; i++ ) {
781  ii = (i+1)*i/2;
782  for( long int j=0; j<=i; j++ )
783  *(m_ptr_data+ii+j) = *(p+ii+j);
784  }
785  delete [] p;
786  }
787 }
788 
789 //______________________________________________________________________________
790 double& AlSymMat::elemr(long int i,long int j)
791 {
792 #ifdef _DEBUG
793  if( i<0 ) {
794  throw std::underflow_error( "AlSymMat::elemr: Index 1 < zero!" );
795  }
796  if( i>=size() ) {
797  throw std::overflow_error( "AlSymMat::elemr: Index 1 too large!" );
798  }
799  if( j<0 ) {
800  throw std::underflow_error( "AlSymMat::elemr: Index 2 < zero!" );
801  }
802  if( j>=size() ) {
803  throw std::overflow_error( "AlSymMat::elemr: Index 2 too large!" );
804  }
805 #endif
806  if( j<=i )
807  return *(m_ptr_data+(i+1)*i/2+j);
808 
809  return *(m_ptr_data+(j+1)*j/2+i);
810 }
811 
812 //______________________________________________________________________________
813 double AlSymMat::elemc(long int i,long int j) const
814 {
815 #ifdef _DEBUG
816  if( i<0 ) {
817  throw std::underflow_error( "AlSymMat::elemc: Index 1 < zero!" );
818  }
819  if( i>=size() ) {
820  throw std::overflow_error( "AlSymMat::elemc: Index 1 too large!" );
821  }
822  if( j<0 ) {
823  throw std::underflow_error( "AlSymMat::elemc: Index 2 < zero!" );
824  }
825  if( j>=size() ) {
826  throw std::overflow_error( "AlSymMat::elemc: Index 2 too large!" );
827  }
828 #endif
829  if( j<=i )
830  return *(m_ptr_data+(i+1)*i/2+j);
831 
832  return *(m_ptr_data+(j+1)*j/2+i);
833 }
834 
835 
837 
838  int si = size();
839 
840  int nnz(0);
841 
842  for( int i=0; i<si; i++ )
843  for( int j=0; j<=i; j++ )
844  if( *(m_ptr_data+(i+1)*i/2+j) != 0 )
845  ++nnz;
846 
847 
848  int *irow = new int[nnz];
849  int *icol = new int[nnz];
850  double *val = new double[nnz];
851  int n(0);
852 
853  for (int i=0;i<si;i++) {
854  for (int j=0;j<=i;j++) {
855  if ( *(m_ptr_data+(i+1)*i/2+j) != 0.) {
856  irow[n] = i;
857  icol[n] = j;
858  val[n] = *(m_ptr_data+(i+1)*i/2+j);
859  ++n;
860  }
861  }
862  }
863 
864 
865  TMatrixDSparse* myTMatrix = new TMatrixDSparse(0,si-1,0,si-1);
866  myTMatrix->SetMatrixArray(nnz,irow,icol,val);
867 
868  delete [] irow;
869  delete [] icol;
870  delete [] val;
871 
872 
873  return myTMatrix;
874 
875 }
876 
877 
878 } // end namespace Trk
Trk::AlSymMat::RemoveAlignPar
virtual void RemoveAlignPar(int, int) override final
Definition: AlSymMat.cxx:539
beamspotman.r
def r
Definition: beamspotman.py:674
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
Trk::AlSymMat::operator+
virtual AlSymMat operator+(const AlSymMat &) const
Definition: AlSymMat.cxx:195
Trk::AlVec
Definition: AlVec.h:23
AlSpaMat.h
index
Definition: index.py:1
Trk::AlSymMatBase
Definition: AlSymMatBase.h:38
hist_file_dump.d
d
Definition: hist_file_dump.py:142
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
Trk::AlSymMat::Write
virtual StatusCode Write(const std::string &, bool, bool, double, float) override final
Definition: AlSymMat.cxx:593
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
Trk::AlSymMat::operator+=
virtual AlSymMat & operator+=(const AlSymMat &)
Definition: AlSymMat.cxx:211
AlVec.h
Trk::AlSymMat::m_pathbin
std::string m_pathbin
Definition: AlSymMat.h:89
keylayer_zslicemap.row
row
Definition: keylayer_zslicemap.py:155
Trk::AlSymMat::elem
long int elem(long int, long int) const
Definition: AlSymMat.h:96
fitman.mx
mx
Definition: fitman.py:520
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
AlSymMat.h
Trk::AlSymMat::invert
virtual int invert() override final
Definition: AlSymMat.cxx:363
Trk::AlSymMat::SetPathBin
virtual void SetPathBin(const std::string &) override final
Definition: AlSymMat.cxx:581
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:825
Trk::AlSymMat::operator*=
virtual AlSymMat & operator*=(const double &)
Definition: AlSymMat.cxx:343
atlasStyleMacro.icol
int icol
Definition: atlasStyleMacro.py:13
Trk::AlSymMat
Definition: AlSymMat.h:26
TMatrixDSparse
class TMatrixTSparse< double > TMatrixDSparse
Definition: AlSpaMat.h:14
Trk::AlSymMatBase::size
long int size() const
Definition: AlSymMatBase.h:145
Trk::AlSymMat::SetPathTxt
virtual void SetPathTxt(const std::string &) override final
Definition: AlSymMat.cxx:587
Trk::AlSymMat::operator=
AlSymMat & operator=(const AlSpaMat &)
Definition: AlSymMat.cxx:94
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
A
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
lumiFormat.i
int i
Definition: lumiFormat.py:85
dsptrf_
void dsptrf_(char *, const int *, double *, int *, int *)
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::AlSymMat::RemoveModule
virtual void RemoveModule(int) override final
Definition: AlSymMat.cxx:475
Trk::AlSymMat::Read
virtual StatusCode Read(const std::string &, int &, bool &, float &) override final
Definition: AlSymMat.cxx:676
AlMat.h
Trk::AlMat
Definition: AlMat.h:27
Trk::AlSymMatBase::m_nele
long int m_nele
Definition: AlSymMatBase.h:104
Trk::AlSymMat::elemc
virtual double elemc(long int, long int) const override final
Definition: AlSymMat.cxx:813
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
Trk::AlSymMat::m_pathtxt
std::string m_pathtxt
Definition: AlSymMat.h:90
Trk::AlSymMat::makeTMatrix
virtual TMatrixDSparse * makeTMatrix() override final
Definition: AlSymMat.cxx:836
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::AlSymMat::copy
void copy(const AlSymMat &m)
Definition: AlSymMat.cxx:115
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
dspev_
void dspev_(char *, char *, const int *, double *, double *, double *, const int *, double *, int *)
Trk::AlSymMat::ReadProjected
virtual StatusCode ReadProjected(const std::string &, int &, bool &, float &) override final
Definition: AlSymMat.cxx:726
python.PyAthena.v
v
Definition: PyAthena.py:154
get_generator_info.version
version
Definition: get_generator_info.py:33
Trk::AlSymMat::diagonalize
virtual int diagonalize(char jobz, AlVec &w, AlMat &z) override final
Definition: AlSymMat.cxx:457
a
TList * a
Definition: liststreamerinfos.cxx:10
Trk::AlSymMat::AlSymMat
AlSymMat()
Definition: AlSymMat.cxx:46
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
dsptri_
void dsptri_(char *, const int *, double *, int *, double *, int *)
Trk::AlSymMat::RemoveCollsRows
virtual int RemoveCollsRows(std::vector< int >) override final
Definition: AlSymMat.cxx:497
Trk::AlSymMat::reSize
virtual void reSize(long int Nnew) override final
Definition: AlSymMat.cxx:769
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
extractSporadic.q
list q
Definition: extractSporadic.py:97
Trk::AlSymMat::operator*
virtual AlMat operator*(const AlSymMat &) const
Definition: AlSymMat.cxx:255
Trk::AlSymMatBase::m_matrix_type
int m_matrix_type
Definition: AlSymMatBase.h:100
I
#define I(x, y, z)
Definition: MD5.cxx:116
Trk::AlSymMat::operator-
virtual AlSymMat operator-(const AlSymMat &) const
Definition: AlSymMat.cxx:225
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:198
Trk::x
@ x
Definition: ParamDefs.h:55
Trk::AlSymMatBase::m_size
long int m_size
Definition: AlSymMatBase.h:103
Trk::AlSymMat::m_ptr_data
double * m_ptr_data
Definition: AlSymMat.h:87
Trk::AlSymMat::~AlSymMat
~AlSymMat()
Definition: AlSymMat.cxx:108
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
Trk::AlSymMat::determinant
virtual double determinant() override final
Definition: AlSymMat.cxx:392
Trk::AlSymMat::CheckMatVersion
virtual StatusCode CheckMatVersion(const std::string &, bool &) override final
Definition: AlSymMat.cxx:654
Trk::AlSpaMat
Definition: AlSpaMat.h:27
Trk::v
@ v
Definition: ParamDefs.h:78
Trk::AlSymMat::elemr
virtual double & elemr(long int, long int) override final
Definition: AlSymMat.cxx:790
fitman.k
k
Definition: fitman.py:528
python.SystemOfUnits.m
float m
Definition: SystemOfUnits.py:106
Trk::AlSymMat::operator-=
virtual AlSymMat & operator-=(const AlSymMat &)
Definition: AlSymMat.cxx:241