LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_trackstate.cc
Go to the documentation of this file.
1 // test lcio::TrackState
4 
5 #include "tutil.h"
6 #include "lcio.h"
7 
8 #include "EVENT/TrackState.h"
9 #include "IMPL/TrackStateImpl.h"
10 
11 //#include "UTIL/Operators.h"
12 
13 #include <sstream>
14 #include <assert.h>
15 
16 using namespace std ;
17 using namespace lcio ;
18 
19 // replace mytest with the name of your test
20 const static string testname="test_trackstate";
21 
22 //=============================================================================
23 
24 int main(int /*argc*/, char** /*argv*/ ){
25 
26  // this should be the first line in your test
27  TEST MYTEST=TEST( testname, std::cout );
28 
29  try{
30 
31  MYTEST.LOG( "testing TrackState" );
32 
33 
34 
35  MYTEST.LOG( "test default constructor" );
36 
37  TrackStateImpl a;
38 
39  MYTEST( a.getLocation(), TrackState::AtOther, "getLocation" ) ;
40  MYTEST( a.getD0(), float( .0 ), "getD0" ) ;
41  MYTEST( a.getPhi(), float( .0 ), "getPhi" ) ;
42  MYTEST( a.getOmega(), float( .0 ), "getOmega" ) ;
43 
44 
45 
46  MYTEST.LOG( "test constructor with arguments" );
47 
48  float cov[15] = { 1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15. } ;
49  float ref[3] = { 1. , 2. , 3. } ;
50 
51  TrackStateImpl b
52  (
53  TrackState::AtLastHit, // location
54  .1, // d0
55  .2, // phi
56  .3, // omega
57  .4, // z0
58  .5, // tanlambda
59  cov,
60  ref
61  );
62 
63  MYTEST( b.getLocation(), TrackState::AtLastHit, "getLocation" ) ;
64  MYTEST( b.getD0(), float( .1 ), "getD0" ) ;
65  MYTEST( b.getPhi(), float( .2 ), "getPhi" ) ;
66  MYTEST( b.getOmega(), float( .3 ), "getOmega" ) ;
67 
68 
69 
70  MYTEST.LOG( "test default copy constructor" );
71 
72  TrackStateImpl c(b);
73 
74  MYTEST( c.getLocation(), TrackState::AtLastHit, "getLocation" ) ;
75  MYTEST( c.getD0(), float( .1 ), "getD0" ) ;
76  MYTEST( c.getPhi(), float( .2 ), "getPhi" ) ;
77  MYTEST( c.getOmega(), float( .3 ), "getOmega" ) ;
78 
79 
80 
81  MYTEST.LOG( "test default assignment operator" );
82 
83  TrackStateImpl d=b;
84 
85  MYTEST( d.getLocation(), TrackState::AtLastHit, "getLocation" ) ;
86  MYTEST( d.getD0(), float( .1 ), "getD0" ) ;
87  MYTEST( d.getPhi(), float( .2 ), "getPhi" ) ;
88  MYTEST( d.getOmega(), float( .3 ), "getOmega" ) ;
89 
90 
91 
92  MYTEST.LOG( "test default copy constructor using EVENT::TrackState pointer" );
93 
94  const EVENT::TrackState * p = new TrackStateImpl(d) ;
95 
96  MYTEST( p->getLocation(), TrackState::AtLastHit, "getLocation" ) ;
97  MYTEST( p->getD0(), float( .1 ), "getD0" ) ;
98  MYTEST( p->getPhi(), float( .2 ), "getPhi" ) ;
99  MYTEST( p->getOmega(), float( .3 ), "getOmega" ) ;
100 
101 
102  const FloatVec& covv = p->getCovMatrix() ;
103 
104  for( unsigned int i=0 ; i<covv.size() ; i++ ){
105  stringstream ss;
106  ss << " covv[" << i << "] " ;
107  MYTEST( covv[i] , float(i+1) , ss.str() ) ;
108  }
109 
110  const float* refp = p->getReferencePoint() ;
111 
112  for( unsigned int i=0 ; i<3 ; i++ ){
113  stringstream ss;
114  ss << " refp[" << i << "] " ;
115  MYTEST( refp[i] , float(i+1) , ss.str() ) ;
116  }
117 
118 
119 
120  MYTEST.LOG( "test default copy constructor using two EVENT::TrackState pointers" );
121 
122  // the ugly way... have to use a dynamic or static_cast to TrackStateImpl..
123  const EVENT::TrackState * pp = new TrackStateImpl(static_cast<const TrackStateImpl&>(*p)) ;
124 
125  MYTEST( pp->getLocation(), TrackState::AtLastHit, "getLocation" ) ;
126  MYTEST( pp->getD0(), float( .1 ), "getD0" ) ;
127  MYTEST( pp->getPhi(), float( .2 ), "getPhi" ) ;
128  MYTEST( pp->getOmega(), float( .3 ), "getOmega" ) ;
129 
130  delete pp;
131  pp=NULL;
132 
133 
134 
135  MYTEST.LOG( "test default copy constructor using two EVENT::TrackState pointers" );
136 
137  // the nicer way... just passing the EVENT::TrackState object
138  pp = new TrackStateImpl( *p ) ;
139 
140  MYTEST( pp->getLocation(), TrackState::AtLastHit, "getLocation" ) ;
141  MYTEST( pp->getD0(), float( .1 ), "getD0" ) ;
142  MYTEST( pp->getPhi(), float( .2 ), "getPhi" ) ;
143  MYTEST( pp->getOmega(), float( .3 ), "getOmega" ) ;
144 
145 
146  delete pp;
147  pp=NULL;
148 
149 
150  delete p;
151  p=NULL;
152 
153 
154  } catch( Exception &e ){
155  MYTEST.FAILED( e.what() );
156  }
157 
158  return 0;
159 }
160 
161 //=============================================================================
162 
virtual float getOmega() const =0
Omega is the signed curvature of the track in [1/mm].
virtual const FloatVec & getCovMatrix() const =0
Covariance matrix of the track parameters.
std::vector< float > FloatVec
Vector of floats.
Definition: LCIOSTLTypes.h:18
static const string testname
The LCIO TrackState class.
Definition: TrackState.h:26
Definition: tutil.h:7
virtual float getD0() const =0
Impact paramter of the track in (r-phi).
virtual int getLocation() const =0
The location of the track state.
void FAILED(const std::string &msg)
Definition: tutil.h:42
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
T str(T...args)
virtual const float * getReferencePoint() const =0
Reference point of the track parameters, e.g.
T ref(T...args)
void LOG(const std::string &msg)
Definition: tutil.h:21
virtual float getPhi() const =0
Phi of the track at the reference point.