ATLAS Offline Software
MatrixNtupleBranch.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <TTree.h>
7 #include <TString.h>
8 
9 namespace Trk {
10  bool MatrixNtupleBranch::initForWrite(TTree& tree, const std::string& varname, int ncol, int nrow, const std::string& prefix ) {
11  if( ncol >= COLMAX ) return false;
12  if( nrow >= ROWMAX ) return false;
13  m_ncols = ncol;
14  m_nrows = nrow;
15  for( int i=0;i<nrow;++i ){
16  for( int j=0;j<ncol;++j ){
17  TString bname = prefix.c_str();
18  bname += varname;
19  bname += i;
20  bname += j;
21  tree.Branch(bname,&m_matrix[i][j]);
22  }
23  }
24  return true;
25  }
26 
27  bool MatrixNtupleBranch::initForRead(TTree& tree, const std::string& varname, int ncol, int nrow, const std::string& prefix ) {
28  if( ncol >= COLMAX ) return false;
29  if( nrow >= ROWMAX ) return false;
30  m_ncols = ncol;
31  m_nrows = nrow;
32  for( int i=0;i<nrow;++i ){
33  for( int j=0;j<ncol;++j ){
34  TString bname = prefix.c_str();
35  bname += varname;
36  bname += i;
37  bname += j;
38  tree.SetBranchAddress(bname,&m_matrix[i][j]);
39  }
40  }
41  return true;
42  }
43 
45  if( m_ncols == -1 ) return false;
46  if( matrix.rows() > m_nrows && matrix.cols() > m_ncols ) return false;
47 
48  for( int i=0;i<m_nrows;++i ){
49  for( int j=0;j<m_ncols;++j ){
50  if( i < matrix.rows() && j < matrix.cols() ) m_matrix[i][j] = matrix(i,j);
51  else m_matrix[i][j] = 0.;
52  }
53  }
54  return true;
55  }
56 
57  bool MatrixNtupleBranch::fill( const HepGeom::Rotate3D& matrix ) {
58  if( m_ncols == -1 ) return false;
59  if( m_nrows != 3 && m_ncols != 3 ) return false;
60 
61  for( int i=0;i<m_nrows;++i ){
62  for( int j=0;j<m_ncols;++j ){
63  if( i < 3 && j < 3 ) m_matrix[i][j] = matrix(i,j);
64  else m_matrix[i][j] = 0.;
65  }
66  }
67  return true;
68  }
69 
70 }
Trk::MatrixNtupleBranch::COLMAX
static const int COLMAX
data
Definition: MatrixNtupleBranch.h:48
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
Trk::MatrixNtupleBranch::fill
bool fill(const Amg::MatrixX &matrix)
fill a vector
Definition: MatrixNtupleBranch.cxx:44
tree
TChain * tree
Definition: tile_monitor.h:30
Trk::MatrixNtupleBranch::m_ncols
int m_ncols
Definition: MatrixNtupleBranch.h:51
Trk::MatrixNtupleBranch::ROWMAX
static const int ROWMAX
Definition: MatrixNtupleBranch.h:49
MatrixNtupleBranch.h
Trk::MatrixNtupleBranch::m_matrix
float m_matrix[COLMAX][ROWMAX]
Definition: MatrixNtupleBranch.h:52
lumiFormat.i
int i
Definition: lumiFormat.py:92
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::MatrixNtupleBranch::initForWrite
bool initForWrite(TTree &tree, const std::string &varname, int ncol, int nrow, const std::string &prefix="")
initialize class for writing
Definition: MatrixNtupleBranch.cxx:10
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
Trk::MatrixNtupleBranch::m_nrows
int m_nrows
Definition: MatrixNtupleBranch.h:50
Trk::MatrixNtupleBranch::initForRead
bool initForRead(TTree &tree, const std::string &varname, int ncol, int nrow, const std::string &prefix="")
initialize class for reading
Definition: MatrixNtupleBranch.cxx:27