7 added files
lcio/examples/cpp/rootDict
diff -N README
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ README 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,98 @@
+###################################################################
+#
+# rootDict: examples for using the ROOT dictionary for LCIO
+#
+#
+# F.Gaede, DESY (01/2010)
+#
+###################################################################
+
+Note: the ROOT dictionary for LCIO is a rather experimental feature
+that should enable the ILC users to evaluate the use of ROOT together with LCIO
+for their data analysis. It should not be used for 'production' type analysis code
+development, as things are likely to evolve.
+
+Please provide feedback to the LCIO team at:
+
+ http://forum.linearcollider.org/index.php?t=threadt&frm_id=5
+
+
+
+Build instructions:
+===================
+
+ In order to build LCIO including a ROOT dictionary you need to:
+
+#----- set ROOT environment (5.26 or higher: ) :
+
+ . ~/ilcsoft/root/5.26.00/bin/thisroot.sh
+
+#---- configure cmake
+
+cd ../../../ ; mkdir build ; cd build
+cmake -D BUILD_ROOTDICT=1 -D ROOT_HOME=$ROOTSYS ..
+
+#----- build and install
+
+make -j 4 install
+cd ..
+export LCIO=$PWD
+
+
+#----- go to example dir:
+
+cd $LCIO/examples/cpp/rootDict
+
+#- and run the
+
+example scripts:
+===============
+
+ anajob.C:
+ reads *.slcio file and dumps events to the screen in a ROOT macro
+ usage:
+ .x anajob.C("DST01-06_ppr004_bbcsdu.slcio")
+
+===
+
+ writeTree.C:
+
+ reads *.slcio file and writ the MCParticle collection to
+ a branch of type std::vector<IMPL::MCParticleImpl*>
+ in file lcioTree.root
+
+ usage:
+ .x writeTree.C("DST01-06_ppr004_bbcsdu.slcio")
+
+ analyse TTree e.g. with TTree::Draw(), see:
+
+===
+
+ treeDraw.C
+ use the TTree::Draw to create some plots from the
+ MCParticle tree created with writeTree.C
+
+ usage:
+ .x treeDraw.C
+
+
+===
+
+ writeEventTree.C :
+ reads *.slcio file and creates a ROOT tree with one branch
+ that hold the complete event
+
+ usage:
+ .x writeEventTree.C("DST01-06_ppr004_bbcsdu.slcio")
+
+===
+
+ readEventTree.C:
+ read LCEvents from tree with branch holding complete event e.g.
+ created with writeEventTree.C
+ and fill a histogram from MCParticle::getEnergy()
+
+ usage:
+
+ .x readEventTree.C("lcioEventTree.root")
+
lcio/examples/cpp/rootDict
diff -N anajob.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ anajob.C 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,58 @@
+#ifndef __CINT__
+#include "IO/LCReader.h"
+#include "IOIMPL/LCFactory.h"
+#include "EVENT/MCParticle.h"
+#include "EVENT/LCCollection.h"
+#include "EVENT/LCEvent.h"
+#include "UTIL/LCTOOLS.h"
+#endif
+
+
+/** Example script for testing the ROOT LCIO dictionary.
+ *
+ * anajob: reads *.slcio file and dumps events to the screen
+ * in a ROOT macro.
+ *
+ */
+
+void anajob(const char* FILEN) {
+
+
+ //just in case this script is executed multiple times
+ delete gROOT->GetListOfFiles()->FindObject( FILEN );
+ delete gROOT->GetListOfCanvases()->FindObject("c1");
+
+
+ if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("${LCIO}/lib/liblcio.so");
+ res = gSystem->Load("${LCIO}/lib/liblcioDict.so");
+ }
+
+ std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
+
+
+ int nEvents = 0 ;
+ IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
+ lcReader->open( FILEN ) ;
+
+
+ //----------- the event loop -----------
+ while( (evt = lcReader->readNextEvent()) != 0 ) {
+
+ UTIL::LCTOOLS::dumpEvent( evt ) ;
+ nEvents ++ ;
+ }
+ // -------- end of event loop -----------
+
+ std::cout << std::endl
+ << " " << nEvents
+ << " events read from file: "
+ << FILEN << std::endl ;
+
+
+ lcReader->close() ;
+
+ delete lcReader ;
+}
lcio/examples/cpp/rootDict
diff -N readEventTree.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ readEventTree.C 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,117 @@
+// #include "TTree.h"
+// #include "TFile.h"
+// #include "TBranch.h"
+#ifndef __CINT__
+#include "IO/LCReader.h"
+#include "IOIMPL/LCFactory.h"
+#include "EVENT/MCParticle.h"
+#include "EVENT/LCCollection.h"
+#include "IMPL/LCEventImpl.h"
+#include "UTIL/LCTOOLS.h"
+#endif
+
+
+/** Example script for testing the ROOT LCIO dictionary.
+ *
+ * readEventTree:
+ * read LCEvents from tree with branch holding complete event e.g.
+ * created with writeEventTree.C
+ * and fill a histogram from MCParticle::getEnergy()
+ */
+
+void readEventTree(const char* FILEN) {
+
+ //just in case this script is executed multiple times
+ delete gROOT->GetListOfFiles()->FindObject( FILEN );
+ delete gROOT->GetListOfCanvases()->FindObject("c1");
+
+ if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("$LCIO/lib/liblcio.so");
+ res = gSystem->Load("$LCIO/lib/liblcioDict.so");
+ }
+
+
+ std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
+
+
+ //======== open file and get tree and branch =====================
+
+ TFile* f = new TFile( FILEN, "READ") ;
+ if (!f) { return; }
+
+ TTree *t; f->GetObject("LCIO",t);
+
+ IMPL::LCEventImpl* evt=0 ;
+ TBranch* bevt = t->GetBranch("LCEvent") ;
+
+ if( bevt ){
+
+ bevt->SetAddress( &evt ) ;
+
+ } else {
+
+ std::cout << " --- branch 'LCEvent' not found ;-( " << std::endl ;
+ }
+
+
+ // define a simple histogram
+
+ TH1F* h_mcpEner = new TH1F("h_mcpEner","MCParticles E(GeV) ", 100, 0. , 100. ) ;
+
+ std::string mcpName("MCParticlesSkimmed") ;
+
+
+ int nEvents = 0 ;
+
+ int nevt = t->GetEntries();
+
+ for (Int_t i = 0; i < nevt ; i++) {
+
+ Long64_t tentry = t->LoadTree(i);
+
+ int nbyte = bevt->GetEntry(tentry);
+
+
+ //======== LCIO event loop below this line ============================
+
+
+ // UTIL::LCTOOLS::dumpEventDetailed( evt ) ;
+ UTIL::LCTOOLS::dumpEvent( evt ) ;
+
+
+ EVENT::LCCollection* col = evt->getCollection( mcpName ) ;
+
+ int nMcp = col->getNumberOfElements() ;
+ for( int j = 0 ; j < nMcp ; ++j ) {
+
+ EVENT::MCParticle* mcp = (EVENT::MCParticle*) col->getElementAt(j) ;
+
+ h_mcpEner->Fill( mcp->getEnergy() ) ;
+
+ }
+
+ nEvents ++ ;
+
+ }
+
+ // -------- end of event loop -----------
+
+ std::cout << std::endl
+ << " " << nEvents
+ << " events read from file: "
+ << FILEN << std::endl ;
+
+
+
+
+ //======== draw histogram(s) ============================
+
+ // -------------------------
+ TCanvas *c1 = new TCanvas("c1","LCIO root example",200,10,700,500);
+ // c1->Divide(2,2);
+ c1->cd(1) ;
+ h_mcpEner->Draw();
+
+}
lcio/examples/cpp/rootDict
diff -N treeDraw.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ treeDraw.C 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,63 @@
+
+/** Example script for testing the ROOT LCIO dictionary.
+ *
+ * treeDraw:
+ * use the TTree::Draw to create some plots from the
+ * MCParticle tree created with writeTree.C
+ *
+ */
+
+{
+
+
+if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("$LCIO/lib/liblcio.so");
+ res = gSystem->Load("$LCIO/lib/liblcioDict.so");
+}
+
+
+TFile* f = new TFile("lcioTree.root","READ") ;
+
+
+// -------------------------
+TCanvas *c1 = new TCanvas("c1","LCIO root example",200,10,700,500);
+c1->Divide(2,2);
+c1->cd(1) ;
+
+
+
+
+// define some cuts
+TCut sizeCut("abs(MCParticlesSkimmed._endpoint[][0])<1000.&&abs(MCParticlesSkimmed._endpoint[][1])<1000." ) ;
+
+TCut isPhoton("MCParticlesSkimmed.getPDG()==22" ) ;
+TCut isElectron("abs(MCParticlesSkimmed.getPDG())==11" ) ;
+
+
+// simple drawing of scalar variable (using API !)
+LCIO->Draw("MCParticlesSkimmed.getPDG()", isPhoton || isElectron ) ;
+
+
+
+c1->cd(2) ;
+LCIO->Draw("MCParticlesSkimmed._endpoint[][0]:MCParticlesSkimmed._endpoint[][1]", sizeCut && isPhoton ) ;
+
+c1->cd(3) ;
+LCIO->Draw("MCParticlesSkimmed._endpoint[][0]:MCParticlesSkimmed._endpoint[][1]", sizeCut && isElectron ) ;
+
+
+// this syntax does not work !?? ....
+//LCIO->Draw("MCParticlesSkimmed.getEndpoint()[][0]:MCParticlesSkimmed.getEndpoint()[][1]", sizeCut) ;
+
+//LCIO->Draw("MCParticlesSkimmed.getEndpoint()[0]:MCParticlesSkimmed.getEndpoint()[1]" ) ;
+
+
+
+TH2F h_trkStop("h_trkStop","particles stopped vs in/out of tracker region" , 2 , -.5 , 1.5 , 2 , -.5 , 1.5 ) ;
+
+c1->cd(4) ;
+LCIO->Draw("MCParticlesSkimmed.isDecayedInTracker():MCParticlesSkimmed.isStopped()>>h_trkStop" ) ;
+
+}
lcio/examples/cpp/rootDict
diff -N writeEventTree.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ writeEventTree.C 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,98 @@
+#ifndef __CINT__
+#include "IO/LCReader.h"
+#include "IOIMPL/LCFactory.h"
+#include "IMPL/LCCollectionVec.h"
+#include "IMPL/MCParticleImpl.h"
+#include "EVENT/LCEvent.h"
+#include "UTIL/LCTOOLS.h"
+#include <vector>
+#endif
+
+
+/** Example script for testing the ROOT LCIO dictionary.
+ *
+ * writeEventTree:
+ * reads *.slcio file and creates a ROOT tree with one branch
+ * that hold the complete event
+ *
+ */
+
+void writeEventTree(const char* FILEN) {
+
+ //just in case this script is executed multiple times
+ delete gROOT->GetListOfFiles()->FindObject( FILEN );
+ delete gROOT->GetListOfCanvases()->FindObject("c1");
+
+ if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("$LCIO/lib/liblcio.so");
+ res = gSystem->Load("$LCIO/lib/liblcioDict.so");
+ }
+
+
+ //--- create a ROOT file, a tree and a branch ...
+
+ TFile* file = new TFile( "lcioEventTree.root" , "RECREATE");
+
+ TTree* tree = new TTree( "LCIO" , "lcio event data tree");
+
+ std::string treeName("LCEvent") ;
+
+
+ IMPL::LCEventImpl* treeEvt=0 ;
+
+ std::string type("IMPL::LCEventImpl") ;
+
+ TBranch* mcpBranch = tree->Branch( treeName.c_str(),
+ type.c_str(),
+ (void*) &treeEvt,
+ 1024, // record size
+ 199 // split level
+ );
+
+
+ std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
+
+ int nEvents = 0 ;
+
+ int maxEvt = 10000 ;
+
+ IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
+
+ lcReader->open( FILEN ) ;
+
+
+ //----------- the event loop -----------
+ while( (evt = lcReader->readNextEvent()) != 0 && nEvents < maxEvt ) {
+
+ if( nEvents < 3 ) // only dump first 3 events
+ UTIL::LCTOOLS::dumpEvent( evt ) ;
+
+ nEvents ++ ;
+
+
+ treeEvt = (IMPL::LCEventImpl*) evt ;
+
+
+ tree->Fill() ;
+
+ }
+ // -------- end of event loop -----------
+
+ file->Write() ;
+ file->Close() ;
+
+ delete file ;
+
+
+ std::cout << std::endl
+ << " " << nEvents
+ << " events read from file: "
+ << FILEN << std::endl ;
+
+
+ lcReader->close() ;
+
+ delete lcReader ;
+}
lcio/examples/cpp/rootDict
diff -N writeTree.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ writeTree.C 21 Jan 2010 16:22:59 -0000 1.1
@@ -0,0 +1,116 @@
+#ifndef __CINT__
+#include "IO/LCReader.h"
+#include "IOIMPL/LCFactory.h"
+#include "IMPL/LCCollectionVec.h"
+#include "IMPL/MCParticleImpl.h"
+#include "EVENT/LCEvent.h"
+#include "UTIL/LCTOOLS.h"
+#include <vector>
+#endif
+
+
+/** Example script for testing the ROOT LCIO dictionary.
+ *
+ * writeTree:
+ * reads *.slcio file and writes the MCParticle collection to
+ * a branch of type std::vector<IMPL::MCParticleImpl*>
+ * in file lcioTree.root
+ *
+ */
+
+void writeTree(const char* FILEN) {
+
+ std::string mcpName("MCParticlesSkimmed") ;
+
+
+ //just in case this script is executed multiple times
+ delete gROOT->GetListOfFiles()->FindObject( FILEN );
+ delete gROOT->GetListOfCanvases()->FindObject("c1");
+
+ if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("${LCIO}/lib/liblcio.so");
+ res = gSystem->Load("${LCIO}/lib/liblcioDict.so");
+ }
+
+
+ //--- create a ROOT file, a tree and a branch ...
+
+ TFile* file = new TFile( "lcioTree.root" , "RECREATE");
+
+ TTree* tree = new TTree( "LCIO" , "lcio event data tree");
+
+
+
+ // IMPL::LCCollectionVec* treeCol = 0 ;
+ // std::string mcpType("IMPL::LCCollectionVec") ;
+
+ std::vector<IMPL::MCParticleImpl*>* treeCol = new std::vector<IMPL::MCParticleImpl*> ;
+ std::string mcpType("std::vector<IMPL::MCParticleImpl*>") ;
+
+
+ TBranch* mcpBranch = tree->Branch( mcpName.c_str(),
+ mcpType.c_str(),
+ (void*) &treeCol,
+ 1024, // record size
+ 99 // split level
+ );
+
+
+ std::cout << " loaded LCIO library and dictionary ... " << std::endl ;
+
+ int nEvents = 0 ;
+ int maxEvt = 10000 ; // change as needed
+
+ IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
+
+ lcReader->open( FILEN ) ;
+
+
+ IMPL::LCCollectionVec emptyCol ;
+
+ //----------- the event loop -----------
+ while( (evt = lcReader->readNextEvent()) != 0 && nEvents < maxEvt ) {
+
+ UTIL::LCTOOLS::dumpEvent( evt ) ;
+ nEvents ++ ;
+
+
+ // ------- fill the MCParticle collection to the branch...
+
+ IMPL::LCCollectionVec* col = (IMPL::LCCollectionVec*) evt->getCollection( mcpName ) ;
+
+// treeCol = col ? col : emptyCol ;
+
+ treeCol->clear() ;
+
+ int nMCP = col->getNumberOfElements() ;
+
+ for(int i=0 ; i<nMCP ; ++i){
+
+ treeCol->push_back( (IMPL::MCParticleImpl*) col->getElementAt(i) ) ;
+ }
+
+
+ tree->Fill() ;
+
+ }
+ // -------- end of event loop -----------
+
+ file->Write() ;
+ file->Close() ;
+
+ delete file ;
+
+
+ std::cout << std::endl
+ << " " << nEvents
+ << " events read from file: "
+ << FILEN << std::endl ;
+
+
+ lcReader->close() ;
+
+ delete lcReader ;
+}
CVSspam 0.2.8