LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_trackerhitplane.cc
Go to the documentation of this file.
1 // test lcio::TrackerHitPlane
4 
5 #include "tutil.h"
6 #include "lcio.h"
7 
8 #include "EVENT/LCIO.h"
9 #include "IO/LCReader.h"
10 #include "IO/LCWriter.h"
11 #include "IMPL/LCEventImpl.h"
12 #include "IMPL/LCCollectionVec.h"
14 //#include "UTIL/Operators.h"
15 
16 #include "UTIL/ILDConf.h"
17 
18 //#include <iostream>
19 
20 using namespace std ;
21 using namespace lcio ;
22 
23 //static const int NRUN = 10 ;
24 static const int NEVENT = 3 ; // events
25 static const int NHITS = 10 ; // tracker hits per event
26 
27 static string FILEN = "trackerhitplane.slcio" ;
28 
29 // replace mytest with the name of your test
30 const static string testname="test_trackerhitplane";
31 
32 //=============================================================================
33 
34 int main(int /*argc*/, char** /*argv*/ ){
35 
36  // this should be the first line in your test
37  TEST MYTEST=TEST( testname, std::cout );
38 
39  try{
40 
41 
42  MYTEST.LOG( " writing TrackerPlaneHits " );
43 
44  // create sio writer
45  LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
46 
47  lcWrt->open( FILEN , LCIO::WRITE_NEW ) ;
48 
49  // EventLoop - create some events and write them to the file
50  for(int i=0;i<NEVENT;i++){
51 
52  // we need to use the implementation classes here
53  LCEventImpl* evt = new LCEventImpl() ;
54 
55 
56  evt->setRunNumber( 4711 ) ;
57  evt->setEventNumber( i ) ;
58 
59  // LCCollectionVec* trkHits = new LCCollectionVec( LCIO::TRACKERHIT ) ;
60  LCCollectionVec* trkHits = new LCCollectionVec( LCIO::TRACKERHITPLANE ) ;
61 
62  for(int j=0;j<NHITS;j++){
63 
64  TrackerHitPlaneImpl* trkHit = new TrackerHitPlaneImpl ;
65 
66  trkHit->setEDep( i*j*117. ) ;
67  // trkHit->setdEdx( i*j*117. ) ;
68  trkHit->setEDepError( (i+j)*.3 ) ;
69 
70  double pos[3] = { 1.*i, 1.*j, 1.*i*j } ;
71  trkHit->setPosition( pos ) ;
72 
73  // float cov[6] = { i, j, i+j , 2*i, 2*j, 2*(i+j) , } ;
74  // trkHit->setCovMatrix( cov );
75 
76  trkHits->addElement( trkHit ) ;
77  }
78  evt->addCollection( trkHits , "TrackerPlaneHits") ;
79 
80  lcWrt->writeEvent(evt) ;
81 
82  delete evt ;
83  }
84 
85 
86  lcWrt->close() ;
87 
88  MYTEST.LOG(" reading back TrackerPlaneHits from file " ) ;
89 
90  // create sio reader
91  LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
92 
93  lcRdr->open( FILEN ) ;
94 
95  for(int i=0;i<NEVENT;i++){
96 
97  //std::cout << " testing event " << i << std::endl ;
98 
99  LCEvent* evt = lcRdr->readNextEvent() ;
100 
101  MYTEST( evt->getRunNumber() , 4711 , " run number " ) ;
102 
103  MYTEST( evt->getEventNumber() , i , " event number " ) ;
104 
105  LCCollection* trkHits = evt->getCollection( "TrackerPlaneHits") ;
106 
107  for(int j=0;j<NHITS;j++) {
108 
109  //std::cout << " testing hit " << j << std::endl ;
110 
111  TrackerHitPlane* trkHit = dynamic_cast<TrackerHitPlane*>(trkHits->getElementAt(j)) ;
112  // TrackerHit* trkHit = dynamic_cast<TrackerHit*>(trkHits->getElementAt(j)) ;
113 
114  //std::cout << *trkHit << std::endl ;
115 
116  MYTEST( trkHit->getEDep() , i*j*117. , "EDep" ) ;
117 
118  // MYTEST( trkHit->getdEdx() , i*j*117. , "dEdx" ) ;
119  // remove float converstion and check what happens ;)
120  MYTEST( trkHit->getEDepError() , float((i+j)*.3) , "EDepError" ) ;
121  //MYTEST( trkHit->getEDepError() , (i+j)*.3 , "EDepError" ) ;
122 
123  const double* pos = trkHit->getPosition() ;
124 
125  MYTEST( pos[0] , i , " pos[0] " ) ;
126  MYTEST( pos[1] , j , " pos[1] " ) ;
127  MYTEST( pos[2] , i*j , " pos[2] " ) ;
128 
129 
130  const FloatVec& cov = trkHit->getCovMatrix() ;
131 
132  // covariance should be size 6
133  MYTEST( cov.size() , 6u , " cov.size() != 6" ) ;
134 
135  MYTEST( cov[0] , 0 , " cov[0] " ) ;
136  MYTEST( cov[1] , 0 , " cov[1] " ) ;
137  MYTEST( cov[2] , 0 , " cov[2] " ) ;
138  MYTEST( cov[3] , 0 , " cov[3] " ) ;
139  MYTEST( cov[4] , 0 , " cov[4] " ) ;
140  MYTEST( cov[5] , 0 , " cov[5] " ) ;
141 
142 
143  }
144  }
145  lcRdr->close() ;
146 
147 
148  } catch( Exception &e ){
149  MYTEST.FAILED( e.what() );
150  }
151 
152  return 0;
153 }
154 
155 //=============================================================================
156 
static const string testname
std::vector< float > FloatVec
Vector of floats.
Definition: LCIOSTLTypes.h:18
Definition: tutil.h:7
static const int NEVENT
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...
static string FILEN
static const int NHITS
void LOG(const std::string &msg)
Definition: tutil.h:21