ATLAS Offline Software
Loading...
Searching...
No Matches
Trk::MatrixNtupleBranch Struct Reference

This class provides a simple interface to write Matricis to a root tree The size of the Matrix cannot exceed COLMAX x ROWMAX. More...

#include <MatrixNtupleBranch.h>

Collaboration diagram for Trk::MatrixNtupleBranch:

Public Member Functions

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
bool fill (const Amg::MatrixX &matrix)
 fill a vector
bool fill (const HepGeom::Rotate3D &matrix)
 fill a vector

Public Attributes

int m_nrows {-1}
int m_ncols {-1}
float m_matrix [COLMAX][ROWMAX] {}

Static Public Attributes

static const int COLMAX = 10
 data
static const int ROWMAX = 10

Detailed Description

This class provides a simple interface to write Matricis to a root tree The size of the Matrix cannot exceed COLMAX x ROWMAX.

The class requires all matrices to have the same size

Usage:

TTree* myTree = new TTree("data","data"); MatrixNtupleBranch branch; branch.initForWrite(*myTree,"vec",3,"");

for(int i=0;i<n;++i){ branch.fill( ); myTree->Fill(); }

Definition at line 33 of file MatrixNtupleBranch.h.

Member Function Documentation

◆ fill() [1/2]

bool Trk::MatrixNtupleBranch::fill ( const Amg::MatrixX & matrix)

fill a vector

Definition at line 44 of file MatrixNtupleBranch.cxx.

44 {
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 }
float m_matrix[COLMAX][ROWMAX]

◆ fill() [2/2]

bool Trk::MatrixNtupleBranch::fill ( const HepGeom::Rotate3D & matrix)

fill a vector

Definition at line 57 of file MatrixNtupleBranch.cxx.

57 {
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 }

◆ initForRead()

bool Trk::MatrixNtupleBranch::initForRead ( TTree & tree,
const std::string & varname,
int ncol,
int nrow,
const std::string & prefix = "" )

initialize class for reading

Definition at line 27 of file MatrixNtupleBranch.cxx.

27 {
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 }
static const int COLMAX
data
TChain * tree

◆ initForWrite()

bool Trk::MatrixNtupleBranch::initForWrite ( TTree & tree,
const std::string & varname,
int ncol,
int nrow,
const std::string & prefix = "" )

initialize class for writing

Definition at line 10 of file MatrixNtupleBranch.cxx.

10 {
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 }

Member Data Documentation

◆ COLMAX

const int Trk::MatrixNtupleBranch::COLMAX = 10
static

data

Definition at line 48 of file MatrixNtupleBranch.h.

◆ m_matrix

float Trk::MatrixNtupleBranch::m_matrix[COLMAX][ROWMAX] {}

Definition at line 52 of file MatrixNtupleBranch.h.

52{};

◆ m_ncols

int Trk::MatrixNtupleBranch::m_ncols {-1}

Definition at line 51 of file MatrixNtupleBranch.h.

51{-1};

◆ m_nrows

int Trk::MatrixNtupleBranch::m_nrows {-1}

Definition at line 50 of file MatrixNtupleBranch.h.

50{-1};

◆ ROWMAX

const int Trk::MatrixNtupleBranch::ROWMAX = 10
static

Definition at line 49 of file MatrixNtupleBranch.h.


The documentation for this struct was generated from the following files: