#include "tutil.h"
#include "lcio.h"
#include "EVENT/LCIO.h"
#include "IO/LCReader.h"
#include "IO/LCWriter.h"
#include "IMPL/LCEventImpl.h"
#include "IMPL/LCCollectionVec.h"
#include "IMPL/TrackerHitImpl.h"
#include "IMPL/LCFlagImpl.h"
Include dependency graph for test_trackerhit.cc:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
static const int | NEVENT = 10 |
static const int | NHITS = 1000 |
static string | FILEN = "trackerhits.slcio" |
static const string | testname = "test_trackerhit" |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 32 of file test_trackerhit.cc.
00032 { 00033 00034 // this should be the first line in your test 00035 TEST MYTEST=TEST( testname, std::cout ); 00036 00037 try{ 00038 00039 00040 MYTEST.LOG( " writing TrackerHits " ); 00041 00042 // create sio writer 00043 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ; 00044 00045 lcWrt->open( FILEN , LCIO::WRITE_NEW ) ; 00046 00047 // EventLoop - create some events and write them to the file 00048 for(int i=0;i<NEVENT;i++){ 00049 00050 // we need to use the implementation classes here 00051 LCEventImpl* evt = new LCEventImpl() ; 00052 00053 00054 evt->setRunNumber( 4711 ) ; 00055 evt->setEventNumber( i ) ; 00056 00057 LCCollectionVec* trkHits = new LCCollectionVec( LCIO::TRACKERHIT ) ; 00058 00059 for(int j=0;j<NHITS;j++){ 00060 TrackerHitImpl* trkHit = new TrackerHitImpl ; 00061 //trkHit->setEDep( i*j*117. ) ; 00062 trkHit->setdEdx( i*j*117. ) ; 00063 trkHit->setEDepError( (i+j)*.3 ) ; 00064 double pos[3] = { i, j, i*j } ; 00065 trkHit->setPosition( pos ) ; 00066 trkHits->addElement( trkHit ) ; 00067 } 00068 evt->addCollection( trkHits , "TrackerHits") ; 00069 00070 lcWrt->writeEvent(evt) ; 00071 00072 delete evt ; 00073 } 00074 00075 00076 lcWrt->close() ; 00077 00078 MYTEST.LOG(" reading back TrackerHits from file " ) ; 00079 00080 // create sio reader 00081 LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ; 00082 00083 lcRdr->open( FILEN ) ; 00084 00085 for(int i=0;i<NEVENT;i++){ 00086 00087 //std::cout << " testing event " << i << std::endl ; 00088 00089 LCEvent* evt = lcRdr->readNextEvent() ; 00090 00091 MYTEST( evt->getRunNumber() , 4711 , " run number " ) ; 00092 00093 MYTEST( evt->getEventNumber() , i , " event number " ) ; 00094 00095 LCCollection* trkHits = evt->getCollection( "TrackerHits") ; 00096 00097 for(int j=0;j<NHITS;j++) { 00098 00099 //std::cout << " testing hit " << j << std::endl ; 00100 00101 TrackerHit* trkHit = dynamic_cast<TrackerHit*>(trkHits->getElementAt(j)) ; 00102 00103 //MYTEST( trkHit->getEDep() , i*j*117. , "EDep" ) ; 00104 MYTEST( trkHit->getdEdx() , i*j*117. , "dEdx" ) ; 00105 // remove float converstion and check what happens ;) 00106 MYTEST( trkHit->getEDepError() , float((i+j)*.3) , "EDepError" ) ; 00107 //MYTEST( trkHit->getEDepError() , (i+j)*.3 , "EDepError" ) ; 00108 00109 const double* pos = trkHit->getPosition() ; 00110 00111 MYTEST( pos[0] , i , " pos[0] " ) ; 00112 MYTEST( pos[1] , j , " pos[1] " ) ; 00113 MYTEST( pos[2] , i*j , " pos[2] " ) ; 00114 00115 } 00116 } 00117 lcRdr->close() ; 00118 00119 00120 } catch( Exception &e ){ 00121 MYTEST.FAILED( e.what() ); 00122 } 00123 00124 return 0; 00125 }
const int NEVENT = 10 [static] |
Definition at line 22 of file test_trackerhit.cc.
const int NHITS = 1000 [static] |
Definition at line 23 of file test_trackerhit.cc.
string FILEN = "trackerhits.slcio" [static] |
Definition at line 25 of file test_trackerhit.cc.
const string testname = "test_trackerhit" [static] |
Definition at line 28 of file test_trackerhit.cc.