/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/TESTS/test_calohit.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/CalorimeterHitImpl.h"
#include "IMPL/LCFlagImpl.h"

Include dependency graph for test_calohit.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 = "calohit.slcio"
static const string testname = "test_calohit"


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file test_calohit.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 CalorimeterHits " );
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* 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     // create sio reader
00097     LCReader* lcRdr = LCFactory::getInstance()->createLCReader()  ;
00098     
00099     lcRdr->open( FILEN ) ;
00100     
00101     for(int i=0;i<NEVENT;i++){
00102       
00103       //std::cout << " testing event " << i << std::endl ;
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         //std::cout << " testing hit " << j << std::endl ;
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         //std::cout << " testing hit " << j << std::endl ;
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 }


Variable Documentation

const int NEVENT = 10 [static]

Definition at line 22 of file test_calohit.cc.

const int NHITS = 1000 [static]

Definition at line 23 of file test_calohit.cc.

string FILEN = "calohit.slcio" [static]

Definition at line 25 of file test_calohit.cc.

const string testname = "test_calohit" [static]

Definition at line 28 of file test_calohit.cc.

Referenced by main().


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