ATLAS Offline Software
VectorNtupleBranch.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 VectorNtupleBranch::initForWrite(TTree& tree, const std::string& varname, int nrow, const std::string& prefix ) {
11  if( nrow >= ROWMAX ) return false;
12  m_nrows = nrow;
13  for( int i=0;i<nrow;++i ){
14  TString bname = prefix.c_str();
15  bname += varname;
16  bname += i;
17  tree.Branch(bname,&m_vector[i]);
18  }
19  return true;
20  }
21 
22  bool VectorNtupleBranch::initForRead(TTree& tree, const std::string& varname, int nrow, const std::string& prefix ) {
23  if( nrow >= ROWMAX ) return false;
24  m_nrows = nrow;
25  for( int i=0;i<nrow;++i ){
26  TString bname = prefix.c_str();
27  bname += varname;
28  bname += i;
29  tree.SetBranchAddress(bname,&m_vector[i]);
30  }
31  return true;
32  }
33 
35  if( m_nrows == -1 ) return false;
36  if( vector.rows() > m_nrows ) return false;
37 
38  for( int i=0;i<m_nrows;++i ){
39  if( i < vector.rows() ) m_vector[i] = vector[i];
40  else m_vector[i] = 0.;
41  }
42  return true;
43  }
44 
45  bool VectorNtupleBranch::fill( const CLHEP::HepVector& vector ) {
46  if( m_nrows == -1 ) return false;
47  if( vector.num_row() > m_nrows ) return false;
48  for( int i=0;i<m_nrows;++i ){
49  if( i < vector.num_row() ) m_vector[i] = vector[i];
50  else m_vector[i] = 0.;
51  }
52  return true;
53  }
54 
55  bool VectorNtupleBranch::fill( const HepGeom::Point3D<double>& vector ) {
56  if( m_nrows == -1 ) return false;
57  if( m_nrows != 3 ) return false;
58  for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
59  return true;
60  }
61 
62  bool VectorNtupleBranch::fill( const CLHEP::Hep3Vector& vector ) {
63  if( m_nrows == -1 ) return false;
64  if( m_nrows != 3 ) return false;
65  for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
66  return true;
67  }
68 
69  bool VectorNtupleBranch::fill( const HepGeom::Vector3D<double>& vector ) {
70  if( m_nrows == -1 ) return false;
71  if( m_nrows != 3 ) return false;
72  for( int i=0;i<m_nrows;++i ) m_vector[i] = vector[i];
73  return true;
74  }
75 
76 }
VectorNtupleBranch.h
Amg::VectorX
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Definition: EventPrimitives.h:32
Trk::VectorNtupleBranch::ROWMAX
static const int ROWMAX
maximum size of the vector
Definition: VectorNtupleBranch.h:58
tree
TChain * tree
Definition: tile_monitor.h:30
Trk::VectorNtupleBranch::initForRead
bool initForRead(TTree &tree, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for reading
Definition: VectorNtupleBranch.cxx:22
Trk::VectorNtupleBranch::initForWrite
bool initForWrite(TTree &tree, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for writing
Definition: VectorNtupleBranch.cxx:10
Trk::VectorNtupleBranch::fill
bool fill(const Amg::VectorX &matrix)
fill a vector
Definition: VectorNtupleBranch.cxx:34
Trk::VectorNtupleBranch::m_nrows
int m_nrows
Definition: VectorNtupleBranch.h:59
lumiFormat.i
int i
Definition: lumiFormat.py:92
vector
Definition: MultiHisto.h:13
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
Trk::VectorNtupleBranch::m_vector
float m_vector[ROWMAX]
Definition: VectorNtupleBranch.h:60
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37