LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_trackerhitzcylinder.cc
Go to the documentation of this file.
1 // test lcio::TrackerHitZCylinder
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 = "trackerhitzcylinder.slcio" ;
28 
29 // replace mytest with the name of your test
30 const static string testname="test_trackerhitzcylinder";
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 TrackerZCylinderHits " );
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::TRACKERHITZCYLINDER ) ;
60 
61  for(int j=0;j<NHITS;j++){
62 
63  TrackerHitZCylinderImpl* trkHit = new TrackerHitZCylinderImpl ;
64 
65  trkHit->setEDep( i*j*117. ) ;
66  // trkHit->setdEdx( i*j*117. ) ;
67  trkHit->setEDepError( (i+j)*.3 ) ;
68 
69  double pos[3] = { 1.*i, 1.*j, 1.*i*j } ;
70  trkHit->setPosition( pos ) ;
71 
72  //float cov[3] = { i, j, i+j } ;
73  //trkHit->setCovMatrix( cov );
74 
75  trkHits->addElement( trkHit ) ;
76  }
77  evt->addCollection( trkHits , "TrackerZCylinderHits") ;
78 
79  lcWrt->writeEvent(evt) ;
80 
81  delete evt ;
82  }
83 
84 
85  lcWrt->close() ;
86 
87  MYTEST.LOG(" reading back TrackerZCylinderHits from file " ) ;
88 
89  // create sio reader
90  LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
91 
92  lcRdr->open( FILEN ) ;
93 
94  for(int i=0;i<NEVENT;i++){
95 
96  //std::cout << " testing event " << i << std::endl ;
97 
98  LCEvent* evt = lcRdr->readNextEvent() ;
99 
100  MYTEST( evt->getRunNumber() , 4711 , " run number " ) ;
101 
102  MYTEST( evt->getEventNumber() , i , " event number " ) ;
103 
104  LCCollection* trkHits = evt->getCollection( "TrackerZCylinderHits") ;
105 
106  for(int j=0;j<NHITS;j++) {
107 
108  //std::cout << " testing hit " << j << std::endl ;
109 
110  TrackerHitZCylinder* trkHit = dynamic_cast<TrackerHitZCylinder*>(trkHits->getElementAt(j)) ;
111 
112  //std::cout << *trkHit << std::endl ;
113 
114  MYTEST( trkHit->getEDep() , i*j*117. , "EDep" ) ;
115 
116  // MYTEST( trkHit->getdEdx() , i*j*117. , "dEdx" ) ;
117  // remove float converstion and check what happens ;)
118  MYTEST( trkHit->getEDepError() , float((i+j)*.3) , "EDepError" ) ;
119  //MYTEST( trkHit->getEDepError() , (i+j)*.3 , "EDepError" ) ;
120 
121  const double* pos = trkHit->getPosition() ;
122 
123  MYTEST( pos[0] , i , " pos[0] " ) ;
124  MYTEST( pos[1] , j , " pos[1] " ) ;
125  MYTEST( pos[2] , i*j , " pos[2] " ) ;
126 
127 
128  const FloatVec& cov = trkHit->getCovMatrix() ;
129 
130  MYTEST( cov.size() , 6u , " cov.size() != 6 " ) ;
131 
132  MYTEST( cov[0] , 0 , " cov[0] " ) ;
133  MYTEST( cov[1] , 0 , " cov[1] " ) ;
134  MYTEST( cov[2] , 0 , " cov[2] " ) ;
135  MYTEST( cov[3] , 0 , " cov[3] " ) ;
136  MYTEST( cov[4] , 0 , " cov[4] " ) ;
137  MYTEST( cov[5] , 0 , " cov[5] " ) ;
138 
139  }
140  }
141  lcRdr->close() ;
142 
143 
144  } catch( Exception &e ){
145  MYTEST.FAILED( e.what() );
146  }
147 
148  return 0;
149 }
150 
151 //=============================================================================
152 
static const int NEVENT
std::vector< float > FloatVec
Vector of floats.
Definition: LCIOSTLTypes.h:18
Definition: tutil.h:7
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 const string testname
static const int NHITS
void LOG(const std::string &msg)
Definition: tutil.h:21
static string FILEN