00001 #ifndef __CINT__
00002 #include "IO/LCReader.h"
00003 #include "IOIMPL/LCFactory.h"
00004 #include "IMPL/LCCollectionVec.h"
00005 #include "IMPL/MCParticleImpl.h"
00006 #include "EVENT/LCEvent.h"
00007 #include "UTIL/LCTOOLS.h"
00008 #include <vector>
00009 #endif
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 void writeTree(const char* FILEN) {
00022
00023 std::string mcpName("MCParticlesSkimmed") ;
00024
00025
00026
00027 delete gROOT->GetListOfFiles()->FindObject( FILEN );
00028 delete gROOT->GetListOfCanvases()->FindObject("c1");
00029
00030 if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
00031 unsigned res ;
00032
00033 res = gSystem->Load("${LCIO}/lib/liblcio.so");
00034 res = gSystem->Load("${LCIO}/lib/liblcioDict.so");
00035 }
00036
00037
00038
00039
00040 TFile* file = new TFile( "lcioTree.root" , "RECREATE");
00041
00042 TTree* tree = new TTree( "LCIO" , "lcio event data tree");
00043
00044
00045
00046
00047
00048
00049 std::vector<IMPL::MCParticleImpl*>* treeCol = new std::vector<IMPL::MCParticleImpl*> ;
00050 std::string mcpType("std::vector<IMPL::MCParticleImpl*>") ;
00051
00052
00053 TBranch* mcpBranch = tree->Branch( mcpName.c_str(),
00054 mcpType.c_str(),
00055 (void*) &treeCol,
00056 1024,
00057 99
00058 );
00059
00060
00061 std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
00062
00063 int nEvents = 0 ;
00064 int maxEvt = 10000 ;
00065
00066 IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
00067
00068 lcReader->open( FILEN ) ;
00069
00070
00071 IMPL::LCCollectionVec emptyCol ;
00072
00073
00074 while( (evt = lcReader->readNextEvent()) != 0 && nEvents < maxEvt ) {
00075
00076 UTIL::LCTOOLS::dumpEvent( evt ) ;
00077 nEvents ++ ;
00078
00079
00080
00081
00082 IMPL::LCCollectionVec* col = (IMPL::LCCollectionVec*) evt->getCollection( mcpName ) ;
00083
00084
00085
00086 treeCol->clear() ;
00087
00088 int nMCP = col->getNumberOfElements() ;
00089
00090 for(int i=0 ; i<nMCP ; ++i){
00091
00092 treeCol->push_back( (IMPL::MCParticleImpl*) col->getElementAt(i) ) ;
00093 }
00094
00095
00096 tree->Fill() ;
00097
00098 }
00099
00100
00101 file->Write() ;
00102 file->Close() ;
00103
00104 delete file ;
00105
00106
00107 std::cout << std::endl
00108 << " " << nEvents
00109 << " events read from file: "
00110 << FILEN << std::endl ;
00111
00112
00113 lcReader->close() ;
00114
00115 delete lcReader ;
00116 }