/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/TESTS/test_trackerhit.cc

Go to the documentation of this file.
00001 ////////////////////////////////////////
00002 //  test lcio::TrackerHit
00003 ////////////////////////////////////////
00004 
00005 #include "tutil.h"
00006 #include "lcio.h"
00007 
00008 #include "EVENT/LCIO.h"
00009 #include "IO/LCReader.h"
00010 #include "IO/LCWriter.h"
00011 #include "IMPL/LCEventImpl.h" 
00012 #include "IMPL/LCCollectionVec.h"
00013 #include "IMPL/TrackerHitImpl.h"
00014 #include "IMPL/LCFlagImpl.h"
00015 
00016 //#include <iostream>
00017 
00018 using namespace std ;
00019 using namespace lcio ;
00020 
00021 //static const int NRUN = 10 ;
00022 static const int NEVENT = 10 ; // events
00023 static const int NHITS = 1000 ;  // tracker hits per event
00024 
00025 static string FILEN = "trackerhits.slcio" ;
00026 
00027 // replace mytest with the name of your test
00028 const static string testname="test_trackerhit";
00029 
00030 //=============================================================================
00031 
00032 int main(int argc, char** argv ){
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 }
00126 
00127 //=============================================================================
00128 

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7