/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/TESTS/test_trackerpulse.cc File Reference

#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/TrackerPulseImpl.h"
#include "IMPL/LCFlagImpl.h"

Include dependency graph for test_trackerpulse.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 NPULSES = 1000
static string FILEN = "trackerpulses.slcio"
static const string testname = "test_trackerpulse"


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file test_trackerpulse.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 TrackerPulses " );
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* trkPulses = new LCCollectionVec( LCIO::TRACKERPULSE )  ;
00058             LCCollectionVec* trkPulsesCov = new LCCollectionVec( LCIO::TRACKERPULSE )  ;
00059 
00060             LCFlagImpl flag( trkPulsesCov->getFlag() ) ;
00061             flag.setBit( LCIO::TRAWBIT_CM ) ;
00062             trkPulsesCov->setFlag( flag.getFlag() ) ;
00063 
00064 
00065             for(int j=0;j<NPULSES;j++){
00066                 TrackerPulseImpl* trkPulse = new TrackerPulseImpl ;
00067                 trkPulse->setTime( 3.1415 + 0.1 * i ) ;
00068                 //trkPulse->setTimeError( (i+j) * .003 ) ;
00069                 trkPulse->setCharge( 3.1415 + 0.1 * j ) ;
00070                 //trkPulse->setChargeError( (i+j)*.005 ) ;
00071                 
00072                 trkPulses->addElement( trkPulse ) ;
00073             }
00074             for(int j=0;j<NPULSES;j++){
00075                 TrackerPulseImpl* trkPulse = new TrackerPulseImpl ;
00076                 trkPulse->setTime( 3.1415 + 0.1 * i ) ;
00077                 //trkPulse->setTimeError( (i+j) * .003 ) ;
00078                 trkPulse->setCharge( 3.1415 + 0.1 * j ) ;
00079                 //trkPulse->setChargeError( (i+j)*.005 ) ;
00080 
00081                 float cov[3] = { i, j, i*j } ;
00082                 trkPulse->setCovMatrix( cov );
00083 
00084                 trkPulsesCov->addElement( trkPulse ) ;
00085             }
00086 
00087             evt->addCollection( trkPulses , "TrackerPulses") ;
00088             evt->addCollection( trkPulsesCov , "TrackerPulsesWithCovMatrix") ;
00089 
00090             lcWrt->writeEvent(evt) ;
00091 
00092             delete evt ;
00093         }
00094 
00095 
00096         lcWrt->close() ;
00097 
00098         MYTEST.LOG(" reading back TrackerPulses from file " ) ;
00099 
00100         // create sio reader
00101         LCReader* lcRdr = LCFactory::getInstance()->createLCReader()  ;
00102 
00103         lcRdr->open( FILEN ) ;
00104 
00105         for(int i=0;i<NEVENT;i++){
00106 
00107             //std::cout << " testing event " << i << std::endl ;
00108 
00109             LCEvent*  evt =  lcRdr->readNextEvent() ;
00110 
00111             MYTEST( evt->getRunNumber() ,  4711 , " run number " )  ;
00112 
00113             MYTEST(  evt->getEventNumber() ,  i , " event number "  ) ;
00114 
00115             LCCollection* trkPulses = evt->getCollection( "TrackerPulses") ;
00116 
00117             //MYTEST.LOG(" reading back TrackerPulses from file " ) ;
00118 
00119             for(int j=0;j<NPULSES;j++) {
00120 
00121                 //std::cout << " testing pulse " << j << std::endl ;
00122 
00123                 TrackerPulse* trkPulse = dynamic_cast<TrackerPulse*>(trkPulses->getElementAt(j)) ;
00124 
00125                 MYTEST( trkPulse->getTime(),  float( 3.1415 + 0.1 * i ), "time" ) ;
00126                 //MYTEST( trkPulse->getTimeError(),  float( (i + j) * .003 ), "time error" ) ;
00127                 MYTEST( trkPulse->getCharge(),  float( 3.1415 + 0.1 * j ), "charge" ) ;
00128                 //MYTEST( trkPulse->getChargeError(), float( (i + j) * .005 ), "charge error" ) ;
00129 
00130 
00131                 const FloatVec& cov = trkPulse->getCovMatrix() ;
00132                 
00133                 // should be initialized to 0
00134                 MYTEST( cov[0] , 0 , " cov[0] " ) ;
00135                 MYTEST( cov[1] , 0 , " cov[1] " ) ;
00136                 MYTEST( cov[2] , 0 , " cov[2] " ) ;
00137 
00138             }
00139 
00140             LCCollection* trkPulsesCov = evt->getCollection( "TrackerPulsesWithCovMatrix") ;
00141 
00142             //MYTEST.LOG(" reading back TrackerPulsesWithCovMatrix from file " ) ;
00143 
00144             for(int j=0;j<NPULSES;j++) {
00145 
00146                 //std::cout << " testing pulse " << j << std::endl ;
00147 
00148                 TrackerPulse* trkPulse = dynamic_cast<TrackerPulse*>(trkPulsesCov->getElementAt(j)) ;
00149 
00150                 MYTEST( trkPulse->getTime(),  float( 3.1415 + 0.1 * i ), "time" ) ;
00151                 //MYTEST( trkPulse->getTimeError(),  float( (i + j) * .003 ), "time error" ) ;
00152                 MYTEST( trkPulse->getCharge(),  float( 3.1415 + 0.1 * j ), "charge" ) ;
00153                 //MYTEST( trkPulse->getChargeError(), float( (i + j) * .005 ), "charge error" ) ;
00154                 const FloatVec& cov = trkPulse->getCovMatrix() ;
00155                 
00156                 MYTEST( cov[0] , i , " cov[0] " ) ;
00157                 MYTEST( cov[1] , j , " cov[1] " ) ;
00158                 MYTEST( cov[2] , i*j , " cov[2] " ) ;
00159             }
00160 
00161         }
00162         lcRdr->close() ;
00163 
00164 
00165     } catch( Exception &e ){
00166         MYTEST.FAILED( e.what() );
00167     }
00168 
00169     return 0;
00170 }


Variable Documentation

const int NEVENT = 10 [static]

Definition at line 22 of file test_trackerpulse.cc.

const int NPULSES = 1000 [static]

Definition at line 23 of file test_trackerpulse.cc.

Referenced by main().

string FILEN = "trackerpulses.slcio" [static]

Definition at line 25 of file test_trackerpulse.cc.

const string testname = "test_trackerpulse" [static]

Definition at line 28 of file test_trackerpulse.cc.


Generated on Mon Jan 7 13:16:52 2013 for MicromegasFramework by  doxygen 1.4.7