ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace 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
44 bool MatrixNtupleBranch::fill( const Amg::MatrixX& matrix ) {
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}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
bool fill(const Amg::MatrixX &matrix)
fill a vector
static const int COLMAX
data
float m_matrix[COLMAX][ROWMAX]
bool initForWrite(TTree &tree, const std::string &varname, int ncol, int nrow, const std::string &prefix="")
initialize class for writing
bool initForRead(TTree &tree, const std::string &varname, int ncol, int nrow, const std::string &prefix="")
initialize class for reading
TChain * tree