00001
00002
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/CalorimeterHitImpl.h"
00014 #include "IMPL/LCFlagImpl.h"
00015
00016
00017
00018 using namespace std ;
00019 using namespace lcio ;
00020
00021
00022 static const int NEVENT = 10 ;
00023 static const int NHITS = 1000 ;
00024
00025 static string FILEN = "calohit.slcio" ;
00026
00027
00028 const static string testname="test_calohit";
00029
00030
00031
00032 int main(int argc, char** argv ){
00033
00034
00035 TEST MYTEST=TEST( testname, std::cout );
00036
00037 try{
00038
00039
00040 MYTEST.LOG( " writing CalorimeterHits " );
00041
00042
00043 LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
00044
00045 lcWrt->open( FILEN , LCIO::WRITE_NEW ) ;
00046
00047
00048 for(int i=0;i<NEVENT;i++){
00049
00050
00051 LCEventImpl* evt = new LCEventImpl() ;
00052
00053
00054 evt->setRunNumber( 4711 ) ;
00055 evt->setEventNumber( i ) ;
00056
00057 LCCollectionVec* calHits = new LCCollectionVec( LCIO::CALORIMETERHIT ) ;
00058 LCCollectionVec* calHitsErr = new LCCollectionVec( LCIO::CALORIMETERHIT ) ;
00059 LCFlagImpl calFlag( calHits->getFlag() ) ;
00060 calFlag.setBit( LCIO::RCHBIT_LONG ) ;
00061 calHits->setFlag( calFlag.getFlag() ) ;
00062
00063 calFlag.setBit( LCIO::RCHBIT_ENERGY_ERROR ) ;
00064 calHitsErr->setFlag( calFlag.getFlag() ) ;
00065
00066 for(int j=0;j<NHITS;j++){
00067 CalorimeterHitImpl* calHit = new CalorimeterHitImpl ;
00068 calHit->setEnergy( i*j*117. ) ;
00069 calHit->setCellID0( i+100000 + j ) ;
00070 float pos[3] = { i , j ,i*j } ;
00071 calHit->setPosition( pos ) ;
00072 calHits->addElement( calHit ) ;
00073 }
00074 for(int j=0;j<NHITS;j++){
00075 CalorimeterHitImpl* calHit = new CalorimeterHitImpl ;
00076 calHit->setEnergy( i*j*117. ) ;
00077 calHit->setEnergyError( i*j*0.117 ) ;
00078 calHit->setCellID0( i+100000 + j ) ;
00079 float pos[3] = { i , j ,i*j } ;
00080 calHit->setPosition( pos ) ;
00081 calHitsErr->addElement( calHit ) ;
00082 }
00083 evt->addCollection( calHits , "CalorimeterHits") ;
00084 evt->addCollection( calHitsErr , "CalorimeterHitsWithEnergyError") ;
00085
00086 lcWrt->writeEvent(evt) ;
00087
00088 delete evt ;
00089 }
00090
00091
00092 lcWrt->close() ;
00093
00094 MYTEST.LOG(" reading back CalorimeterHits from file " ) ;
00095
00096
00097 LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
00098
00099 lcRdr->open( FILEN ) ;
00100
00101 for(int i=0;i<NEVENT;i++){
00102
00103
00104
00105 LCEvent* evt = lcRdr->readNextEvent() ;
00106
00107 MYTEST( evt->getRunNumber() , 4711 , " run number " ) ;
00108
00109 MYTEST( evt->getEventNumber() , i , " event number " ) ;
00110
00111 LCCollection* calHits = evt->getCollection( "CalorimeterHits") ;
00112 LCCollection* calHitsErr = evt->getCollection( "CalorimeterHitsWithEnergyError") ;
00113
00114 for(int j=0;j<NHITS;j++) {
00115
00116
00117
00118 CalorimeterHit* calHit = dynamic_cast<CalorimeterHit*>(calHits->getElementAt(j)) ;
00119
00120 MYTEST( calHit->getEnergy() , i*j*117. , "energy" ) ;
00121 MYTEST( calHit->getCellID0() , i+100000 + j , " cellid0 " ) ;
00122
00123 const float* pos = calHit->getPosition() ;
00124
00125 MYTEST( pos[0] , i , " pos[0] " ) ;
00126 MYTEST( pos[1] , j , " pos[1] " ) ;
00127 MYTEST( pos[2] , i*j , " pos[2] " ) ;
00128
00129 }
00130 for(int j=0;j<NHITS;j++) {
00131
00132
00133
00134 CalorimeterHit* calHit = dynamic_cast<CalorimeterHit*>(calHitsErr->getElementAt(j)) ;
00135
00136 MYTEST( calHit->getEnergy() , i*j*117. , "energy" ) ;
00137 MYTEST( calHit->getEnergyError() , float(i*j*0.117) , "energy error" ) ;
00138 MYTEST( calHit->getCellID0() , i+100000 + j , " cellid0 " ) ;
00139
00140 const float* pos = calHit->getPosition() ;
00141
00142 MYTEST( pos[0] , i , " pos[0] " ) ;
00143 MYTEST( pos[1] , j , " pos[1] " ) ;
00144 MYTEST( pos[2] , i*j , " pos[2] " ) ;
00145
00146 }
00147 }
00148 lcRdr->close() ;
00149
00150
00151 } catch( Exception &e ){
00152 MYTEST.FAILED( e.what() );
00153 }
00154
00155 return 0;
00156 }
00157
00158
00159